Appium移动端UI自动化中,如果需要两个APP交互操作的实践经验

前段时间在用Appium做UI自动化,碰到一个原来没有碰到的问题,原来做的项目都是单独的APP操作。

在目前的项目中,有两个APP,两个APP需要交互操作,一个发单,一个接单,这边发单以后,另外个APP需要接单。

想了两种方法:

一、Two App in one device 两个app在同一个设备上运行

  1.启动device,安装一个app

@BeforeTest
  public void beforeTest() throws Exception{
	  logger.info("***********************************************************************");
	  logger.info("Test begin:");
	  logger.info("发单接单,整车,测试");
	  
	  //获取app路径 
	  File classpathRoot = new File(System.getProperty("user.dir"));
	  File appDir = new File(classpathRoot, "apps");
	  File app_carrier = new File(appDir, "carrier.apk");
	  File app_shipper = new File(appDir, "shipper.apk");
	  logger.info("获取app path:"+app_carrier.getAbsolutePath());
	  //set up Appium
	  DesiredCapabilities capabilities1 = new DesiredCapabilities();
	  capabilities1.setCapability("device","Android");
	  capabilities1.setCapability(MobileCapabilityType.DEVICE_NAME, "HC35NW906179");
	  capabilities1.setCapability(MobileCapabilityType.UDID, "HC35NW906179");
	  capabilities1.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.4");
	  capabilities1.setCapability(MobileCapabilityType.APP, app_carrier.getAbsolutePath());
	  capabilities1.setCapability(MobileCapabilityType.APP_PACKAGE, "com.kuaihuoyun.driver");
	  capabilities1.setCapability(MobileCapabilityType.APP_ACTIVITY, ".KDLaunch");
	  //for input Chinese
	  capabilities1.setCapability("unicodeKeyboard", "True");  
	  capabilities1.setCapability("resetKeyboard", "True");
	  try {
		  driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities1);
		logger.info("carrier app启动成功");
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

  2.安装另外一个app

	  //安装货主端
	  driver.installApp(app_shipper.getAbsolutePath());
	  logger.info(app_shipper.getAbsolutePath());
	  if(driver.isAppInstalled("com.kuaihuoyun.freight")==true){
		  logger.info("货主端安装成功");
	  }
	  else{
		  logger.info("货主端安装失败");		  
	  }

  3.操作时通过startActivity切换不同app

	  //切换到货主端
	  driver.startActivity("com.kuaihuoyun.freight", ".KDLaunch");

二、two devices two apps 两个设备,每个设备单独一个app

 

	  //set up Appium
	  	//司机端
	  DesiredCapabilities capabilities1 = new DesiredCapabilities();
	  capabilities1.setCapability("device","Android");
	  capabilities1.setCapability(MobileCapabilityType.DEVICE_NAME, "7N2MYN14BK036952");
	  capabilities1.setCapability(MobileCapabilityType.UDID, "7N2MYN14BK036952");
	  capabilities1.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.3");
	  capabilities1.setCapability(MobileCapabilityType.APP, app_carrier.getAbsolutePath());
	  capabilities1.setCapability(MobileCapabilityType.APP_PACKAGE, "com.kuaihuoyun.driver");
	  capabilities1.setCapability(MobileCapabilityType.APP_ACTIVITY, ".KDLaunch");
	  //for input Chinese
	  capabilities1.setCapability("unicodeKeyboard", "True");  
	  capabilities1.setCapability("resetKeyboard", "True");
	  
	  try {
		  driver__carrier = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities1);
		logger.info("carrier app启动成功");
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	  
	  	//货主端
	  DesiredCapabilities capabilities2 = new DesiredCapabilities();
	  capabilities2.setCapability("device","Android");
	  capabilities2.setCapability(MobileCapabilityType.DEVICE_NAME, "HC35NW906179");
	  capabilities2.setCapability(MobileCapabilityType.UDID, "HC35NW906179");
	  capabilities2.setCapability(MobileCapabilityType.PLATFORM_VERSION, "4.4.4");
	  capabilities2.setCapability(MobileCapabilityType.APP, app_shipper.getAbsolutePath());
	  capabilities2.setCapability(MobileCapabilityType.APP_PACKAGE, "com.kuaihuoyun.freight");
	  capabilities2.setCapability(MobileCapabilityType.APP_ACTIVITY, ".KDLaunch");
	  //for input Chinese
	  capabilities2.setCapability("unicodeKeyboard", "True");  
	  capabilities2.setCapability("resetKeyboard", "True");

	  try {
		  driver__shipper = new AndroidDriver<>(new URL("http://127.0.0.1:4725/wd/hub"), capabilities2);
		logger.info("shipper app启动成功");
	} catch (MalformedURLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

  启动两个appium代理,设置不同port,在不同设备中安装不同app

 

总结:Two App in one device的方式运行起来不是很稳定,目前采用two devices two apps的方式

转载于:https://www.cnblogs.com/appstest/p/5088877.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值