我有一个自动化项目,它与java-client 5.0.4正常工作,同时将其更新为java-client:pom.xml
文件中的6.1.0,然后在IDE上显示以下错误
java.lang.NoClassDefFoundError: org/openqa/selenium/remote/internal/OkHttpClient$Factory
在一秒钟内显示错误,似乎与Appium服务器没有交互,因此在Appium服务器上没有错误日志
项目:Maven
Appium服务器:1.8.1
答案 0 :(得分:0)
我已尝试使用最新的javaclient 6.1.0和appium 1.8.1桌面执行以下代码,并且该代码正在运行。请尝试使用带有提及的pom.xml的以下代码。它已在模拟器中成功运行chrome浏览器,并且测试通过了。
public class AppiumClass {
static AndroidDriver<WebElement> driver;
static DesiredCapabilities capabilities;
@BeforeTest
public static void start() throws MalformedURLException, InterruptedException{
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4725/wd/hub"),setCapsforMobileBrowser(capabilities));
Thread.sleep(4000);
Set<String> contextHandle = driver.getContextHandles();
for(String str:contextHandle){
System.out.println(str);
}
Thread.sleep(2000);
driver.context("NATIVE_APP");
driver.findElement(By.id("com.android.chrome:id/terms_accept")).click();
driver.findElement(By.id("com.android.chrome:id/negative_button")).click();
driver.context("CHROMIUM");
driver.get("https://www.google.com");
Thread.sleep(6000);
driver.findElement(By.id("lst-ib")).sendKeys("appium latest version");
Thread.sleep(3000);
driver.findElement(By.xpath("(//h3[@class='r'])[1]//a")).click();
System.out.println(driver.getTitle());
driver.quit();
}
@Test
public void init() throws MalformedURLException, InterruptedException {
try {
start();
} catch (Exception e) {
System.out.println("inside catch");
e.printStackTrace();
}
}
public static DesiredCapabilities setCapsforMobileBrowser(DesiredCapabilities capabilities){
capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.8.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("autoAcceptAlerts", true);
return capabilities;
}
@AfterTest
public void tearDown(){
}
}
<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>com.test</groupId>
<artifactId>AppiumLatest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.13.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<testFailureIgnore> false </testFailureIgnore>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</project>
答案 1 :(得分:0)
您似乎正在使用旧的硒版本,并且仅更新java-client
版本。在java-client 6.0
之后,您需要selenium version 3.12.0
或以后。请检查并更新。
请告知我们,即使更新后仍然不起作用