我使用 ChromeDriver 和 Selenium 来运行我的自动化测试。测试套件在 Eclipse 和命令行中均成功运行。但是,当我尝试在 Jenkins 中构建它时,它不会运行。
这是我在 Jenkins 中的工作配置(为了保密起见,所有信息的名称均已经过 sanitizer ): 我可以确认 Ant 正在运行 JDK8。
这是构建的控制台输出:
[junit] Running main.TESTNAME
[junit] Starting ChromeDriver 2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f) on port 27352
[junit] Only local connections are allowed.
[junit] Apr 26, 2018 3:52:34 PM org.openqa.selenium.remote.ProtocolHandshake createSession
[junit] INFO: Detected dialect: OSS
[junit] Running through test suite as:
[junit] User: USERNAME
[junit] URL: CONFIDENTIAL
[junit] [30.168][SEVERE]: Timed out receiving message from renderer: 20.000
[junit] [30.170][SEVERE]: Timed out receiving message from renderer: -0.003
[junit] Total number of tests ran for TESTNAME: 5, Number of tests failures: 4, Number of tests ignored: 0
[junit] testViewProfileDetailsButtonAndBrowseBack(test.TESTNAME): timeout
[junit] (Session info: chrome=64.0.3282.119)
[junit] (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64) (WARNING: The server did not provide any stacktrace information)
[junit] Command duration or timeout: 0 milliseconds
[junit] Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:14.666Z'
[junit] System info: host: 'PC', ip: 'IP', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_151'
[junit] Driver info: org.openqa.selenium.chrome.ChromeDriver
[junit] Capabilities {acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.33.506120 (e3e53437346286..., userDataDir: C:\WINDOWS\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 64.0.3282.119, webStorageEnabled: true}
下面的 build.xml
大部分是自动生成的,除了我添加 JUnit 集成的末尾:
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="build" name="PROJECTSeleniumTest">
<property environment="env"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.8"/>
<property name="source" value="1.8"/>
<path id="PROJECTSeleniumTest.classpath">
<pathelement location="bin"/>
<pathelement location="lib/byte-buddy-1.7.5.jar"/>
<pathelement location="lib/client-combined-3.8.1-sources.jar"/>
<pathelement location="lib/client-combined-3.8.1.jar"/>
<pathelement location="lib/commons-codec-1.10.jar"/>
<pathelement location="lib/commons-exec-1.3.jar"/>
<pathelement location="lib/commons-logging-1.2.jar"/>
<pathelement location="lib/gson-2.8.2.jar"/>
<pathelement location="lib/guava-23.0.jar"/>
<pathelement location="lib/hamcrest-core-1.3.jar"/>
<pathelement location="lib/httpclient-4.5.3.jar"/>
<pathelement location="lib/httpcore-4.4.6.jar"/>
<pathelement location="lib/junit-4.12.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project,junit" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="PROJECTSeleniumTest.classpath"/>
</javac>
</target>
<target name="create_directory">
<echo message="Create the directory JenkinsTestReports\" />
<mkdir dir="JenkinsTestReports" />
</target>
<target name="junit" depends="create_directory">
<echo message="${java.version}"/>
<junit printsummary="yes" fork="yes" haltonfailure="yes">
<classpath>
<path refid="PROJECTSeleniumTest.classpath" />
<pathelement location="${basedir}\bin"/>
</classpath>
<batchtest todir="JenkinsTestReports" fork="true">
<fileset dir="${basedir}\bin">
<include name="main\TESTNAME.class"/>
</fileset>
</batchtest>
<formatter type="xml"/>
<formatter type="plain"/>
</junit>
</target>
有谁知道是什么原因吗?谢谢。
最佳答案
此错误消息...
[30.168][SEVERE]: Timed out receiving message from renderer: 20.000
...意味着 ChromeDriver 无法启动新的 Chrome 浏览器进程。
您的主要问题是您正在使用的二进制文件之间的版本兼容性,如下所示:
- 您正在使用 chromedriver=2.33
- chromedriver=2.33 的发行说明明确提到以下内容:
Supports Chrome v60-62
- 您正在使用chrome=64.0
- ChromeDriver v2.35 的发行说明明确提到以下内容:
Supports Chrome v62-64 (includes the browser version you are using)
- 您的Selenium 客户端版本是3.8.1。
- 您的JDK版本是1.8.0_151,这是相当旧的。
因此,JDK v8u151、Selenium Client v3.8.1、ChromeDriver v2.33 和 Chrome 之间存在明显不匹配浏览器 v64.0
解决方案
- 将 JDK 升级到最新级别 JDK 8u162 .
- 将Selenium升级到当前级别 Version 3.11.0 .
- 将ChromeDriver升级到当前的ChromeDriver v2.38级别。
- 将 Chrome 版本保持在 Chrome v66.x 级别。 (as per ChromeDriver v2.38 release notes)
- 通过IDE清理您的项目工作区,并仅使用所需的依赖项重建项目。
- 使用CCleaner工具可以清除执行测试套件之前和之后的所有操作系统杂务。
- 如果您的基本网络客户端版本太旧,请通过 Revo Uninstaller 卸载它并安装最新的 GA 和已发布版本的Web 客户端。
- 重新启动系统。
- 执行您的
@Test
。
关于selenium - 通过 Jenkins 上的 Selenium 执行测试套件时出现错误 [SEVERE] : Timed out receiving message from renderer: 20. 000,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55949492/