1. 获取driver
appium通过生成driver来识别和操作app的UI元素。生成driver时,需要给出被测设备的相关信息。appium官方上的例子如下:
public static AndroidDriver> mobiledriver;
@BeforeTest
public void beforeTest( ) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.7.2");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME,"Appium");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Browser");
capabilities.setCapability("newCommandTimeout", 2000);
mobiledriver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
Android 第三方被测app举例:
public static AndroidDriver<?> driver1;
public static void main(String\[\] args) {
//set up Appium
DesiredCapabilities capabilities1 = new DesiredCapabilities();
capabilities1.setCapability(MobileCapabilityType.AUTOMATION\_NAME, "uiautomator2");
capabilities1.setCapability(MobileCapabilityType.PLATFORM\_NAME, "Android");
capabilities1.setCapability(MobileCapabilityType.PLATFORM\_VERSION, "9.0.0");
capabilities1.setCapability(MobileCapabilityType.DEVICE\_NAME, "PCT-AL10");
capabilities1.setCapability(MobileCapabilityType.UDID, "xxxx");
capabilities1.setCapability("appPackage", "com.xxxx.xxx.demo");
capabilities1.setCapability("appActivity", ".MainActivity");
//for input Chinese
capabilities1.setCapability("unicodeKeyboard", true);
capabilities1.setCapability("resetKeyboard", true);
try {
driver1 = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities1);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
如何获取以上信息呢?
手机扫一扫
移动阅读更方便
你可能感兴趣的文章