How to resize browser window for screenshots on Testcafe - testing

When running a test in Testcafe, I'd like to resize the browser for screenshots.
As described in https://devexpress.github.io/testcafe/documentation/test-api/actions/resize-window.html#setting-the-window-size, I've tried the following:
(1) "testcafe \"chrome:headless --window-size='width,height'\"
(2) await t.resizeWindow(width,height)
For some reason, the screenshots dimensions that are returned are twice the size: 2400x1690. Has anyone else encountered this and know how to resolve it?

Related

nightwatch test fails with multiple click events in sequence

When running a nightwatch.js test on a browser with a checkbox that
is not visible using the following code.
browser.moveToElement('input[id="2verificationYes"]')
.click('input[id="2verificationYes"]')
I get the following error :
An error occurred while running .click() command on ,input[id="2verificationYes"]>: unknown error: Element `element` is not clickable at point (111, 701). Other element would receive the click: `otherElement`
at process._tickCallback (internal/process/next_tick.js:64:7)
I am using
nightwatch v.1.0.19, chromedriver ^2.43.0, geckodriver ^1.16.2, selenium-server ^3.14.0
I have tried using the callback functions with each call but the result is the same. Tried to research how to scroll to an element in nightwatch, but the api's don't have that. It is my understanding the the moveToElement function is supposed to scroll to the element.
For me moveToElement is working good. I believe you are seeing error because you forgot to mentioned the Xoffset and Yoffset.
Try my below work around and let me know:
browser.moveToElement('input[id="2verificationYes"]',Xoffset,Yoffset)
.click('input[id="2verificationYes"]')
for your reference: search 'moveToElement' here
Can you try giving '0' and let me know:
browser.moveToElement('input[id="2verificationYes"]',0,0)
.click('input[id="2verificationYes"]')
Same time try giving little wait time to narrow down the issue. Good luck

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 ?

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

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)
}

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

How should I test Gmaps4rails generated maps?

I am using gmaps4rails-1.3.0 to render a few maps in my rails-3.0.7 application. When the map loads, it already has a few markers set. The users get to select which type of markers they want to see by getting to click on a few checkboxes. This works fine in all versions of FF, Chrome and IE that I have checked.
So, now I wanted to write automated test cases to check this functionality. For this, I wrote rspec-2.6.0 request examples which are run through capybara-1.1.2 using the selenium-2.14.0 driver. The test is able to load the map fine with all of the markers showing up correctly. However, no markers are removed when the test unchecks one of the checkboxes. I inserted a debugger statement at the end of test and then checked the error console in the browser. It had the following message:
console is not defined
http://127.0.0.1:51643/javascripts/gmaps4rails/gmaps4rails.googlemaps.js?1323052026 Line 196
Checking the relevant file showed the following function:
Gmaps4RailsGoogle.prototype.clearMarker = function(marker) {
console.log(marker);
return marker.serviceObject.setMap(null);
};
I then noticed that during normal operation, a no. of such log messages are displayed in the firebug console. The selenium webdriver profile doesn't have firebug and nor do I expect all my users to have firebug.
Should a console.log() call be there in any javascript file post-development? If yes, what's the way to test it with a rendering driver, in particular with selenium?