AWS Device Farm 是亚马逊提供的移动app云测平台,对于Android和iOS支持多种自动化测试框架,比如appium+testng、appium+junit、appium+python等,也支持网络、语言、地址、appium版本的选择。
本地编写脚本
参考官方文档说明 :https://docs.aws.amazon.com/zh_cn/devicefarm/latest/developerguide/test-types-ios-appium-java-testng.html
1、我本地使用appium+testng开发iOS的脚本,下面是一个本地的启动登录app的脚本
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.touch.offset.PointOption;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class iOSUITest {
public IOSDriver driver;
@Test
public void login() throws InterruptedException, MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "11.4.1");
capabilities.setCapability("deviceName", "iPhone 6s plus");
capabilities.setCapability("udid", "your device udid");
capabilities.setCapability("bundleId", "your.package.name");
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(5000);
TouchAction action = new TouchAction(driver);
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
double x1 = 300.0 / 414.0;
double y1 = 430.0 / 736.0;
int X1 = (int) (x1 * width);
int Y1 = (int) (y1 * height);
action.press(PointOption.point(X1, Y1)).release().perform();
Thread.sleep(5000);
action.press(PointOption.point(X1, Y1)).release().perform();
Thread.sleep(5000);
WebElement serverip=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]");
serverip.clear();
serverip.sendKeys("your serverip");
driver.findElementByName("确定").click();
Thread.sleep(2000);
WebElement account=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]");
account.clear();
account.sendKeys("your account");
WebElement password=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField[1]");
password.clear();
password.sendKeys("your password");
driver.findElementByName("登录").click();
Thread.sleep(5000);
}
}
2、本地执行通过后,注释掉设备信息,修改后的代码如下所示:
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.touch.offset.PointOption;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.net.URL;
public class iOSUITest {
public IOSDriver driver;
@Test
public void login() throws InterruptedException, MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(5000);
TouchAction action = new TouchAction(driver);
int width = driver.manage().window().getSize().width;
int height = driver.manage().window().getSize().height;
double x1 = 300.0 / 414.0;
double y1 = 430.0 / 736.0;
int X1 = (int) (x1 * width);
int Y1 = (int) (y1 * height);
action.press(PointOption.point(X1, Y1)).release().perform();
Thread.sleep(5000);
action.press(PointOption.point(X1, Y1)).release().perform();
Thread.sleep(5000);
WebElement serverip=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]");
serverip.clear();
serverip.sendKeys("your serverip");
driver.findElementByName("确定").click();
Thread.sleep(2000);
WebElement account=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeTextField[1]");
account.clear();
account.sendKeys("your account");
WebElement password=driver.findElementByXPath("//XCUIElementTypeOther[1]/XCUIElementTypeSecureTextField[1]");
password.clear();
password.sendKeys("your password");
driver.findElementByName("登录").click();
Thread.sleep(5000);
}
}
3、按照官方文档在maven添加依赖打包,进入到项目中所在目录,执行指令
mvn clean package -DskipTests=true
出现BUILD SUCCESS说明打包成功,可以上到平台云测了
AWS Device Farm操作
1、上传被测试的ipa安装包
2、上传打包的脚本,可以选择appium的版本
3、选择测试的应用,可以直接选择标准的,也可以自己选择需要的设备
4、选择设备配置,网络场景、经纬度、语言
5、提交
6、查看测试报告
遇到的问题
1、执行失败,如下图报错
(1)脚本包含case太多执行不起来
(2)同样的脚本测试Android
(3)脚本没问题,只能是安装包的问题,可能是证书的问题,也可能是第三方库不支持