尝试运行 Testproject sdk 时出现此错误。TestProject 代理运行良好。该令牌也可以正常工作。我试图在网上找到一个解决方案,但我找不到任何解决这个错误的方法。
public static void main(final String[] args) throws Exception {
ChromeDriver driver = new DriverBuilder<ChromeDriver>(new ChromeOptions())
.withRemoteAddress(new URL("http://localhost:8585"))
.withToken("XXX")
.build(ChromeDriver.class);
driver.navigate().to("https://example.testproject.io/web/");
driver.findElement(By.cssSelector("#name")).sendKeys("John Smith");
driver.findElement(By.cssSelector("#password")).sendKeys("12345");
driver.findElement(By.cssSelector("#login")).click();
boolean passed = driver.findElement(By.cssSelector("#logout")).isDisplayed();
if (passed) {
System.out.println("Test Passed");
} else {
System.out.println("Test Failed");
}
driver.quit();
错误信息是
Exception in thread "main" org.openqa.selenium.WebDriverException: Failed to create an instance of io.testproject.sdk.drivers.web.ChromeDriver
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'S01128', ip: '192.168.42.18', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.1'
Driver info: driver.version: unknown
at io.testproject.sdk.DriverBuilder.build(DriverBuilder.java:263)
at DemoClass.main(DemoClass.java:17)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at io.testproject.sdk.DriverBuilder.build(DriverBuilder.java:251)
... 1 more
Caused by: java.lang.NoClassDefFoundError: org/apache/http/config/Lookup
at org.apache.http.impl.client.HttpClients.custom(HttpClients.java:48)
at io.testproject.sdk.internal.rest.AgentClient.<init>(AgentClient.java:270)
at io.testproject.sdk.internal.rest.AgentClient.getClient(AgentClient.java:573)
at io.testproject.sdk.drivers.web.ChromeDriver.<init>(ChromeDriver.java:917)
... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.http.config.Lookup
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 11 more
Process finished with exit code 1
我正在使用JDK 11。以前我使用JDK 17,然后降级到11,但它并没有解决问题。
这是POM文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>org.example</groupId>
<artifactId>FourWDSupaCentre1.0</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>17.0.1</maven.compiler.source>
<maven.compiler.target>17.0.1</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.testproject/java-sdk -->
<dependency>
<groupId>io.testproject</groupId>
<artifactId>java-sdk</artifactId>
<version>1.2.4-RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<version>3.11.10</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>