由于使用Jenkins在Windows上通过ChromeDriver和Chrome进行截图时,接收来自渲染器的消息超时:10.000。

15

操作系统: Windows 10 浏览器: Chrome 浏览器版本: Version 73.0.3683.86 (Official Build) (32-bit)

我正在运行一个基于selenium cucumber BDD的项目,其中我正在验证一个页面的标题。我使用的是extent-report version4。该项目在本地成功运行。但是当我通过Jenkins运行时,在捕获截图时失败,并显示以下错误。

如果我从pom.xml中删除surfire插件,则无法通过Jenkins运行测试。

在Jenkins的“执行Windows批处理命令”选项中,我已经给出了以下命令:

C:\Program Files (x86)\Jenkins\workspace\CucumberBDDFramework
mvn test

测试运行器

    package com.accenture.TestRunner;

    import org.testng.annotations.AfterClass;
    import org.testng.annotations.Test;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.DataProvider;
    import org.testng.annotations.Test;

    import cucumber.api.CucumberOptions;
    import cucumber.api.testng.AbstractTestNGCucumberTests;
    import cucumber.api.testng.CucumberFeatureWrapper;
    import cucumber.api.testng.TestNGCucumberRunner;


    /**
     * @author ajinkya.pande
     *
     */

    @CucumberOptions(
            features="./features/WhatIsBitcoin.feature",
            glue= {"com.accenture.StepDef"},
            tags= {"@ExtentReport"}, 
            dryRun = false
            )

    public class TestRunner {

        // Write following steps or Try to extend AbstractTestNGCucumberTests

        private TestNGCucumberRunner testNGCucumberRunner;

        @BeforeClass(alwaysRun = true)
        public void setUpClass() throws Exception{ 
            testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
        }

        @Test(dataProvider = "features")
        public void feature(CucumberFeatureWrapper cucumberFeature) {
            testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
        }

        @DataProvider
        public Object [][] features(){
            return testNGCucumberRunner.provideFeatures();
        }


        @AfterClass(alwaysRun = true)
        public void tearDownClass() throws Exception{
            testNGCucumberRunner.finish();
        }

    }

