多测师是一家拥有先进的教学理念,强大的师资团队,业内好评甚多的接口自动化测试培训机构!

17727591462

联系电话

您现在所在位置:接口自动化测试培训 > 新闻资讯

基于APPIUM的移动自动化测试

更新时间:2022-05-18 09:03:21 作者:多测师 浏览:227

  Appium一款开源自动化测试工具,可以非常快捷的为iOS和Android移动平台创建功能自动化测试用例。相比其他的移动自动化测试工具,Appium测试由于调用了Selenium的client库使其可以使用任意的语言,包括Python、Ruby、Node.js,Objective,java等。

基于APPIUM的移动自动化测试

  本文我们主要讨论如何通过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");

  }

  以上内容为大家介绍了基于APPIUM的移动自动化测试,本文由多测师亲自撰写,希望对大家有所帮助。了解更多自动化测试相关知识:https://www.aichudan.com/xwzx/

联系电话

17727591462

返回顶部