ITPub博客

首页 > 应用开发 > IT综合 > Appium笔记

Appium笔记

原创 IT综合 作者:21ca 时间:2017-05-04 09:22:30 0 删除 编辑
  1. 安装Android SDK,AndroidSDK_installer_r24.4.1-windows.exe

  2. 用Admistrator运行"SDK Manager.exe",
    Tools 下选择SDK Tools, SDK Platform-tools, SDK Build-tools 安装
    Android 7.11 (API 25) 下选择 SDK Platform 安装
    Android 5.1.1 (API 22) 下选择 SDK Platform,ARM EABI v7a System Image和Intel x86 Atom System Image 安装
    这个可以自己选择安装。

  3. 用Administrator 运行"AVD Manager.exe"
    在Device Definitions 下选择 Nexus 4然后点Create Device,输入名字,屏幕大小,分辨率,内存大小。
    Device Definitions 下选择刚才新建的Device,然后点击Create AVD 创建虚拟设备, CPU/ABI 选择 ARM (armeabi-v7a), Skin 选 No Skin
    在Android Virtual Devices下 选择金健的虚拟设备,点Start, 启动设备

  4. 添加环境变量 ANDROID_HOME=C:\Program Files (x86)\Android\android-sdk

  5. 安装 nodejs

  6. nodejs 下安装 appium
    npm install -g appium
    npm install -g appium-doctor

  7. 运行 appium-doctor, 检查环境
    info AppiumDoctor Appium Doctor v.1.4.2
    info AppiumDoctor ### Diagnostic starting ###
    info AppiumDoctor  ? The Node.js binary was found at: C:\Program Files\nodejs\node.exe
    info AppiumDoctor  ? Node version is 6.10.2
    info AppiumDoctor  ? ANDROID_HOME is set to: C:\Program Files (x86)\Android\android-sdk
    info AppiumDoctor  ? JAVA_HOME is set to: C:\Program Files\Java\jdk1.8.0_51
    info AppiumDoctor  ? adb exists at: C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe
    info AppiumDoctor  ? android exists at: C:\Program Files (x86)\Android\android-sdk\tools\android.bat
    info AppiumDoctor  ? emulator exists at: C:\Program Files (x86)\Android\android-sdk\tools\emulator.exe
    info AppiumDoctor  ? Bin directory of %JAVA_HOME% is set
    info AppiumDoctor ### Diagnostic completed, no fix needed. ###
    info AppiumDoctor
    info AppiumDoctor Everything looks good, bye!
    info AppiumDoctor

  8. 运行appium, 启动appium hub server
    C:\Program Files\nodejs>appium
    [Appium] Welcome to Appium v1.6.4
    [Appium] Appium REST http interface listener started on 0.0.0.0:4723

  9. Maven dependency
    1. <dependency>
    2.     <groupId>io.appium</groupId>
    3.     <artifactId>java-client</artifactId>
    4.     <version>4.1.2</version>
    5. </dependency>
  10. Java
    1. import java.net.URL;

    2. import org.openqa.selenium.remote.CapabilityType;
    3. import org.openqa.selenium.remote.DesiredCapabilities;

    4. import io.appium.java_client.MobileElement;
    5. import io.appium.java_client.android.AndroidDriver;

    6. public class AndroidDriverTest {
    7.     public static void main(String[] args) throws Exception {
    8.         DesiredCapabilities capabilities = new DesiredCapabilities();
    9.         capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    10.         capabilities.setCapability("platformName", "Android");
    11.         capabilities.setCapability("deviceName", "Android Emulator");
    12.         capabilities.setCapability("platformVersion", "5.1.1");
    13.         capabilities.setCapability("appPackage", "com.android.calculator2");
    14.         capabilities.setCapability("appActivity", ".Calculator");
    15.         
    16.         AndroidDriver<MobileElement> driver =
    17.                 new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    18.         
    19.         driver.findElementByAndroidUIAutomator("text(\"1\")").click();
    20.         driver.findElementByAndroidUIAutomator("text(\"+\")").click();
    21.         driver.findElementByAndroidUIAutomator("text(\"2\")").click();
    22.         driver.findElementByAndroidUIAutomator("text(\"=\")").click();

    23.         System.out.println(driver.currentActivity());
    24.         driver.quit();
    25.     }
    26.     
    27.     
    28. }


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

请登录后发表评论 登录
全部评论

注册时间:2009-03-24

  • 博文量
    58
  • 访问量
    83483