How to attach screen shot to XCUITest report in Jenkins. Can only see screenshot if running through XCODE - xctest

How to attach screen shot to XCUITest report in Jenkins. Can only see screenshot if running through XCODE
Steps
I have a job in Jenkins which builds and runs the XCUITest
But after completing there is no option to see the screenshot of failed cases
I used xcpretty to generate HTML type report, but there also screenshot is not displayed.
it has a -screenshot attribute but that only accepts screenshot with a sepecified name. (like TestcaseName_Classname.jpg)
But xcuitest takes screenshot with name 'screenshot_<>.jpg"
Can anyone throw some information on this
Thanks

Screenshot collection in xcpretty is broken as of now.
https://github.com/supermarin/xcpretty/issues/251
You may use xcsummary as a workaround.
https://github.com/supermarin/xcpretty/issues/251

You need to point attachment.name as here
func takeScreenshot() {
let screenshot = XCUIScreen.main.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.lifetime = .deleteOnSuccess
attachment.name = UITest.sharedInstance.testCase.name
add(attachment)
}

Related

Mime Type for adding sauce labs video link in cucumber report

I am trying to add a video link to the cucumber report using embedded method in scenario ,
String html = "www.saucelabs.com/asdfs234234sdafs/video.mp4";
scenario.embed(html.getBytes(), "text/html");
In the report i still see as text , not a link , also tried below , now this opening in windows media player instead of in browser
String html = "https://www.saucelabs.com/asdfs234234sdafs/video.mp4" >VideoLink;
scenario.embed(html.getBytes(), "text/html");
Can you please help me ? i want a link to appeared in the report by clicking upon , it must navigate to the sauce labs link.
Thanks in advance.
Ruby Implementation: (You can use the same logic in other languages too).
Just call this below line in your hooks.rb, before closing the driver. The below line of code will build the saucelabs video link dynamically based on driver session id.
puts "<button style=\"background-color: #525fa0;font-weight: bold;color: #fff;border: double;border-radius: 25px;\" onclick= \"window.open('https://saucelabs.com/jobs/#{browser.driver.session_id}','_blank')\">SauceLabs Execution Report</button>"
This will add a button to the html report with the saucelabs video link.
If you want to pass the url then use the below code.
puts "<button style=\"background-color: #525fa0;font-weight: bold;color: #fff;border: double;border-radius: 25px;\" onclick= \"window.open(url_goes_here,'_blank')\">SauceLabs Execution Report</button>"
If you are trying to access the html report from jenkins then make sure to run the below line in jenkins console.
System.setProperty("hudson.model.DirectoryBrowserSupport.CSP", "sandbox allow-scripts allow-popups unsafe-inline; ")
Make sure to restart the jenkins, once you ran the script in the script console.
This will allow you to see the report in the html otherwise your url will be blocked.

How to create a better screenshot during the selenium automation in JAVA?

I am creating automated test cases by using selenium 3 & testng. Everything looks good, except the screenshots that are generated. Here is my piece of code to create screenshots PNG files:
file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(pngfile));
which is pretty standard way to do it, but the quality of the created PNG file is not so good.
As you can see from following PNG file. In the picture, the email value ( "....#yahoo.com"), which should be at the upper-right corner of the web-page and should be as high as the other navigation bar elements on the left side. But in the created PNG file, this item has been squeezed to the lower level, which is not what I am looking for. Any ideas ? Thanks for the help !
Make sure your window is the right size when you're opening the browser. You can do this via visual inspection or using Selenium's getSize method. I assume you're using Java, but here it is in Python as well.
Then, if the window is not of the correct size in order to guarantee that your webpage's CSS doesn't break, use setSize. Here is that method in Python as well.
Afterwards, your screenshot should look like the window does.
Please try this,
public void calltakeScreenShot(String SSName) throws Exception
{
File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage img = ImageIO.read(screen);
File filetest = Paths.get(".").toAbsolutePath().normalize().toFile();
ImageIO.write(img, "png", new File(filetest + "\\Screenshots\\" + SSName + ".png"));
}
Additionally Here you just need to pre-created Screenshots folder in your Project directory. It will store it by getting absolute path of your project. Also you can manage screenshot name by passing argument.
After several day's research, here is my latest summary.
A). If I was executing the scripts, that is not in the "headless" mode. When the selenium test case is being executed, I will see a new browser session is being popped up and get to that URL, click some buttons, etc, ... till the execution is finished. In this execution, the screenshot page will be saved in good quality.
B). For the same selenium test script, if I am including one extra ChromeOptions setting, which is "--headless", I will not see any browser being brought up during the execution. And once execution is finished, I will get the screenshot with such squeezed web elements.
Comments ?

