标签:
一、环境准备
a)下载Appium压缩包,并使用appium-installer.exe安装appium
b) 配置appium环境变量
b.1 配置Appium环境变量为C:\Program Files (x86)\Appium\node_modules\.bin
b.2 在Path环境变量中加入 %Appium%;
b.3 测试:CMD中输入appium-doctor,能看到All Checks were successful
二、编写脚本
1. 下载Selenium依赖包
selenium-java-2.45.0.zip
java-client-2.2.0.jar
2. 在eclipse中创建JAVA工程并导入相应的jar包
导入java-client-2.2.0.jar和selenium-java-2.45.0.jar
导入selenium-java-2.45.0.zip的libs目录下所有jar包
3. 创建测试类:OneTest.java
4. 获取deviceName
5. 获取platformVersion
在手机系统信息中获取Android版本,这里是6.0.1
6. 明确appPackage和appActivity,这里使用的是手机自带的计算器app。Android的版本不一样,其中appPackage和appActivity也有区别。
7. 获取URL
8. 编写测试代码:
import java.net.URL; import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.By; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; public class OneTest { public static void main(String[] args) throws Exception{ DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability("platforName", "Android"); capabilities.setCapability("deviceName", "05157df53de0042b"); capabilities.setCapability("platformVersion", "6.0.1"); capabilities.setCapability("appPackage", "com.sec.android.app.popupcalculator"); capabilities.setCapability("appActivity", ".Calculator"); AppiumDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); driver.findElement(By.name("9")).click(); driver.findElement(By.name("5")).click(); driver.findElement(By.name("+")).click(); driver.findElement(By.name("6")).click(); driver.findElement(By.name("=")).click(); driver.quit(); } }
标签:
原文地址:http://www.cnblogs.com/moonpool/p/5460005.html