步骤定义

    package com.accenture.listeners;

    import java.io.File;
    import java.io.IOException;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Date;

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.TakesScreenshot;
    import org.openqa.selenium.WebDriver;

    import com.accenture.Utility.Constants;
    import com.aventstack.extentreports.ExtentReports;
    import com.aventstack.extentreports.ExtentTest;
    import com.aventstack.extentreports.markuputils.ExtentColor;
    import com.aventstack.extentreports.markuputils.MarkupHelper;
    import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
    import com.aventstack.extentreports.reporter.configuration.Theme;

    /**
     * @author ajinkya.pande
     *
     */

    public class ExtentReportListener extends Constants {

        public static ExtentHtmlReporter report = null;
        public static ExtentReports extent = null;
        public static ExtentTest test = null;

        public static ExtentReports setUp() {
            String reportLocation = "./Reports/Extent_Report.html";
            report = new ExtentHtmlReporter(reportLocation);
            report.config().setDocumentTitle("Automation Test Report");
            report.config().setReportName("Automation Test Report");
            report.config().setTheme(Theme.STANDARD);
            System.out.println("Extent Report location initialized . . .");
            report.start();

            extent = new ExtentReports();
            extent.attachReporter(report);
            extent.setSystemInfo("Application", "Youtube");
            extent.setSystemInfo("Operating System", System.getProperty("os.name"));
            extent.setSystemInfo("User Name", System.getProperty("user.name"));
            System.out.println("System Info. set in Extent Report");
            return extent;
        }

        public static void testStepHandle(String teststatus, WebDriver driver, ExtentTest extenttest, Throwable throwable) {
            if (teststatus.equals("FAIL")) {

                extenttest.fail(MarkupHelper.createLabel("Test Case is Failed : ", ExtentColor.RED));
                extenttest.error(throwable.fillInStackTrace());

                try {
                    extenttest.addScreenCaptureFromPath(captureScreenShot(driver));
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if (driver != null) {
                    driver.quit();
                }

                if (teststatus.equals("PASS")) {
                    extenttest.pass(MarkupHelper.createLabel("Test Case is Passed : ", ExtentColor.GREEN));
                    try {
                        extenttest.addScreenCaptureFromPath(captureScreenShot(driver));
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

            }
        }

        public static String captureScreenShot(WebDriver driver) throws IOException {
            TakesScreenshot screen = (TakesScreenshot) driver;
            File src = screen.getScreenshotAs(OutputType.FILE);
            String dest = SCRRENSHOT_PATH + getcurrentdateandtime() + ".png";
            File target = new File(dest);
            FileUtils.copyFile(src, target);
            return dest;
        }

        private static String getcurrentdateandtime() {
            String str = null;
            try {
                DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss:SSS");
                Date date = new Date();
                str = dateFormat.format(date);
                str = str.replace(" ", "").replaceAll("/", "").replaceAll(":", "");
            } catch (Exception e) {
            }
            return str;
        }

    }

pom.xml

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>org.ajinkya.cucumber</groupId>
      <artifactId>extent-reporting</artifactId>
      <version>0.0.1-SNAPSHOT</version>



       <build>
        <plugins>


    <!--       <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.7.0</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
              <encoding>UTF-8</encoding>
            </configuration>
          </plugin> -->


          <plugin>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.1</version>
            <configuration>
              <fork>1.7</fork>
              <executable>C:\Program Files\Java\jdk1.8.0_191\bin\javac.exe</executable>
            </configuration>
          </plugin>


       <!--    <plugin>
        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>3.15.0</version>
        <executions>
            <execution>
                <id>execute</id>
                <phase>verify</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory>
                    <cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput>
                </configuration>
            </execution>            
        </executions>
          </plugin> -->


           <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-surefire-plugin</artifactId>
              <version>2.19.1</version>
              <configuration>
                <suiteXmlFiles>testng.xml</suiteXmlFiles>
              </configuration>
            </plugin>


        </plugins>
      </build>












      <dependencies>

      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.11.0</version>
    </dependency>



      <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
    <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>1.2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.9.8</version>
    </dependency>


      <dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-jvm-deps</artifactId>
    <version>1.0.5</version>
    <scope>provided</scope>
    </dependency>

    <dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.0.6</version>
    </dependency>

    <dependency>
    <groupId>org.freemarker</groupId>
    <artifactId>freemarker</artifactId>
    <version>2.3.23</version>
    </dependency>

      <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>


      </dependencies>



    </project>

Jenkins日志:


     T E S T S
    -------------------------------------------------------
    Running TestSuite
    Starting...............
    Extent Report location initialized . . .
    System Info. set in Extent Report
    Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 8950
    Only local connections are allowed.
    Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
    Mar 26, 2019 11:15:27 PM org.openqa.selenium.remote.ProtocolHandshake createSession
    INFO: Detected dialect: OSS
    [1553622354.306][SEVERE]: Timed out receiving message from renderer: 10.000
    [1553622354.307][WARNING]: screenshot failed, retrying
    [1553622364.313][SEVERE]: Timed out receiving message from renderer: 9.996
    [1553622374.336][SEVERE]: Timed out receiving message from renderer: 9.998
    [1553622374.337][WARNING]: screenshot failed, retrying
    [1553622384.337][SEVERE]: Timed out receiving message from renderer: 9.998
    [1553622394.343][SEVERE]: Timed out receiving message from renderer: 10.000
    [1553622394.344][WARNING]: screenshot failed, retrying
    [1553622404.345][SEVERE]: Timed out receiving message from renderer: 9.996

    Failed scenarios:
    ./features/WhatIsBitcoin.feature:3 # Scenario: Testing extent reports

    1 Scenarios (1 failed)
    4 Steps (1 failed, 3 skipped)
    1m25.069s

    org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 9.996
      (Session info: chrome=73.0.3683.86)
      (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 0 milliseconds
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
    System info: host: 'BDC11-L-FYK3VP2', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:\windows\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:51833}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.86, webStorageEnabled: true}
    Session ID: 1b4d8402a8e29651ed2c7a773c11ca37
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
        at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
        at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
        at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)
        at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:291)
        at com.accenture.listeners.ExtentReportListener.captureScreenShot(ExtentReportListener.java:81)
        at com.accenture.StepDef.WhatIsBitcoin.go_to_chrome(WhatIsBitcoin.java:47)
        at ?.When Go to chrome(./features/WhatIsBitcoin.feature:4)

    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 86.657 sec <<< FAILURE! - in TestSuite
    feature(com.accenture.TestRunner.TestRunner)  Time elapsed: 85.109 sec  <<< FAILURE!
    cucumber.runtime.CucumberException: 
    org.openqa.selenium.TimeoutException: timeout: Timed out receiving message from renderer: 9.996
      (Session info: chrome=73.0.3683.86)
      (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 0 milliseconds
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
    System info: host: 'BDC11-L-FYK3VP2', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:\windows\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:51833}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.86, webStorageEnabled: true}
    Session ID: 1b4d8402a8e29651ed2c7a773c11ca37
        at com.accenture.TestRunner.TestRunner.feature(TestRunner.java:42)
    Caused by: org.openqa.selenium.TimeoutException: 
    timeout: Timed out receiving message from renderer: 9.996
      (Session info: chrome=73.0.3683.86)
      (Driver info: chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
    Command duration or timeout: 0 milliseconds
    Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
    System info: host: 'BDC11-L-FYK3VP2', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
    Driver info: org.openqa.selenium.chrome.ChromeDriver
    Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:\windows\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:51833}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), rotatable: false, setWindowRect: true, strictFileInteractability: false, takesHeapSnapshot: true, takesScreenshot: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 73.0.3683.86, webStorageEnabled: true}
    Session ID: 1b4d8402a8e29651ed2c7a773c11ca37


    Results :

    Failed tests: 
      TestRunner.feature:42 » Cucumber org.openqa.selenium.TimeoutException: timeout...

    Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  01:33 min
    [INFO] Finished at: 2019-03-26T23:16:45+05:30
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project extent-reporting: There are test failures.
    [ERROR] 
    [ERROR] Please refer to C:\Program Files (x86)\Jenkins\workspace\CucumberBDDFramework\target\surefire-reports for the individual test results.
    [ERROR] -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
    Build step 'Execute Windows batch command' marked build as failure
    Finished: FAILURE
