appium 的启动
public void setUpAppiumServer() throws InterruptedException, MalformedURLException {
setNodeOrAppiumJSPath();
// start AppiumServer
PropertyConfigurator.configure("./src/main/resources/osvc/log4j.properties");
this.setServer(AppiumDriverLocalService.buildService(
new AppiumServiceBuilder().usingDriverExecutable(new File(nodePath))
.withArgument(GeneralServerFlag.LOG_LEVEL, "info")
.withAppiumJS(new File(appiumJSPath))
.withIPAddress("127.0.0.1").usingPort(4720)));
this.getServer().start();
// config appium
capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", DEVICE_NAME);
capabilities.setCapability("automationName", "Appium");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("noReset", true);
capabilities.setCapability("fullReset", "false");
capabilities.setCapability("sessionOverride", true);
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", false);
capabilities.setCapability("appPackage",APP_PACKAGE );
capabilities.setCapability("appActivity", APP_ACTIVITY);
ChromeOptions op= new ChromeOptions();
op.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
capabilities.setCapability(ChromeOptions.CAPABILITY, op);
//init driver
try {
driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4720/wd/hub"), capabilities);
} catch (MalformedURLException e) {
logger.info("MalformedURLException" + e);
} catch (SessionNotCreatedException e) {
logger.info("Session cannot be created" + e);
}
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
这个 class 是继承上面的 class
driver.findElementByXPath("//android.view.View[@text='研发中心']").click();
driver.findElementByXPath("//android.view.View[@text='Enterprise Demo']").click();
driver.findElementByXPath("//android.widget.TextView[@text='My Incidents']").click();
driver.context("WEBVIEW_com.tencent.mm:tools");//切换
driver.findElement(By.xpath("//*[@id=\"0\"]/div/div[2]")).click();//click 操作