Appium筆記

21ca發表於2017-05-04
  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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章