屏幕截图无法使用Chrome浏览器,但相同的代码可以正常使用firefox

时间:2017-03-20 09:29:38

标签: selenium-webdriver screenshot

**CaptureScreenShot.java**

public class CaptureScreenshot {
    WebDriver driver;

          public static void takescreenshot(WebDriver driver,String Screenshotname) throws IOException
           {
                  TakesScreenshot takescreenshot=(TakesScreenshot)driver;
                  File source=takescreenshot.getScreenshotAs(OutputType.FILE);
                  FileUtils.copyFile(source, new File("./Screenshots/"+Screenshotname+".png"));
                  System.out.println("Screenshot Taken Successfully!!!!");

           }

**Main.java**
public class ToadsLogin extends SuperTestNG {



@BeforeClass
    public void precondition()
    {
        System.setProperty("webdriver.chrome.driver", "D:/personal/chromedriver_win32/chromedriver.exe");
        driver=new ChromeDriver();
        driver.get("http://10.1.19.234:8002/");
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    }
    @Test()
    public void login1()
    {

        Login login=new Login(driver);
        login.toadsLogin();
        //login.clkUsers();
        Assert.assertEquals("Index - TOADSw", "Index - TOADS");
    }

    @AfterMethod
    public void failedCondi(ITestResult result) throws Exception
    {
        System.out.println("Testcase status is"+ result.getStatus());
        System.out.println("result status is"+ ITestResult.FAILURE);
        if(ITestResult.FAILURE==result.getStatus())
        {
            CaptureScreenshot.takescreenshot(driver, "titlefail");
        }

    }

}

此代码在Firefox浏览器中正常运行,但相同的代码在Chrome浏览器中出现以下错误。

Error: FAILED CONFIGURATION: @AfterMethod failedCondi([TestResult name=login1 status=FAILURE method=ToadsLogin.login1()[pri:0, instance:script.ToadsLogin@523884b2] output={null}])
org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension
from unknown error: page could not be found: chrome-extension://aapnijgdinlhnhlmodcfapnahmbfebeb/_generated_background_page.html
  (Session info: chrome=57.0.2987.110)
  (Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)

1 个答案:

答案 0 :(得分:2)

我认为Chrome仍然不完全支持使用网络驱动程序截取屏幕截图。看看Chromedriver项目中的这些突出问题:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=1083

https://bugs.chromium.org/p/chromedriver/issues/detail?id=294