appium android——利用testng和maven并行执行用例

一、测试类

package com.wiley.appiumConcurrent;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

public class Demo {
	private AndroidDriver driver;

	@Test
	@Parameters({ "port", "udid" })
	public void login(String port,String udid) throws MalformedURLException, InterruptedException {
		System.out.println("port is: " + port + ", udid is: " + udid);
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("deviceName", "android emulator");
		capabilities.setCapability("udid", udid);
		capabilities.setCapability("appPackage", "com.haodou.recipe");
		capabilities.setCapability("appActivity", "com.haodou.recipe.Main");
		driver = new AndroidDriver(new URL("http://127.0.0.1:" + port + "/wd/hub"), capabilities);
		Thread.sleep(3000);
		driver.findElement(By.id("com.haodou.recipe:id/mine_item")).click();
	}

	@AfterClass
	public void teardown(){
		driver.quit();
	}
}
pom.xml部分代码:


		complie
		
			
				maven-surefire-plugin
				2.18.1
				
					 
						testng1.xml 
						testng2.xml 
					
				
			
			
				maven-compiler-plugin
				3.3
				
					1.7
					1.7
				
			
		
	


二、连接两个android设备或者启动两个虚拟机(我用的是一真机、一虚拟机)

命令行使用:adb devices获取udid

三、项目路径下新建两个testng.xml

testng1.xml




	
	    
		
		
			
		
		

testng2.xml



	
	
	    
		
		
			
		
		

四、开启两个appium server(命令行启动)

appium -p 4723 -bp 4724 -U 7C5901B01446
appium -p 4725 -bp 4726 -U 192.168.56.101:5555

五、导出依赖(命令行切换到工程所在目录)
因为是用 maven 工程创建的,所以先导出依赖到项目路径下的lib文件夹
mvn dependency:copy-dependencies -DoutputDirectory=lib

六、执行测试
先用 Maven 串行执行一次以编译出Class文件
mvn clean test
然后(已配置testng环境变量)
java -classpath ".\target\classes" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml,这样就可以并行执行测试用例了

七、查看报告
默认在项目路径下的 test-output 文件夹


注:引用:https://testerhome.com/topics/1639


你可能感兴趣的:(appium,appium,android,并行)