|
Appium一款开源自动化测试工具,可以非常快捷的为iOS和Android移动平台创建功能自动化测试用例。相比其他的移动自动化测试工具,Appium测试由于调用了Selenium的client库使其可以使用任意的语言,包括Python、Ruby、Node.js,Objective,java等。
本文我们主要讨论如何通过junit java example tests测试完成iOS sample apps的测试(此处我们还会创建TestNG example Tests)
当然在开始之前,我们首先需要下载Appium,下载地址为https://github.com/appium/appium,根据安装说明我们可以完成Appium的安装。
运行以下命令行构建sample projects:
grunt buildApp:TestAppgrunt buildApp:UICatalog一旦sample projects完成构建,即可通过以下命令启动Appium:
grunt appium变更工作目录到sample-code/examples/java/junit,运行测试
mvn test或运行单个测试:
mvn -Dtest=com.saucelabs.appium.SimpleTest testJava Appium测试与Selenium Test非常的相似,你可以创建一个RemoteWebDriver实例并指定DesiredCapabilities,脚本如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| @Before
public void setUp() throws Exception {
// set up appium against a local application
File appDir = new File(System.getProperty("user.dir"), "../../../apps/TestApp/build/Release-iphonesimulator");
File app = new File(appDir, "TestApp.app");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "iOS");
capabilities.setCapability(CapabilityType.VERSION, "6.0");
capabilities.setCapability(CapabilityType.PLATFORM, "Mac");
//tell Appium where the location of the app is
capabilities.setCapability("app", app.getAbsolutePath());
//create a RemoteWebDriver, the default port for Appium is 4723
driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
|
完成以上脚本后即可直接通过类似selenium测试的方式完成测试脚本:
1
2
3
4
5
6
7
8
9
10
11
| @Test
public void example() throws Exception {
// find an element by tag name
WebElement button = driver.findElement(By.tagName("button"));
button.click();
// get the value of the element
WebElement texts = driver.findElement(By.tagName("staticText"));
assertEquals(texts.getText(), "some expected value");
}
|
|
|