1、安装 nodejs 测试安装是否成功:运行cmd,输入命令node -v
2、安装 android 的 sdk 包,由于本人的用的是普通eclipse 只要eclipse 上安装ADT 插件,且并确保你安装了Level17或以上的版本 api。设置ANDROID_HOME 系统变量为你的 Android SDK 路径,并把tools和platform-tools两个目录加入到系统的 Path路径里。
3、安装 maven 插件
4、安装appium:在cmd使用命令 npm install –g appium
5、在cmd启动appium
6、运行实例代码
package com.saucelabs.appium; import java.io.File; import java.net.URL; import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.Capabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.HasTouchScreen; import org.openqa.selenium.interactions.TouchScreen; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteTouchScreen; import org.openqa.selenium.remote.RemoteWebDriver; public class AndroidContactsTest { public class SwipeableWebDriver extends RemoteWebDriver implements HasTouchScreen { private final RemoteTouchScreen touch; public SwipeableWebDriver(final URL remoteAddress, final Capabilities desiredCapabilities) { super(remoteAddress, desiredCapabilities); touch = new RemoteTouchScreen(getExecuteMethod()); } public TouchScreen getTouch() { return touch; } } private WebDriver driver; @Test public void addContact() { final WebElement el = driver.findElement(By.name("Add Contact")); el.click(); final List<WebElement> textFieldsList = driver.findElements(By .tagName("textfield")); textFieldsList.get(0).sendKeys("Some Name"); textFieldsList.get(2).sendKeys("[email protected]"); driver.findElement(By.name("Save")).click(); } @Before public void setUp() throws Exception { final File app = new File( "C:/Users/Administrator/Desktop/appium/appium-master/sample-code/apps/ContactManager/ContactManager.apk"); final DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("device", "Android"); capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); capabilities.setCapability(CapabilityType.VERSION, "4.2"); capabilities.setCapability(CapabilityType.PLATFORM, "MAC"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("app-package", "com.example.android.contactmanager"); capabilities.setCapability("app-activity", ".ContactManager"); driver = new SwipeableWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); } @After public void tearDown() throws Exception { driver.quit(); } }
代码从放的地址
时间: 2024-10-26 07:07:34