Appium Blank Screenshot in Real Devices

When I am taking screenshot using the below code I am getting blank screenshots. I tried putting sleep but that too is not working.
Please advice. It's not that I am getting all blank screens, I am getting few blank screens and few proper screenshots. I dont know what I am doing wrong. I didn't hear appium has any issues in taking screenshots.
Help me in figuring out a solution.
Code:
WebDriver driver1 = new Augmenter().augment(AppiumBaseTest.getAndroidDriver());
File file = ((TakesScreenshot) driver1).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(System.getProperty("test.screenshot.dir") + href));
Code:
FileUtils.copyFile(((TakesScreenshot) AppiumBaseTest.getAndroidDriver()).
getScreenshotAs(OutputType.FILE), new File(System.getProperty("test.screenshot.dir") + href));
I tried taking screenshot using appium driver also and that is also giving me the same issue of blank screenshot. Some are proper and some are blank.
I have tried giving wait for 7 seconds before each screenshot but of no use.
ThankS,
Rajit

org.openqa.selenium.WebDriverException: unknown error: cannot focus element on trying to upload a file in selenium

I am trying to upload a file in the webpage through selenium webdriver, and i have written the below code
driver.findElement(By.cssSelector("#collapseDocuments > div > button.button.ng-isolatescope")).sendKeys("C:\\Users\\siva.247588\\Desktop\\Clarient+AML+Questionnaire.docx");
The CSS selector is that of the browse button.
I am getting the below error whwn i run this:
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: cannot focus element
What is wrong with my code? Could any one advise?
When you try to upload a file, the control is shifted to our local machine from website where we were writing scripts.
So normal click method and select method won't work. You can use robot method to browse and upload some file from your local machine to websites.
Hope this help you..
See the below link for help:
http://www.seleniumeasy.com/selenium-tutorials/webdriver-file-upload-using-robots
I've used this somewhere , hope you can relate this:
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_A);
rb.keyRelease(KeyEvent.VK_A);
rb.keyPress(KeyEvent.VK_L);
rb.keyRelease(KeyEvent.VK_L);
rb.keyPress(KeyEvent.VK_E);
rb.keyRelease(KeyEvent.VK_E);
rb.keyPress(KeyEvent.VK_R);
rb.keyRelease(KeyEvent.VK_R);
rb.keyPress(KeyEvent.VK_T);
rb.keyRelease(KeyEvent.VK_T);
Thread.sleep(4000L);
rb.keyPress(KeyEvent.VK_TAB);
rb.keyRelease(KeyEvent.VK_TAB);
Thread.sleep(4000L);
rb.keyPress(KeyEvent.VK_ENTER);
rb.keyRelease(KeyEvent.VK_ENTER);
This will browse and upload a file with name "Alert"
If you need more help, kindly provide me code and what you want to upload , I'll help you to resolve your issue.
As #theroot mentioned AutoIT is a good solution, but the downside is it works only on windows based platforms. The best solution so far that I have come across for upload or focus outside browser situations is using Sikuli. Example code is below
Screen sikuliObject= new Screen(); // Creating Screen class object
Pattern add = new Pattern("path to the image.png"); // Path of the upload button image.
sikuliObject.click(add); // Click on Upload button
Thread.sleep(2000); // Wait for 2 seconds for upload window pop-up.
sikuliObject.type("Path of the uploading file and click on enter."+ Key.ENTER );
//Path of the uploading file and click on enter.
Thread.sleep(2000); // Wait for 2 seconds to load the file.
I've once had a similar problem (I'm not sure anymore if it threw a "not visible" exception or the "could not focus"one) and the problem was that the input Element wasn't accessible because it had no dimensions. I've changed the DOM information using the JavaScriptExecuter and afterwards it worked fine. Just go through your page with Firebug and look if the element is really visible.

Jbehave - full page screenshot

I would like my application to take a screenshot when fail and I want this screenshot to be full screen, I am using this(which is taking the screenshot) however it is not full page.
new WebDriverScreenshotOnFailure(driverProvider, configuration.storyReporterBuilder()));
for full page screen shot you can use the following method
final Screenshot screenshot = new AShot().shootingStrategy(
new ViewportPastingStrategy(500)).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", new File(
"D://"
+ "AShot_BBC_Entire.png"));
Maven dependency is here.
Now as far as i know there is no jBehave inbuild function for full page screenshot. Hence you can write this in a method and call it on failures.
Hope this helps.