查看设备:adb services
获取 APP 的基本信息
adb logcat | grep -i ActivityManage*Displayed
aapt dump badging apkname | grep launchable-activity
启动 Appium Desktop
双击桌面 Appium 图标,点击 “Start Server v1.7.2” 启动 appium server
查看页面属性
点击 “Select Elements” 按钮,点击任何一个元素,在右侧的 Selected Element 栏能够显示选中的元素的 id、xpath 和属性信息。
发送 Tap、Send keys,clear 事件
自动录制脚本
点击 “Start Recording” 按钮,会打开 Recorder 面板
此时执行按键输入等操作,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();
}
}