jenkins服务器上的硒测试失败

时间:2018-02-27 14:47:48

标签: java selenium jenkins selenium-webdriver

我正在尝试使用Jbehave运行BDD测试用例,selenium在本地环境中运行良好但在我运行Jenkins时失败。错误我看到如下:

org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.xpath: //*[@id='my-id'] 
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' 
System info: host: 'lt29nxas000000u.opr.statefarm.org', ip: '10.56.8.88', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.11.6.el7.x86_64', java.version: '1.7.0_95' Session ID: 10a633701cc1b7e5b678d24c0ee8890e 
Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.org.chromium.Chromium.D1Awd8, chromedriverVersion=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, mobileEmulationEnabled=false, locationContextEnabled=true, pageLoadStrategy=normal, version=64.0.3282.186, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true, acceptInsecureCerts=false}]

我可以看到应用程序记录BDD执行产生的流量但是它无法获取该元素,我尝试增加超时值但没有运气。我在jenkins上使用Headless Chrome浏览器。

感谢任何帮助!

2 个答案:

答案 0 :(得分:0)

错误堆栈跟踪确实给出了一些关于错误发生的提示,如下所示:

org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for visibility of element located by By.xpath: //*[@id='my-id'] 
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09' 
System info: host: 'lt29nxas000000u.opr.statefarm.org', ip: '10.56.8.88', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-693.11.6.el7.x86_64', java.version: '1.7.0_95' Session ID: 10a633701cc1b7e5b678d24c0ee8890e 
Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{platform=LINUX, acceptSslCerts=false, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/tmp/.org.chromium.Chromium.D1Awd8, chromedriverVersion=2.35.528139 (47ead77cb35ad2a9a83248b292151462a66cd881)}, networkConnectionEnabled=false, unexpectedAlertBehaviour=, rotatable=false, setWindowRect=true, mobileEmulationEnabled=false, locationContextEnabled=true, pageLoadStrategy=normal, version=64.0.3282.186, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, webStorageEnabled=true, nativeEvents=true, hasTouchScreen=false, applicationCacheEnabled=false, takesScreenshot=true, acceptInsecureCerts=false}]

从错误堆栈跟踪中可以清楚地看出驱动程序信息无法识别如下:

Driver info: org.openqa.selenium.chrome.ChromeDriver

您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:

  • 您正在使用 chromedriver = 2.35
  • 您正在使用 chrome = 64.0
  • 您的 Selenium客户端 2016-06-30 19:26:09 2.53.1 ,几乎 2年年长。
  • 你的 JDK版 1.7.0_95 ,这很古老。

因此, JDK v7u95 Selenium Client v2.53.1 ChromeDriver 版本( v2.35)之间明显不匹配)和 Chrome浏览器版本( v64.0

解决方案

  • JDK 升级到最近的级别JDK 8u162
  • Selenium 升级到当前级别Version 3.9.1
  • ChromeDriver 保留在 ChromeDriver v2.35 级别。
  • Chrome 版本保留在 Chrome v64.x 级别。 ([根据ChromeDriver v2.35发行说明] [2])
  • 清除您的项目工作区重建您的项目仅具有所需的依赖项。
  • 使用CCleaner工具清除执行测试套件之前和之后的所有操作系统杂务。
  • 如果您的基本 Chrome 版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的Chrome版本。
  • 而不是通用的定位器策略,而不是 By.xpath:// * [@ id =' my-id'] 尝试使用更具体的Locator Strategy,它将唯一地标识 WebElement xpath的一个例子:

    //tagName[@attribute='attribute_value']
    
  • 执行@Test

答案 1 :(得分:0)

2.53.1似乎是一个在spring-boot项目中继承的版本。无论如何,你是否可以将它更新为更新的东西,你可以在我尝试的一些Selenium版本中找到以下3个选项,但是它们都应该与你驱动的Chrome驱动程序的v2.35.528161产生相同的结果使用:

1) Selenium 2.53.1:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("acceptInsecureCerts", true); // no dedicated method
WebDriver driver = new ChromeDriver(capabilities);

<强>结果

Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'xxxx', ip: 'x.y.z.w', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver                                                                                                                                                                                                                                                                                                                                                                                                                                             v--------v--------v  v-----------v----------v
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73), userDataDir=C:\Users\batman\AppData\Local\Temp\scoped_dir17748_29858}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=64.0.3282.186, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, acceptInsecureCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]

2) Selenium 3.4.0:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setAcceptInsecureCerts(true); // dedicated method
WebDriver driver = new ChromeDriver(capabilities);

<强>结果

Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'xxx', ip: 'x.y.z.w', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver                                                                                                                                                                                                                                                                                                                                                                                                                                             v---------v-------v  v-----------v----------v
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73), userDataDir=C:\Users\batman\AppData\Local\Temp\scoped_dir11844_18447}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=64.0.3282.186, platform=XP, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, acceptInsecureCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=}]

3) Selenium 3.9.1:

ChromeOptions options = new ChromeOptions(); 
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options); // use "Options" constructor instead of deprecated capabilities one

<强>结果

Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'
System info: host: 'xxxx', ip: 'x.y.z.w', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: org.openqa.selenium.chrome.ChromeDriver
              v-----------v-----------v  v---------v--------v
Capabilities {acceptInsecureCerts: true, acceptSslCerts: true, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.35.528161 (5b82f2d2aae0ca..., userDataDir: C:\Users\batman\AppDa...}, 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.186, webStorageEnabled: true}