Screen captures of the browser session helps you to show error conditions.
#JAVA
WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com/");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\sample.jpeg"),true);
#Python
#!/usr/bin/env python
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com/')
browser.save_screenshot('screenie.png')
browser.quit()
Example Test
[Note:- "Scripts in Orange color are mandatory"]
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
public class classname{
private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://in.yahoo.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
public void testWww() throws Exception {
driver.get(baseUrl + "/?p=us");
driver.findElement(By.id("p_13838465-p")).clear();
driver.findElement(By.id("p_13838465-p")).sendKeys("screen");
driver.findElement(By.id("search-submit")).click();
Thread.sleep(2000);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("c:\\sample.jpeg"),true);
Thread.sleep(2000);
}
@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
}
Use the command: captureEntirePageScreenshotAndWait
Target: C:\\$(image).jpg
This cmd won't work for WebDriver
Example with 'captureScreenshot()'
Selenium selenium;
selenium = new DefaultSelenium(seleniumServer, 4444,
"*firefox", "http://www.google.com");
selenium.start();
selenium.open("/");
selenium.captureScreenshot("C:\screenshot.png");
Examples with 'captureEntirePageScreenshot()'
Selenium selenium;
selenium = new DefaultSelenium(seleniumServer, 4444,
"*firefox", "http://www.google.com");
selenium.start();
selenium.open("/");
selenium.captureEntirePageScreenshot("C:\screenshot.png","");
Tamil:
ReplyDeleteI am getting a error message for the following script line. Can any one help me out to verify it?
FileUtils.copyFile(scrFile, new File("c:\\sample.jpeg"),true);
Tamil, can I have your script ?
Deleteemail to seleniumworks@gmail.com
Cheers!!
_
Sams
Is this to capture screenshot or for screenshot on failure
ReplyDeleteMake use of EventFiringWebDriver for capturing screenshot on failure
DeleteI have a post on that too.. please check http://seleniumworks.blogspot.in/2014/02/eventfiringwebdriver.html
By writing only this command
ReplyDeleteselenium.captureEntirePageScreenshot("C:\screenshot.png","");
screenshot functionality is not working..pls help
Hi,
ReplyDeleteCan anyone help me how to take multiple screenshots.
-> How to take screenshots only for PASSED /FAILED test case
Your answer would help me a lot.
Explain me with some simple example.
Thanks in advance
ReplyDeleteHi Guys,
Please find the link to jar file by which we can take Taking Multiple screenshots and element Screenshots and minimize browser in Webdriver 2.0
https://github.com/MultiScreenShot/MultiScreenShot
Regards,
Pavankumar Nagaraj
+91 8971673487
pavankumar.nagaraj@gmail.com
in.linkedin.com/in/PavankumarNagaraj/
Bangalore.
ReplyDeleteI am using selenium to automate testing in IE using C#. When the case fails I take the screenshot. But the screenshot does not capture the pop up.
Thanks for sharing the useful information with us. This information is impressive..I am inspired with your post writing style & how continuously you describe this topic. After reading your post,thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic.
ReplyDeleteThanks
Pratical oritented Selenium Training
off white
ReplyDeletegolden goose shoes
curry 7
curry 7 sour patch
kd 12
kd shoes
bape hoodie
yeezy boost 350 v2
golden goose
kd shoes
7a replica bags wholesale replica bags prada replica bags in pakistan
ReplyDeleteyurtdışı kargo
ReplyDeleteresimli magnet
instagram takipçi satın al
yurtdışı kargo
sms onay
dijital kartvizit
dijital kartvizit
https://nobetci-eczane.org/
UMR2
salt likit
ReplyDeletesalt likit
dr mood likit
big boss likit
dl likit
dark likit
FRLJ