ITPub博客

首页 > 应用开发 > IT综合 > Appium测试ContactManager.apk

Appium测试ContactManager.apk

原创 IT综合 作者:21ca 时间:2017-05-04 09:50:26 0 删除 编辑

启动 虚拟设备参考:Appium笔记


下载 ContactManager.apk

https://raw.githubusercontent.com/appium/sample-code/master/sample-code/apps/ContactManager/ContactManager.apk

安装ContactManager.apk
C:\Program Files (x86)\Android\android-sdk\platform-tools>adb install D:\xxx\ContactManager.apk

Java代码:
  1. import java.net.MalformedURLException;
  2. import java.net.URL;
  3. import java.util.List;

  4. import org.openqa.selenium.WebElement;
  5. import org.openqa.selenium.remote.CapabilityType;
  6. import org.openqa.selenium.remote.DesiredCapabilities;

  7. import io.appium.java_client.MobileElement;
  8. import io.appium.java_client.android.AndroidDriver;

  9. public class ContactManagerAppTest {

  10.     public static void main(String[] args) throws MalformedURLException {
  11.         DesiredCapabilities capabilities = new DesiredCapabilities();
  12.         capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
  13.         capabilities.setCapability("platformName", "Android");
  14.         capabilities.setCapability("deviceName", "Android Emulator");
  15.         capabilities.setCapability("platformVersion", "5.1.1");
  16.         capabilities.setCapability("appPackage", "com.example.android.contactmanager");
  17.         capabilities.setCapability("appActivity", ".ContactManager");

  18.         AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);


  19.         WebElement el = driver.findElementByAndroidUIAutomator("text(\"Add Contact\")");
  20.         el.click();
  21.         List<MobileElement> textFieldsList = driver.findElementsByClassName("android.widget.EditText");
  22.         textFieldsList.get(0).sendKeys("Some Name");
  23.         textFieldsList.get(2).sendKeys("Some@example.com");
  24.         driver.swipe(100, 500, 100, 100, 2);
  25.         driver.findElementByAndroidUIAutomator("text(\"Save\")").click();
  26.     
  27.         driver.quit();

  28.     }

  29. }

一些adb命令
传文件到设备:adb push D:\xxx\ContactManager.apk /data
启动shell: adb shell
adb remount

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10742815/viewspace-2138392/,如需转载,请注明出处,否则将追究法律责任。

上一篇: Appium笔记
下一篇: 可扩展性笔记一
请登录后发表评论 登录
全部评论

注册时间:2009-03-24

  • 博文量
    58
  • 访问量
    83463