appium 多个设备同时执行

 

测试需要同时在多个android设备上运行,就需要启动多个appium

使用adb命令获取udid,命令:adb get-serialno

使用的是testng测试框架,代码使用java编写

第一台,运行真机,代码如下:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

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.BeforeClass;
import org.testng.annotations.Test;

import io.appium.java_client.android.AndroidDriver;

public class StartGoogle {
	
	public AndroidDriver driver;

	@BeforeClass
	public void startTest() throws MalformedURLException {
		
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("platformName","Android");
		capabilities.setCapability("deviceName","860BDMD2229B");
		capabilities.setCapability("udid", "860BDMD2229B");
		//capabilities.setCapability("deviceName","860BDMD2229B");
		capabilities.setCapability("platformVersion", "7.0.0");
		capabilities.setCapability("browserName", "Chrome");
		//capabilities.setCapability("browserName", "Browser");
		driver = new AndroidDriver(new URL("http://127.0.0.1:4725/wd/hub"), capabilities);
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@AfterClass
	public void afterClass() {
		
		driver.quit();
	}

	@Test
	public void addContact() throws InterruptedException {
		Thread.sleep(2000);
		//打开百度首页
		driver.get("https://www.baidu.com");
		//输入框元素
		WebElement inputBox = driver.findElement(By.id("index-kw"));
		//输入JAVA关键字
		inputBox.sendKeys("JAVA");
		Thread.sleep(2000);
		//百度一下按钮
		WebElement searchButton = driver.findElement(By.id("index-bn"));
		//点击百度一下按钮
		searchButton.click();
		
		Thread.sleep(5000);

	}
}

  

第二台运行在模拟器,代码如下:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

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

import io.appium.java_client.android.AndroidDriver;

public class Sammydress_login {
	
	public AndroidDriver driver;

	@BeforeClass
	public void startTest() throws MalformedURLException {
		
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability("platformName","Android");
		//capabilities.setCapability("deviceName","860BDMD2229B");
		capabilities.setCapability("deviceName","192.168.35.102:5555");
		capabilities.setCapability("udid", "192.168.35.102:5555");
		capabilities.setCapability("platformVersion", "7.0.0");
		//capabilities.setCapability("platformVersion", "5.1");
		//capabilities.setCapability("browserName", "Chrome");
		capabilities.setCapability("browserName", "Browser");
		driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
		driver.manage().timeouts().implicitlyWait(6, TimeUnit.SECONDS);
	}

	@AfterClass
	public void afterClass() {
		
		driver.quit();
	}
	
	/**
	 * 登录测试
	 * @throws InterruptedException 
	 */
	@Test
	public void SD_login() throws InterruptedException{
		
		driver.get("http://wap-sammydress.com.trunk.s1.egomsl.com/");
		driver.findElement(By.id("js_top_cate")).click();
		Thread.sleep(3000);
		driver.findElement(By.cssSelector("#nav > div > ul > li:nth-child(2) > p")).click();
		Thread.sleep(5000);
		driver.findElement(By.cssSelector("#header > div.top.on > a.icon_tag.top_user.isnoLogin")).click();
		Thread.sleep(2000);
		
		driver.findElement(By.id("email")).sendKeys("18666904557@163.com");
    	driver.findElement(By.id("passwordsign")).sendKeys("jiang861107");
    	driver.findElement(By.id("js_signInBtn")).click();
    	
    	Thread.sleep(2000);
	}

}

必须要加一条配置:capabilities.setCapability("udid", "xxxxx");

启动多个appium ,设置不同的端口号,同时运行这两个类,就可以同时测试两个实例了。。。。

 

posted @ 2016-10-27 15:53  星星故乡  阅读(3649)  评论(0编辑  收藏  举报