我正在使用appium最新版本1.8.1,selenium 3.14.0 java客户端,appium 6.1.0 java客户端。 下面是我获取android驱动程序实例的代码:
public AndroidDriver<?> driver;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, “1.8.1”);
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, “K9 Viraat”);
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, “6.0”);
capabilities.setCapability(MobileCapabilityType.PLATFORM, “Android”);
capabilities.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,
"UiAutomator2");
driver = new AndroidDriver<>(new URL(“https://0.0.0.0:4723/wd/hub”),
capabilities);
我有较早的appium 1.4和相应的Java客户端。但是更新到1.8.1版本后,我得到了错误消息:
“java.lang.NoClassDefFoundError:
org/openqa/selenium/remote/internal/OkHttpClient$Factory”
我还将selenium java客户端更新为3.14.0,但是它不起作用。 如果有人遇到过这种情况,请提供步骤来解决。
答案 0 :(得分:1)
您使用的jar文件有问题。 我建议您创建一个Maven项目,因为它易于管理依赖文件。在pom.xml文件中包括以下依赖项:
<!-- 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.14.0</version>
</dependency>
如下定义所需的功能。您需要在期望的功能中提供appPackage和appActivity。
AppiumDriver<MobileElement> driver;
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Android phone");
caps.setCapability("udid", "your device's udid");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "your device's platform version");
caps.setCapability("appPackage", "your app's appPackage name");
caps.setCapability("appActivity", "your app's main appActivity name");
driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);
使您已经启动了appium服务器。