4个回答

14

看起来您正在使用 chromedriver=73.0.3683.68chrome=73.0.3683.86Windows 操作系统

John Chen(chromedriver 的所有者)最近已确认:

我们已经确认了在 Windows 上由服务(例如 Jenkins 或任务计划程序)启动 Chrome 73.0.3686.75 时截图存在问题。有关更多详细信息,请参见https://crbug.com/942023。对此造成的任何不便,我们深感抱歉。

然而,我们还没有能够在 Linux 上观察到类似的问题,因此我们非常感谢您提供的任何有助于我们在 Linux 上重现问题的帮助。我们没有访问 TeamCity,但我们已经使用 Selenium 生成的 Docker 映像(selenium/standalone-chrome:3.141.59-lithium)测试了截图,并未发现任何问题。

chromedriver73


更新

我们找出了主要问题。主要问题不在于 ChromeDriver v73.x,而在于 Chrome v73.x,John 正式确认:

根本原因确实在于 Chrome 73.x,而不是 ChromeDriver。我们正在与 Chrome 开发人员合作寻找解决方案。

chrome73_issue


解决方案

解决方案如下:

注意:如果您正在使用 Chrome 版本 72,请下载 ChromeDriver 2.46 或 ChromeDriver 72.0.3626.69


结语


更新(2019年4月3日)

通过 ChromeOptions() 的实例添加

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-features=VizDisplayCompositor");
WebDriver driver = new ChromeDriver(options);
driver.get("https://google.com");

谢谢DevanjanB。看起来我需要降级Chrome版本,这样就可以正常工作了。希望Chrome尽快解决这个问题。 - Ajinkya
谷歌是否提供访问旧版Chrome的任何地方?我在网上找到的都是第三方网站的下载,我宁愿避免那样做。 - Tyler Nielsen
不,@TylerNielsen,没有地方可以访问旧版本的Chrome构建。 - Ryan Shillington
如果您之前添加了 disable-features=VizDisplayCompositor,则在 Chrome 79 中需要将其删除,否则会出现此错误。 - Ryan Shillington
它在Chrome 94(Mac)上仍然适用。但是这里提供的更新解决方案(2019年4月)似乎可以正常工作。 - user2235215
这仍然是一个问题,使用chromedriver版本:103.0.5060.134,添加上述的“VizDisplayCompositor”并不起作用。 - ndtreviv

0

我之前也遇到了Chromedriver 81的同样问题,但是我已经更新到了83版本,现在可以正常工作。

请尝试一下......


1
我们在使用Chrome 83版本的Jenkins时偶尔会遇到这种情况。 - casper

0

我在使用Team City构建时,以无头模式运行相同版本的Chrome / Chromedriver时遇到了同样的问题。这是在2019年3月25日构建服务器上安装最新更新后开始出现的。

首先截图的原因是测试也由于我怀疑与虚拟渲染有关的缺陷而开始失败,再次限制了当通过服务(TeamCity)运行Chrome实例时的无头模式。

当我在构建服务器VM上从命令提示符运行构建脚本时,所有测试都可以正常运行。

我通过降级Chrome版本来解决了这个问题。说起来容易做起来难:

  1. 我找不到获取旧版Chrome的官方方法,但我找到了这个链接,其中托管了一些旧版。使用时请自行决定风险:https://www.slimjet.com/chrome/google-chrome-old-version.php

  2. 我下载了版本 71.0.3578.80

  3. 从构建服务器卸载Chrome,运行此安装程序。

  4. 在安装过程中创建更新目录后立即将文件 GoogleUpdate.exe 重命名以防止其自我更新:C:\Program Files (x86)\Google\Update

  5. 在任务计划程序中禁用Google Chrome更新任务。

更新:这里的一个答案表明可以通过向chromedriver传递一些额外参数来解决问题,我尚未测试此解决方案:

https://sqa.stackexchange.com/a/38456/37816


0

我曾经遇到过同样的问题,我通过删除代码使其正常工作。

 chromeOptions.addArguments("--window-size=1920,1080");

或者使用

 chromeOptions.addArguments("--window-size=1920,1080");
 chromeOptions.addArguments("--force-device-scale-factor=1");

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接