代码很简单,如下
AndroidDriver androidDriver = null;
DesiredCapabilities cap=new DesiredCapabilities();
//cap.setCapability("noReset", true);
cap.setCapability("deviceName", "Android Emulator");//设备名称
cap.setCapability(CapabilityType.BROWSER_NAME, "");
cap.setCapability("platformName", "Android");
//cap.setCapability("platformName", "Android"); //安卓自动化还是 iOS 自动化
cap.setCapability("platformVersion", "7.1.1"); //安卓操作系统版本
//cap.setCapability("sessionOverride", true);//重新启动的话会重置 session

cap.setCapability("appPackage","com.xunmeng.pinduoduo");//被测 app 的包名
cap.setCapability("appActivity",".ui.activity.MainFrameActivity");//被测 app 的入口 Activity 名称

//cap.setCapability("unicodeKeyboard", true); //支持中文输入
//cap.setCapability("resetKeyboard", true); //支持中文输入,必须两条都配置

try {
androidDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,cap);//把以上配置传到 appium 服务端并连接手机")
} catch (MalformedURLException e) {
e.printStackTrace();
}
androidDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//隐式等待

//找到横滑栏,挨个点击 icon
List eList = androidDriver.findElements(By.id("image"));
for(WebElement element:eList){
element.click();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
androidDriver.pressKeyCode(AndroidKeyCode.BACK);
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
这行报错:androidDriver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub,cap"));
异常如下:
Connected to the target VM, address: '127.0.0.1:62301', transport: 'socket'
Exception in thread "main" java.lang.IllegalAccessError: tried to access method org.openqa.selenium.Platform.extractFromSysProperty(Ljava/lang/String;) Lorg/openqa/selenium/Platform; from class org.openqa.selenium.remote.RemoteWebDriver
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:271)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:36)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:114)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:132)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:92)
at com.pdd.test.MainDemo.main(MainDemo.java:39)
实在没看懂什么意思,google 了也没找到相关资料,请大家赐教


↙↙↙阅读原文可查看相关链接,并与作者交流