appium样例代码
com.appium.driver包下创建InitDriver.java类:
package com.appium.driver;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;
public class InitDriver {
public static AndroidDriver<AndroidElement> initDriverWebapp() throws MalformedURLException{
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "chinablue");
caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
caps.setCapability(MobileCapabilityType.UDID, "DU3ADH154V007404");
caps.setCapability(AndroidMobileCapabilityType.UNICODE_KEYBOARD, true);
caps.setCapability(AndroidMobileCapabilityType.RESET_KEYBOARD, true);
caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.2");
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(url,caps);
return driver;
}
public static AndroidDriver<AndroidElement> initDriver() throws MalformedURLException{
File apk_path = new File("apps/zhihu.apk");
DesiredCapabilities caps = new DesiredCapabilities();
// 与appium服务器相关的caps
caps.setCapability(MobileCapabilityType.DEVICE_NAME, "chinablue");
caps.setCapability(MobileCapabilityType.APP, apk_path.getAbsolutePath());
// 手机网页测试
// caps.setCapability(MobileCapabilityType.BROWSER_NAME, "chinablue");
// caps.setCapability(MobileCapabilityType.UDID, "127.0.0.1:62001");
// 服务端等待客户端发送脚本命令时间
caps.