1,首先大家先看下面这段,大家应该都知道要能使 Appium 运行起来必须先配置好相关的参数;
这是我个人的代码,有点丑勿见怪
public void setUp() throws Exception{
//启动
// set up appium
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "apps");
// File app = new File(appDir, "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
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 = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
//进入发现页面
2,大家看完之后留意下这个地方:
driver = new AndroidDriver(new URL("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 啦,到主机上面随便找一个脚本只需要更改一个地方
public void setUp() throws Exception{
//启动
// set up appium
// File classpathRoot = new File(System.getProperty("user.dir"));
// File appDir = new File(classpathRoot, "apps");
// File app = new File(appDir, "ContactManager.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
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 = new AndroidDriver(new URL("http://172.17.6.173:4723/wd/hub"), capabilities);
//进入发现页面
改好后各项参数都对应起来点击运行一个普通的 case,你会发现你的另外一台机器上的设备自动运行起来了!!!!
你可以把这个 url 封装起来然后开多个虚拟机和多版本的模拟器进行并发分布式测试!具体方法以后分享
祝大家成功!
有什么问题随便时找我!
欢迎一起交流,一起进步 可以关注我的微信公众号: