【发布时间】:2019-03-31 00:17:03
【问题描述】:
我使用 TestNG 为 selenium webdriver(Chrome 浏览器)创建了一个 Maven 项目。我使用 TestNG 运行基本测试,Chrome 浏览器已成功打开。如果我使用“Maven 测试”命令运行相同的测试并收到错误消息。
你能帮忙吗?我尝试了许多解决方案,如 Stack Overflow 建议的,但仍然不成功:(
我为基本测试“Hello World”运行“Maven 测试”并且构建成功 >>>“Maven 测试”创建成功构建的证据
我使用打开 Chrome 浏览器的命令运行 TestNG 测试,它运行正常 >>> TestNG 成功运行的证据
我使用命令运行“Maven 测试”以打开 Chrome 浏览器,但它不起作用 >>> 对此感到沮丧,尝试了 StackOverflow 中出现的所有解决方案但不成功
我已经创建了 testng.xml 文件
我为 Selenium-Java 和 Selenium-Server 依赖项以及 Chromedriver 和 SureFire 插件使用了不同的版本,但问题仍然存在,现在我为所有这些使用了最新版本(请参阅下面的 POM 文件了解更多详情)。
我已卸载并重新安装 Google Chrome,现在我拥有最新版本 73
我的机器上没有防火墙
POM 文件出现在下方
<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>MavenProject</groupId>
<artifactId>MavenProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.141.59</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
testng.xml 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="MavenPackage.NewTest"/>
</classes>
</test> <!-- Test -->
我的代码如下:
public class NewTest {
WebDriver driver;
@Test
public void MyFunction() {
try {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.get("http://www.ebay.com");
Thread.sleep(3000);
driver.quit();
System.out.println("Test passed");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
错误信息
Starting ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72) on port 49053
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 23.798 s <<< FAILURE! - in TestSuite
[ERROR] MyFunction(MavenPackage.NewTest) Time elapsed: 21.874 s <<< FAILURE!
org.openqa.selenium.WebDriverException:
Timed out waiting for driver server to start.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-DV883K3', ip: '192.168.1.109', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201'
Driver info: driver.version: ChromeDriver
at MavenPackage.NewTest.MyFunction(NewTest.java:20)
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for [http://localhost:49053/status] to be available after 20008 ms
at MavenPackage.NewTest.MyFunction(NewTest.java:20)
Caused by: java.util.concurrent.TimeoutException
at MavenPackage.NewTest.MyFunction(NewTest.java:20)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] NewTest.MyFunction:20 » WebDriver Timed out waiting for driver server to start...
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 28.467 s
[INFO] Finished at: 2019-03-30T23:32:42Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project MavenProject: There are test failures.
【问题讨论】:
标签: google-chrome selenium-webdriver testng maven-3