基于APPIUM的移动自动化测试

发表于:2013-4-17 10:23

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:zzxxbb112 译    来源:51Testing软件测试网采编

  Appium一款开源自动化测试工具,可以非常快捷的为iOS和Android移动平台创建功能自动化测试用例。相比其他的移动自动化测试工具,Appium测试由于调用了Selenium的client库使其可以使用任意的语言,包括PythonRuby、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:TestApp
grunt buildApp:UICatalog

  一旦sample projects完成构建,即可通过以下命令启动Appium:

grunt appium

  变更工作目录到sample-code/examples/java/junit,运行测试

mvn test

  或运行单个测试:

mvn -Dtest=com.saucelabs.appium.SimpleTest test

  Java Appium测试与Selenium Test非常的相似,你可以创建一个RemoteWebDriver实例并指定DesiredCapabilities,脚本如下:

@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测试的方式完成测试脚本:

@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");
}

《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号