Appium Desktop 安装

Appium 生态工具

appium desktop 安装

Appium Desktop 工具使用

此时执行按键输入等操作,Appium 会自动录制并生成相应的脚本在 Recorder 面板显示件中运行

自动录制的脚本默认为 Java-Junit 文件,可以点击 “Java-Junit” 下拉列表,选择其他的语言。我们现在以 Java 为例,点击 “Show/Hide Boilerplate Code” 按钮生成一个完整的脚本文件,点击 “Copy code to clipboard” 按钮会将录制的脚本拷贝到剪贴板,把录制的脚本粘贴到 Java 文件

package com.demo;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.remote.DesiredCapabilities;

public class SampleTest {

  private AndroidDriver driver;

  @Before
  public void setUp() throws MalformedURLException {
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("platformName", "Android");
    desiredCapabilities.setCapability("deviceName", "192.168.9.101:5555");
    desiredCapabilities.setCapability("appPackage", "com.worktile");
    desiredCapabilities.setCapability("appActivity", ".ui.external.WelcomeActivity");
    desiredCapabilities.setCapability("noReset", "true");

    URL remoteUrl = new URL("http://localhost:4723/wd/hub");

    driver = new AndroidDriver(remoteUrl, desiredCapabilities);
    //设置超时时间
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
  }

  @Test
  public void sampleTest() {
    MobileElement el1 = (MobileElement) driver.findElementById("com.worktile:id/btn_login");
    el1.click();
    MobileElement el2 = (MobileElement) driver.findElementById("com.worktile:id/et_username");
    el2.sendKeys("yourname");
    MobileElement el3 = (MobileElement) driver.findElementById("com.worktile:id/et_password");
    el3.sendKeys("yourpasswd");
    MobileElement el4 = (MobileElement) driver.findElementById("com.worktile:id/btn_login");
    el4.click();
  }

  @After
  public void tearDown() {
    driver.quit();
  }
}


↙↙↙阅读原文可查看相关链接,并与作者交流