超时从渲染器接收消息:10.000 在 Windows 上通过 Jenkins 使用 chromedriver 和 chrome 捕获屏幕截图 [英] Timed out receiving message from renderer: 10.000 while capturing screenshot using chromedriver and chrome through Jenkins on Windows

查看:32
本文介绍了超时从渲染器接收消息:10.000 在 Windows 上通过 Jenkins 使用 chromedriver 和 chrome 捕获屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows 10浏览器:铬浏览器版本:Version 73.0.3683.86(正式版)(32位)

我正在运行 selenium cucumber BDD 项目,我正在验证一页的标题.我正在使用范围报告版本 4.项目在本地成功运行.但是当我通过 Jenkins 运行它时,它在捕获屏幕截图并显示以下错误时失败.

如果我从 pom.xml 中删除了 surfire 插件,那么测试不会通过 Jenkins 运行.

在 Jenkins 的 Execute Windows Batch 命令选项中,我给出了以下命令

C:Program Files (x86)JenkinsworkspaceCucumberBDDFrameworkmvn 测试

TestRunner

 包 com.accenture.TestRunner;导入 org.testng.annotations.AfterClass;导入 org.testng.annotations.Test;导入 org.testng.annotations.BeforeClass;导入 org.testng.annotations.AfterClass;导入 org.testng.annotations.BeforeClass;导入 org.testng.annotations.DataProvider;导入 org.testng.annotations.Test;导入 cucumber.api.CucumberOptions;导入 cucumber.api.testng.AbstractTestNGCucumberTests;导入 cucumber.api.testng.CucumberFeatureWrapper;进口黄瓜.api.testng.TestNGCucumberRunner;/*** @作者 ajinkya.pande**/@黄瓜选项(features="./features/WhatIsBitcoin.feature",胶水= {com.accenture.StepDef"},标签= {"@ExtentReport"},干运行 = 假)公共类TestRunner {//编写以下步骤或尝试扩展 AbstractTestNGCucumberTests私有TestNGCucumberRunner testNGCucumberRunner;@BeforeClass(alwaysRun = true)公共无效 setUpClass() 抛出异常{testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());}@Test(dataProvider = "功能")公共无效特征(CucumberFeatureWrapper cucumberFeature){testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());}@DataProvider公共对象 [][] 特征(){返回 testNGCucumberRunner.provideFeatures();}@AfterClass(alwaysRun = true)public void tearDownClass() 抛出异常{testNGCucumberRunner.finish();}}

步骤定义

 包 com.accenture.listeners;导入java.io.File;导入 java.io.IOException;导入 java.text.DateFormat;导入 java.text.SimpleDateFormat;导入 java.util.Date;导入 org.apache.commons.io.FileUtils;导入 org.openqa.selenium.OutputType;导入 org.openqa.selenium.TakesScreenshot;导入 org.openqa.selenium.WebDriver;导入 com.accenture.Utility.Constants;导入 com.aventstack.extentreports.ExtentReports;导入 com.aventstack.extentreports.ExtentTest;导入 com.aventstack.extentreports.markuputils.ExtentColor;导入 com.aventstack.extentreports.markuputils.MarkupHelper;导入 com.aventstack.extentreports.reporter.ExtentHtmlReporter;导入 com.aventstack.extentreports.reporter.configuration.Theme;/*** @作者 ajinkya.pande**/公共类 ExtentReportListener 扩展常量 {公共静态ExtentHtmlReporter报告=空;公共静态范围报告范围=空;公共静态范围测试测试=空;公共静态 ExtentReports setUp() {字符串报告位置 = "./Reports/Extent_Report.html";报告 = 新的 ExtentHtmlReporter(reportLocation);report.config().setDocumentTitle("自动化测试报告");report.config().setReportName("自动化测试报告");report.config().setTheme(Theme.STANDARD);System.out.println("Extent 报告位置已初始化...");报告.start();范围=新范围报告();extent.attachReporter(报告);extent.setSystemInfo("应用程序", "Youtube");extent.setSystemInfo("操作系统", System.getProperty("os.name"));extent.setSystemInfo("用户名", System.getProperty("user.name"));System.out.println("系统信息设置在 Extent Report");返回范围;}public static void testStepHandle(String teststatus, WebDriver driver, ExtentTest extenttest, Throwable throwable) {如果(teststatus.equals(失败")){extenttest.fail(MarkupHelper.createLabel("测试用例失败:", ExtentColor.RED));extenttest.error(throwable.fillInStackTrace());尝试 {extenttest.addScreenCaptureFromPath(captureScreenShot(driver));} 捕捉(IOException e){e.printStackTrace();}如果(驱动程序!= null){driver.quit();}if (teststatus.equals("PASS")) {extenttest.pass(MarkupHelper.createLabel("测试用例通过:", ExtentColor.GREEN));尝试 {extenttest.addScreenCaptureFromPath(captureScreenShot(driver));} 捕捉(IOException e){e.printStackTrace();}}}}公共静态字符串 captureScreenShot(WebDriver 驱动程序)抛出 IOException {TakesScreenshot 屏幕 = (TakesScreenshot) 驱动程序;文件 src = screen.getScreenshotAs(OutputType.FILE);字符串 dest = SCRRENSHOT_PATH + getcurrentdateandtime() + ".png";文件目标=新文件(目标);FileUtils.copyFile(src, target);返回目的地;}私有静态字符串 getcurrentdateandtime() {字符串 str = null;尝试 {DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss:SSS");日期日期 = 新日期();str = dateFormat.format(date);str = str.replace(" ", "").replaceAll("/", "").replaceAll(":", "");} 捕捉(异常 e){}返回字符串;}}

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>范围报告</artifactId><版本>0.0.1-SNAPSHOT</版本><构建><插件><!-- <插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><版本>3.7.0</版本><配置><来源>1.8</来源><目标>1.8</目标><编码>UTF-8</编码></配置></插件>--><插件><artifactId>maven-compiler-plugin</artifactId><版本>3.1</版本><配置><叉子>1.7</叉子><可执行文件>C:Program FilesJavajdk1.8.0_191injavac.exe</executable></配置></插件><!-- <插件><groupId>net.masterthought</groupId><artifactId>maven-cucumber-reporting</artifactId><版本>3.15.0</版本><执行><执行><id>执行</id><阶段>验证</阶段><目标><目标>生成</目标></目标><配置><outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory><cucumberOutput>target/cucumber-reports/CucumberTestReport.json</cucumberOutput></配置></执行></执行></插件>--><插件><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><版本>2.19.1</版本><配置><suiteXmlFiles>testng.xml</suiteXmlFiles></配置></插件></插件></构建><依赖关系><!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java --><依赖性><groupId>org.seleniumhq.selenium</groupId><artifactId>selenium-java</artifactId><版本>3.11.0</版本></依赖><依赖性><groupId>info.cukes</groupId><artifactId>黄瓜-java</artifactId><版本>1.2.5</版本></依赖><!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng --><依赖性><groupId>info.cukes</groupId><artifactId>黄瓜测试</artifactId><版本>1.2.5</版本></依赖><!-- https://mvnrepository.com/artifact/org.testng/testng --><依赖性><groupId>org.testng</groupId><artifactId>testng</artifactId><版本>6.9.8</版本></依赖><依赖性><groupId>info.cukes</groupId><artifactId>cucumber-jvm-deps</artifactId><版本>1.0.5</版本><范围>提供的</范围></依赖><依赖性><groupId>com.aventstack</groupId><artifactId>extentreports</artifactId><版本>4.0.6</版本></依赖><依赖性><groupId>org.freemarker</groupId><artifactId>freemarker</artifactId><版本>2.3.23</版本></依赖><!-- https://mvnrepository.com/artifact/org.apache.commons/commons-io --><依赖性><groupId>org.apache.commons</groupId><artifactId>commons-io</artifactId><版本>1.3.2</版本></依赖></依赖关系></项目>

詹金斯日志:

<小时>

 T E S T S-------------------------------------------------------运行测试套件开始...............范围报告位置已初始化...系统信息.在范围报告中设置在端口 8950 上启动 ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72)只允许本地连接.请保护 ChromeDriver 和相关测试框架使用的端口,防止恶意代码访问.2019 年 3 月 26 日晚上 11:15:27 org.openqa.selenium.remote.ProtocolHandshake createSession信息:检测到的方言:OSS[15536​​22354.306][严重]:从渲染器接收消息超时:10.000[15536​​22354.307][警告]:截图失败,重试[15536​​22364.313][严重]:从渲染器接收消息超时:9.996[15536​​22374.336][严重]:从渲染器接收消息超时:9.998[15536​​22374.337][警告]:截图失败,重试[15536​​22384.337][严重]:从渲染器接收消息超时:9.998[15536​​22394.343][严重]:从渲染器接收消息超时:10.000[15536​​22394.344][警告]:截图失败,重试[15536​​22404.345][严重]:从渲染器接收消息超时:9.996失败的场景:./features/WhatIsBitcoin.feature:3 # 场景:测试范围报告1个场景(1个失败)4 个步骤(1 个失败,3 个跳过)1m25.069sorg.openqa.selenium.TimeoutException:超时:从渲染器接收消息超时:9.996(会话信息:chrome=73.0.3683.86)(驱动程序信息:chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),平台=Windows NT 10.0.17134 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:0 毫秒构建信息:版本:'3.11.0',修订:'e59cfb3',时间:'2018-03-11T20:26:55.152Z'系统信息:主机:'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'驱动程序信息:org.openqa.selenium.chrome.ChromeDriver功能 {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:windowsTEMPscoped_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:正常,平台:XP,平台名称:XP,代理:Proxy(),可旋转:false,setWindowRect:true,strictFileInteractability:false,takeHeapSnapshot:true,takeScreenshot:true,超时:{implicit:0,pageLoad:300000,脚本:30000},unexpectedAlertBehaviour:忽略,unhandledPromptBehavior:忽略,版本:73.0.3683.86,webStorageEnabled:true}会话 ID:1b4d8402a8e29651ed2c7a773c11ca37在 sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)在 sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)在 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)在 java.lang.reflect.Constructor.newInstance(Constructor.java:423)在 org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)在 org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)在 org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)在 org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)在 org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)在 org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)在 org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)在 org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602)在 org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(RemoteWebDriver.java:291)在 com.accenture.listeners.ExtentReportListener.captureScreenShot(ExtentReportListener.java:81)在 com.accenture.StepDef.WhatIsBitcoin.go_to_chrome(WhatIsBitcoin.java:47)在 ?.When Go to chrome(./features/WhatIsBitcoin.feature:4)测试运行:1,失败:1,错误:0,跳过:0,经过的时间:86.657 秒 <<<<失败!- 在测试套件中特征(com.accenture.TestRunner.TestRunner)经过时间:85.109秒<<<<失败!cucumber.runtime.CucumberException:org.openqa.selenium.TimeoutException:超时:从渲染器接收消息超时:9.996(会话信息:chrome=73.0.3683.86)(驱动程序信息:chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),平台=Windows NT 10.0.17134 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:0 毫秒构建信息:版本:'3.11.0',修订:'e59cfb3',时间:'2018-03-11T20:26:55.152Z'系统信息:主机:'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'驱动程序信息:org.openqa.selenium.chrome.ChromeDriver功能 {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:windowsTEMPscoped_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:正常,平台:XP,平台名称:XP,代理:Proxy(),可旋转:false,setWindowRect:true,strictFileInteractability:false,takeHeapSnapshot:true,takeScreenshot:true,超时:{implicit:0,pageLoad:300000,脚本:30000},unexpectedAlertBehaviour:忽略,unhandledPromptBehavior:忽略,版本:73.0.3683.86,webStorageEnabled:true}会话 ID:1b4d8402a8e29651ed2c7a773c11ca37在 com.accenture.TestRunner.TestRunner.feature(TestRunner.java:42)引起:org.openqa.selenium.TimeoutException:超时:从渲染器接收消息超时:9.996(会话信息:chrome=73.0.3683.86)(驱动程序信息:chromedriver=73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72),平台=Windows NT 10.0.17134 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:0 毫秒构建信息:版本:'3.11.0',修订:'e59cfb3',时间:'2018-03-11T20:26:55.152Z'系统信息:主机:'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'驱动程序信息:org.openqa.selenium.chrome.ChromeDriver功能 {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 73.0.3683.68 (47787ec04b6e3..., userDataDir: C:windowsTEMPscoped_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:正常,平台:XP,平台名称:XP,代理:Proxy(),可旋转:false,setWindowRect:true,strictFileInteractability:false,takeHeapSnapshot:true,takeScreenshot:true,超时:{implicit:0,pageLoad:300000,脚本:30000},unexpectedAlertBehaviour:忽略,unhandledPromptBehavior:忽略,版本:73.0.3683.86,webStorageEnabled:true}会话 ID:1b4d8402a8e29651ed2c7a773c11ca37结果 :失败的测试:TestRunner.feature:42 » Cucumber org.openqa.selenium.TimeoutException: timeout...测试运行:1,失败:1,错误:0,跳过:0[信息] ----------------------------------------------------------------------[信息] 构建失败[信息] ----------------------------------------------------------------------[INFO] 总时间:01:33 分钟[INFO] 完成时间:2019-03-26T23:16:45+05:30[信息] ----------------------------------------------------------------------[错误] 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project extent-reporting: 有测试失败.[错误][错误] 个别测试结果请参考 C:Program Files (x86)JenkinsworkspaceCucumberBDDFramework	argetsurefire-reports.[错误]->[帮助1][错误][错误] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven.[错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录.[错误][错误] 有关错误和可能的解决方案的更多信息,请阅读以下文章:[错误] [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException构建步骤执行 Windows 批处理命令"将构建标记为失败完成:失败

解决方案

看来你在 上使用 chromedriver=73.0.3683.68chrome=73.0.3683.86视窗操作系统

John Chen(所有者 - chromedriver)最近证实:

<块引用>

我们已确认当 Chrome 73.0.3686.75 由 Windows 上的服务(例如 Jenkins 或任务调度程序)启动时出现截图问题.请参阅

<小时>

更新

我们能够挖掘出主要问题.主要问题不在于 ChromeDriver v73.x 本身,而在于 Chrome v73.x,John 正式确认为:

<块引用>

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

<小时>

解决方案

解决办法是:

<块引用>

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

<小时>

结尾

<小时>

更新(2019 年 4 月 3 日)

通过 ChromeOptions() 的实例添加参数 --disable-features=VizDisplayCompositor 似乎可以解决问题:

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

OS: Windows 10 Browser: Chrome Browser version: Version 73.0.3683.86 (Official Build) (32-bit)

I am running selenium cucumber BDD project where I am verifying title of one page. I am using extent-report version4. Project running successfully in local. But when i am running it through Jenkins, its failing while capturing screenshot and showing below error.

If i remove the surfire plugin from pom.xml then the TEST is not running via Jenkins.

In Execute Windows Batch command option of Jenkins i have given below command

C:Program Files (x86)JenkinsworkspaceCucumberBDDFramework
mvn test

TestRunner

    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();
        }

    }

