老宋的地盘

 找回密码
 我要加入
搜索
查看: 3326|回复: 3

基于Appium的移动自动化测试

[复制链接]
发表于 2014-4-14 17:42:15 | 显示全部楼层 |阅读模式
Appium一款开源自动化测试工具,可以非常快捷的为iOS和Android移动平台创建功能自动化测试用例。相比其他的移动自动化测试工具,Appium测试由于调用了Selenium的client库使其可以使用任意的语言,包括Python、Ruby、Node.js,Objective,java等。
Appium-ios.png
本文我们主要讨论如何通过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");
}




您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

歌名 - 歌手
0:00

    QQ|手机版|小黑屋|老宋 ( 备案中... )

    GMT+8, 2024-4-18 11:05 , Processed in 0.071295 second(s), 25 queries , Gzip On.

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表