周末在家无聊研究了一个关于Appium 远程控制从机执行的方法,分享给大家
分享的主题:说白了就是你的机器的case交给别的机器帮你执行!
1,首先大家先看下面这段,大家应该都知道要能使Appium运行起来必须先配置好相关的参数;
这是我个人的代码,有点丑勿见怪
publicvoidsetUp()throwsException{//启动// set up appium// File classpathRoot = new File(System.getProperty("user.dir"));// File appDir = new File(classpathRoot, "apps");// File app = new File(appDir, "ContactManager.apk");DesiredCapabilitiescapabilities=newDesiredCapabilities();capabilities.setCapability("device","Android");// capabilities.setCapability(CapabilityType.BROWSER_NAME, "");capabilities.setCapability("deviceName","xiaomi-mi_3-02214788");//小米// capabilities.setCapability("deviceName", "52c7c049");//三星// capabilities.setCapability("deviceName", "614ad249");//红米capabilities.setCapability("platformVersion","4.4.4");capabilities.setCapability("platformName","Android");// capabilities.setCapability("app", app.getAbsolutePath());capabilities.setCapability("appPackage","com.tencent.mm");capabilities.setCapability("appActivity","com.tencent.mm.ui.LauncherUI");/* capabilities.setCapability("unicodeKeyboard", "True"); capabilities.setCapability("resetKeyboard", "True"); */driver=newAndroidDriver(newURL("http://127.0.0.1:4723/wd/hub"),capabilities);//进入发现页面
2,大家看完之后留意下这个地方:
driver=newAndroidDriver(newURL("http://127.0.0.1:4723/wd/hub"),capabilities);
这个里面这个url:http://127.0.0.1:4723/wd/hub 就是本机开辟的一个4723的端口去与Appium交互的,知道这个很重要,因为我们这次就会用到它
拿到这段url后我们去用浏览器打开看一下这个:
如果出现这个的话证明4723端口开辟成功是成功的,当然你的Appium server 肯定先开着
3,用另外一台机器改一下他的appium server Address :
改完运行:
运行成功后回到原来的主机 打开浏览器输入:之前设置的appium server Address,出现下面的
如果是这样的话,那证明你配置成功咯!!
4,接下来就是运行Case啦,到主机上面随便找一个脚本只需要更改一个地方
publicvoidsetUp()throwsException{//启动// set up appium// File classpathRoot = new File(System.getProperty("user.dir"));// File appDir = new File(classpathRoot, "apps");// File app = new File(appDir, "ContactManager.apk");DesiredCapabilitiescapabilities=newDesiredCapabilities();capabilities.setCapability("device","Android");// capabilities.setCapability(CapabilityType.BROWSER_NAME, "");capabilities.setCapability("deviceName","xiaomi-mi_3-02214788");//小米// capabilities.setCapability("deviceName", "52c7c049");//三星// capabilities.setCapability("deviceName", "614ad249");//红米capabilities.setCapability("platformVersion","4.4.4");capabilities.setCapability("platformName","Android");// capabilities.setCapability("app", app.getAbsolutePath());capabilities.setCapability("appPackage","com.tencent.mm");capabilities.setCapability("appActivity","com.tencent.mm.ui.LauncherUI");/* capabilities.setCapability("unicodeKeyboard", "True"); capabilities.setCapability("resetKeyboard", "True"); *///改这里driver=newAndroidDriver(newURL("http://172.17.6.173:4723/wd/hub"),capabilities);//进入发现页面
改好后driverName 对应,参数都对应起来 点击运行,你会发现你的另外一台机器上的设备自动运行起来了!!!!
你可以把这个url 封装起来然后开多个虚拟机和多版本的模拟器进行并发分布式测试!具体方法以后分享
祝大家成功!
有什么问题随便时找我!