测试时截取屏幕截图对于自动化非常重要,这样您就可以指出并捕获确切的错误。在这篇文章中,我们将学习如何在硒测试用例失败时进行屏幕截图。在硒测试失败时拥有屏幕截图更为重要,但是如果要在硒测试通过时捕获屏幕截图,则可以添加代码。
一旦知道如何使用它,便可以在任何地方使用它。因此,让我们开始吧。 。 。
一旦知道如何使用它,便可以在任何地方使用它。因此,让我们开始吧。 。 。
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class ScreenshootGoogle {
@Test
public void TestJavaS1()
{
// Open chrome browser
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Anuja.AnujaPC\\Downloads\\chromedriver_win32\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
// Maximize the window
driver.manage().window().maximize();
// Pass the url
driver.get("http://www.yubo666.com");
// Take screenshot and store as a file format
File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
// now copy the screenshot to desired location using copyFile //method
FileUtils.copyFile(src, new File("C:/selenium/error.png"));
}
catch (IOException e)
{
System.out.println(e.getMessage());
}
}
import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.testng.annotations.Test; public class ScreenshootGoogle { @Test public void TestJavaS1() { // Open chrome browser System.setProperty("webdriver.chrome.driver", "C:\\Users\\Anuja.AnujaPC\\Downloads\\chromedriver_win32\\chromedriver.exe"); WebDriver driver=new ChromeDriver(); // Maximize the window driver.manage().window().maximize(); // Pass the url driver.get("http://www.yubo666.com"); // Take screenshot and store as a file format File src= ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); try { // now copy the screenshot to desired location using copyFile //method FileUtils.copyFile(src, new File("C:/selenium/error.png")); } catch (IOException e) { System.out.println(e.getMessage()); } }
您好,
回复删除有关使用Selenium WebDriver进行ScreenShot的文章内容翔实,提供了详细信息。感谢您共享有关使用Selenium WebDriver进行ScreenShot程序的信息。 软件测试服务
该评论已被博客管理员删除。
回复删除不错的信息非常感谢您提供这么好的信息。
回复删除