Appium测试环境搭建实践
一、环境准备
![](https://images2015.cnblogs.com/blog/950020/201605/950020-20160504215613904-1754939317.png)
a)下载Appium压缩包,并使用appium-installer.exe安装appium
b) 配置appium环境变量
b.1 配置Appium环境变量为 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 : http://pan.baidu.com/s/1dFDf27Z (selenium-java-2.53.0.zip)
java-client-2.2.0.jar : http://appium.io/downloads.html
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(); } }
9.开始运行
![](https://images2015.cnblogs.com/blog/950020/201605/950020-20160504220622951-141708384.png)
本文来自博客园,作者:月色深潭,交流群:733423266,转载请注明原文链接:https://www.cnblogs.com/moonpool/p/5460005.html