码迷,mamicode.com
首页 > 移动开发 > 详细

Appium——主从控制执行

时间:2016-08-16 17:31:52      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

1.客户端(Eclipse)机器A, 服务端(appium、Genymotion)机器B

2.设置Appium,Server Address为192.168.17.123,重新启动Appium

 技术分享

技术分享

3.在客户端机器A浏览器中输入:http://192.168.17.123:4723/wd/hub,

技术分享

说明配置成功。

JAVA代码:

其中driver= new AndroidDriver<WebElement>(new URL("http://192.168.17.123:4723/wd/hub"), capabilities);

capabilities.setCapability("app", "F:\\ContactManager.apk");F:\\ContactManager.apk为服务端APK的路径

public class AppiumTest {
    
    public AndroidDriver<WebElement> driver;
    
      @BeforeClass
      public void startTest() throws MalformedURLException{
          
         // File classpathRoot= new File(System.getProperty("user.dir"));
         // File appDir= new File(classpathRoot, "res/app");
        //  File app= new File(appDir, "ContactManager.apk");
          DesiredCapabilities capabilities= new DesiredCapabilities();
          capabilities.setCapability("automationName", "Appium");
          capabilities.setCapability("platformName","Android");
          capabilities.setCapability("deviceName","Android Emulator");
          capabilities.setCapability("platformVersion", "4.4.2");
          // 根据这个app capabilities,Appium会在启动测试之前安装好app到设备 
          capabilities.setCapability("app", "F:\\ContactManager.apk");
          //设置安卓app的包名的capability,告诉appium你要运行哪个app。
          capabilities.setCapability("appPackage", "com.example.android.contactmanager");
          capabilities.setCapability("appActivity", ".ContactManager");
          driver= new AndroidDriver<WebElement>(new URL("http://192.168.17.123:4723/wd/hub"), capabilities);
      }
    
  @Test
  public void addContact() {
     // WebElement el= driver.findElement(By.xpath(".//*[@text=‘Add Contact‘]"));
      WebElement el = driver.findElementByAndroidUIAutomator("new UiSelector().text(\"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.findElementByXPath(".//*[@text=‘Save‘]").click();
 
  }
  

  @AfterClass
  public void afterClass() {
      driver.quit();
  }
   
}

 

Appium——主从控制执行

标签:

原文地址:http://www.cnblogs.com/hjhsysu/p/5777095.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!