StepDefinition

    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 FilesJavajdk1.8.0_191injavac.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 Log:


     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:windowsTEMPscoped_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:windowsTEMPscoped_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:windowsTEMPscoped_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)JenkinsworkspaceCucumberBDDFramework	argetsurefire-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

解决方案

Seems you are using chromedriver=73.0.3683.68 and chrome=73.0.3683.86 on Windows OS

John Chen (Owner - chromedriver) recently have confirmed that:

We have confirmed issues with take screenshot when Chrome 73.0.3686.75 is started by a service (such as Jenkins or Task scheduler) on Windows. Please see https://crbug.com/942023 for more details. We apologize for any inconvenience caused by this.

However, we haven't yet been able to observe similar issue on Linux, so we appreciate any help you can provide to enable us to reproduce the issue on Linux. We don't have access to TeamCity, but we have tested take screenshot using Docker image produced by Selenium (selenium/standalone-chrome:3.141.59-lithium), and didn't find any problems.


Update

We were able to dig up the main issue. The main issue is not with ChromeDriver v73.x as such but with Chrome v73.x and John officially confirms it as:

The root cause is indeed in Chrome 73.x, not in ChromeDriver. We are working with Chrome devs to find a solution.


Solution

The solution would be to:

Note: If you are using Chrome version 72, please download ChromeDriver 2.46 or ChromeDriver 72.0.3626.69


Outro


Update(03-April-2019)

Adding the argument --disable-features=VizDisplayCompositor through an instance of ChromeOptions() seems solves the issue:

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

这篇关于超时从渲染器接收消息:10.000 在 Windows 上通过 Jenkins 使用 chromedriver 和 chrome 捕获屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