我正在尝试使用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浏览器。
感谢任何帮助!
答案 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
您的主要问题是您使用的二进制文件之间的版本兼容性,如下所示:
因此, JDK v7u95 , Selenium Client v2.53.1 , ChromeDriver 版本( v2.35)之间明显不匹配)和 Chrome浏览器版本( v64.0 )
而不是通用的定位器策略,而不是 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}