我在测试包中创建了一个maven项目,添加了一个testNg测试用例:
public class SampleTestNGTest {
private WebDriver driver;
@Test
public void testEasy() {
System.setProperty("webdriver.chrome.driver","D:\\NetBeansProjects\\webdrivertestng\\Drivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.get("example.com");
String title = driver.getTitle();
Assert.assertTrue(title.contains("abcd"));
//System.out.println("checking new build");
}
@AfterTest
public void afterTest() {
driver.quit();
}
}
我在Netbeans中完美地执行了它,没有任何错误。但是当我从Jenkins执行(与Jenkins集成maven项目)时,它显示以下错误:
Running SampleTestNGTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator@6d8acf
Starting ChromeDriver 2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf) on port 2916
Only local connections are allowed.
Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 64.572 sec <<< FAILURE!
testEasy(SampleTestNGTest) Time elapsed: 63.571 sec <<< FAILURE!
org.openqa.selenium.WebDriverException: unknown error: unable to discover open pages
(Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.1 SP1 x86) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 61.32 seconds
Build info: version: '2.53.0', revision: '35ae25b1534ae328c771e0856c93e187490ca824', time: '2016-03-15 10:43:46'
System info: host: 'MVSL1742', ip: '172.16.17.42', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_05'
Driver info: org.openqa.selenium.chrome.ChromeDriver
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:408)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at SampleTestNGTest.testEasy(SampleTestNGTest.java:24)
afterTest(SampleTestNGTest) Time elapsed: 63.573 sec <<< FAILURE!
java.lang.NullPointerException
at SampleTestNGTest.afterTest(SampleTestNGTest.java:37)
Results :
Failed tests: testEasy(SampleTestNGTest): unknown error: unable to discover open pages(..)
afterTest(SampleTestNGTest)
Tests run: 2, Failures: 2, Errors: 0, Skipped: 0
如果我使用FirefoxDriver,则构建执行时没有错误。
如果我使用ChromeDriver,则构建会执行错误。
pom .xml
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>2.53.0</version>
</dependency>
编辑:在我的本地计算机上,ChromeDriver版本为2.9