Today we learn how to use Appium Inspector to create test scripts.

Start the Appium service:

  1. Plug in the Android phone to the computer, and confirm that adb devices can be displayed correctly;
    image.png
  2. Open the Appium Server GUI, as shown below, keep Address and Port as default values;
    image.png
  3. If you do not want to use the JAVA_HOME and ANDROID_HOME configured in the previous article, you can click Edit Configuration modify;
  4. Click the Start Server button to start the service and enter the following interface;
    image.png
  5. Open Appium Inspector and enter the following main page. Appiumn also provides a web version of the Inspector, you can visit here with Chrome. ;
    image.png
  6. 127.0.0.1 , 4723 and /wd/hub in the Host, Port and Path text boxes as shown in the figure;
  7. In Desired Capabilities, add a line of platform as Android. If you need more ability conditions to filter mobile phones, you can refer to here enter more content;
  8. Click the Start Session button to successfully connect to the mobile phone with the specified capability controlled by the Server;
    image.png
  9. The top of the figure is the toolbar, and the main interface is divided into 3 columns, which are the descriptions of the phone screen, App source files, and selected controls.

Record test script:

  1. Download the test Android installation package from here to the local, and execute the following command to install;

    adb install eyes-android-hello-world.apk
  2. Start Recording button (eye-shaped icon) in the top toolbar to start recording the script;
  3. On the mobile desktop on the left side of Appium Inspector, select the App icon you just installed, and click the Tap button on the right;
    image.png
  4. Open the App window on your phone, enter the following interface, the upper right area shows the script automatically generated for the click operation;
    image.png
  5. In the figure above, select the row where the first check box is located, and click the Tap button on the right again;
  6. The first checkbox is selected, and a new line of script is added to the upper right;
    image.png
  7. In the picture above, select the CLICK ME! picture button, and click the Tap button on the right again;
  8. A picture is displayed on the page, and a new line of script is added to the upper right;
    image.png
  9. Pause button in the toolbar at the top to stop recording;
  10. Select Java-JUnit in the upper right drop-down menu, and then click the Copy code to clipboard button to copy the code;
    image.png
  11. Get the following Appium automated test script in Java form. Here we add comments to briefly explain the steps.

    // 使用XPath选择器,查找App桌面图标。
    MobileElement el1 = (MobileElement) driver.findElementByXPath("//android.widget.ImageView[@content-desc=\"ApplitoolsHelloWorld\"]");
    // 点击图标,启动App。
    el1.click();
    
    // 使用Id选择器,查找指定的控件。
    MobileElement el2 = (MobileElement) driver.findElementById("com.applitools.helloworld.android:id/random_number_check_box");
    // 点击控件
    el2.click();
    
    // 使用Id选择器,查找指定的控件。
    MobileElement el3 = (MobileElement) driver.findElementById("com.applitools.helloworld.android:id/click_me_btn");
    // 点击控件
    el3.click();

In the next article, we will learn how to package recorded scripts into Java test classes to achieve complete automated testing.

thematic directory


陈哥聊测试
158 声望3.3k 粉丝

资深敏捷测试顾问,国内知名项目管理软件禅道团队成员。