|
2#
楼主 |
发表于 2017-7-12 10:36:40
|
只看该作者
本帖最后由 悠悠小仙仙 于 2017-7-12 11:40 编辑
三、下载测试APK
1、下载测试的文件ContactManager.apk:https://github.com/appium/sample ... apps/ContactManager
2、将下载的apk放到项目的apps目录下
四、建立package包和案例文件
1、在src文件夹上右键单击,【New】-->【package】,输入包名:com.dan.demo,点击【Finish】
2、在package下新建类:ContactsTest.java,如下:
下载地址:https://github.com/appium/sample ... om/saucelabs/appium
- package com.dan.demo;
- import io.appium.java_client.AppiumDriver;
- import io.appium.java_client.android.AndroidDriver;
- import io.appium.java_client.android.AndroidElement;
- 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.WebElement;
- import org.openqa.selenium.remote.DesiredCapabilities;
- public class ContactsTest {
- private AppiumDriver driver;
- @Before
- public void setUp() throws Exception {
- // set up appium
- File classpathRoot = new File(System.getProperty("user.dir"));
- File appDir = new File(classpathRoot, "/apps");
- File app = new File(appDir, "ContactManager.apk");
- DesiredCapabilities capabilities = new DesiredCapabilities();
- capabilities.setCapability("deviceName","4d1219502472216f");
- capabilities.setCapability("platformVersion", "4.4");
- capabilities.setCapability("app", app.getAbsolutePath());
- capabilities.setCapability("appPackage", "com.example.android.contactmanager");
- capabilities.setCapability("appActivity", ".ContactManager");
- driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
- System.out.println("App is launched!");
- }
- @Test
- public void addContact(){
- WebElement el = driver.findElement(By.name("Add Contact"));
- el.click();
- List<AndroidElement> 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();
- System.out.println("App is done!");
- }
- @After
- public void tearDown() throws Exception {
- driver.quit();
- }
- }
复制代码
五、 启动Android模拟器(也可以连接真机)
1、cmd输入:android avd,选择模拟器,点击【Start】即可。
2、启动好后,cmd输入:adb devices,确定设备是否连接上,如下图连接成功:
六、 启动Appium
方法一:cmd输入:appium
方法二:
1、直接双击appium gui图标(如下图):
2、点击右上角的启动按钮,启动日志如下:
七、 运行测试案例:
1、在eclipse中,项目右键>【Run As】>【JUnit Test】,运行过程截图如下:
八、eclipse运行结果:
九、Appium运行结果:
|
|