appium-java,连接真机启动微信(适应于安卓8.0及以上,新版appium)

1.同理设置appium配置,要启动多少台机器就启动多少个appium,注意端口号不能重复

 

 

 

 2.

    public DesiredCapabilities getCapabilities(int i,String appName){
        //配置appuim信息
        DesiredCapabilities capabilities = new DesiredCapabilities();  
        switch (i) {
        case 1:
            capabilities.setCapability("platformName", "Android");  //手机操作系统
            capabilities.setCapability("deviceName", "device"); //手机类型
            capabilities.setCapability("udid", "712CKCRXXXX");  //连接手机的唯一标识
            capabilities.setCapability("platformVersion", "7.0");  //操作系统版本
            //H5驱动关键,不配置webview会被识别成com.tencent.mm的webview,不是com.tencent.mm:tools的(旧版本需配置新版不需要)
//            ChromeOptions op= new ChromeOptions();
//            op.setExperimentalOption("androidProcess", "com.tencent.mm:tools");
//            capabilities.setCapability(ChromeOptions.CAPABILITY, op);
            break;
        case 2:
            capabilities.setCapability("platformName", "Android");  
            capabilities.setCapability("deviceName","device");
            capabilities.setCapability("udid", "HLRDU20309XXXX");
            capabilities.setCapability("platformVersion", "10");  
            break;
        default:
            break;
        }
        switch (appName) {
		case "微信":
			capabilities.setCapability("appPackage", "com.tencent.mm");  //app包名
	        capabilities.setCapability("appActivity", ".ui.LauncherUI"); //要启动的Android Activity名
			break;
		default:
			break;
		}
        capabilities.setCapability("skipServerInstallation", true);//是否跳过appiumServer安装
		capabilities.setCapability("skipDeviceInitialization", true);//是否跳过appiumDevice安装
        capabilities.setCapability("noReset", true); //不要在会话前重置应用状态
        capabilities.setCapability("fullReset", false); //Android是否删除应用,IOS是否删除整个模拟器目录
        capabilities.setCapability("unicodeKeyboard", true); //是否启动Unicode输入法
        capabilities.setCapability("resetKeyboard", true);  //结束后是否切换回默认输入法
        return capabilities;  
    }

  3.使用例子

    private AndroidDriver AndroidDriver;
    @Before
    public void setUp() throws Exception {
        
        try {
            AndroidDriver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), Start_Driver.get_capabilities(1));
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
    }

 

posted on 2020-06-16 17:35  研者  阅读(841)  评论(0编辑  收藏  举报