Some of the scenarios we may need to capture a screenshot using Selenium WebDriver are
i. Application issues
ii. Assertion Failure
iii. Difficulty to find Webelements on the web page
iv. Timeout to find Webelements on the web page
Tosca
Take Screen Shot In Tosca Testsuite
A standard module is provided by tricentis to take screenshot. It is present in standard modules. TBox TakesScreenshot
Selenium
Selenium provides an interface called TakesScreenshot which has a method getScreenShotAs which can be used to take a screenshot of the application under test.
Syntax to capture and save the screenshot.
File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
Syntax to store it in our local drive
FileUtils.copyFile(screenshotFile, new File("filename_with_path"));
to capture full page screenshot using Selenium WebDriver:
What is aShot?
aShot is a WebDriver Screenshot utility. It takes a screenshot of the WebElement on different platforms (i.e. desktop browsers, iOS Simulator Mobile Safari, Android Emulator Browser).
aShot might be configured to handle browsers with the viewport problem. This gives a screenshot of the entire page even for Chrome, Mobile Safari, etc
Add this jar file in to your project. Note: Select Project and Right click on the Project – Go to ‘Build path’ – Go to ‘Configure build path’ – Click on ‘lib’ section – Add external jar
Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"PNG",new File("D:///FullPageScreenshot.png"));
To Capture Screenshot of Failed Test Cases Using Selenium WebDriver
If a script fails, we need to know where was the error in script. Solution for this is to capture a screenshot of webpage when the test case fails. We could easily identify where exactly the script got failed by seeing the screenshot.
To achieve this, we could place the entire code in try-catch block. Which means placing the test steps in try block and screen capture statement in catch block. If a test step fails in the try block then it goes to the catch block and capture a screenshot of the web page.
UFT/QTP
Dim ScreenName
On Error Resume Next
ScreenName = " "
CurrentTime = "_Test_Case"&"_"& Day(Now)&"_"& Month(Now)&"_"& Year(Now)&"_"&
Hour(Now)&"_"& Minute(Now)&"_"& Second(Now)
ScreenShotName = "Name_of_the_Screen" & CurrentTime & ".png"
ScreenName ="Path where the Screenshot needs to be stored"&"\"&ScreenShotName
Desktop.CaptureBitmap ScreenName,True
No comments:
Post a Comment