appium-java,连接真机启动微信(适应于安卓6.0及以下,旧版appium)
1.启动appium
2.设置信息
3.设置IP和端口
4.appium连接手机,微信中打开debugx5.qq.com,信息-》TBS settings-》是否打开TBS内核Insperector调试功能
5.代码
选择安装包后可以获取
appPackage,
appActivity
方法
public DesiredCapabilities get_capabilities(int i){ //配置appuim信息 DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); //定义使用的浏览器Chrome,Safari switch (i) { case 1: capabilities.setCapability("platformName", "Android"); //手机操作系统 capabilities.setCapability("deviceName", "4d00be1d37cd4033"); //手机类型 capabilities.setCapability("udid", "4d00be1d37cd4033"); //连接手机的唯一标识 capabilities.setCapability("platformVersion", "5.0.1"); //操作系统版本 break; case 2: capabilities.setCapability("platformName", "Android"); capabilities.setCapability("deviceName","93ac5a2"); capabilities.setCapability("udid", "93ac5a2"); capabilities.setCapability("platformVersion", "5.1.1"); break; default: break; } capabilities.setCapability("appPackage", "com.tencent.mm"); //app包名 capabilities.setCapability("appActivity", ".ui.LauncherUI"); //要启动的Android Activity名 capabilities.setCapability("noReset", true); //不要在会话前重置应用状态 capabilities.setCapability("fullReset", false); //Android是否删除应用,IOS是否删除整个模拟器目录 capabilities.setCapability("sessionOverride", true); //输入配置 capabilities.setCapability("unicodeKeyboard", true); //是否启动Unicode输入法 capabilities.setCapability("resetKeyboard", false); //结束后是否切换回默认输入法 //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); return capabilities; }
使用例子
import io.appium.java_client.android.AndroidDriver;
private AndroidDriver AndroidDriver; @Before public void setUp() throws Exception { try { AndroidDriver = new AndroidDriver(new URL("http://127.0.0.1:4728/wd/hub"), Start_Driver.get_capabilities(1)); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
6.运行test