appium入门教程(intellij idea)
1.下载appium客户端
官网下载: http://appium.io/
网盘下载:http://yunpan.cn/cVBCxWz29kuhL 访问密码 fd70
2.新建java项目
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>groupId</groupId> <artifactId>appiumDemo</artifactId> <version>1.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>LATEST</version> </dependency> </dependencies> </project> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
import io.appium.java_client.AppiumDriver; import io.appium.java_client.android.AndroidDriver; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import java.util.List; /** * Created by pengwei08 on 2015/4/14. */ public class main { public static void main(String[] args) throws MalformedURLException { File app = new File("D:/java/AppiumDemo2/apps/ContactManager/ContactManager.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("deviceName","emulator-5554"); capabilities.setCapability("platformVersion", "4.4"); capabilities.setCapability("app", app.getAbsolutePath()); capabilities.setCapability("appPackage", "com.example.android.contactmanager"); capabilities.setCapability("appActivity", ".ContactManager"); AppiumDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities); System.out.print("app is start"); WebElement el = driver.findElement(By.name("Add Contact")); el.click(); List<WebElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText"); textFieldsList.get(0).sendKeys("Some Name"); textFieldsList.get(2).sendKeys("Some@example.com"); driver.swipe(100, 500, 100, 100, 2); driver.findElementByName("Save").click(); } } |
源码下载:http://7u2n7b.com1.z0.glb.clouddn.com/appiumDemo_201504140011.zip
3.打开虚拟机
4.点击运行
转载请注明:软件测试 » appium入门教程(intellij idea)