Today we learn how to use Appium Inspector to create test scripts.
Start the Appium service:
- Plug in the Android phone to the computer, and confirm that adb devices can be displayed correctly;
- Open the Appium Server GUI, as shown below, keep Address and Port as default values;
- If you do not want to use the JAVA_HOME and ANDROID_HOME configured in the previous article, you can click Edit Configuration modify;
- Click the Start Server button to start the service and enter the following interface;
- Open Appium Inspector and enter the following main page. Appiumn also provides a web version of the Inspector, you can visit here with Chrome. ;
- 127.0.0.1 , 4723 and /wd/hub in the Host, Port and Path text boxes as shown in the figure;
- 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;
- Click the Start Session button to successfully connect to the mobile phone with the specified capability controlled by the Server;
- 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:
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
- Start Recording button (eye-shaped icon) in the top toolbar to start recording the script;
- 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;
- Open the App window on your phone, enter the following interface, the upper right area shows the script automatically generated for the click operation;
- In the figure above, select the row where the first check box is located, and click the Tap button on the right again;
- The first checkbox is selected, and a new line of script is added to the upper right;
- In the picture above, select the CLICK ME! picture button, and click the Tap button on the right again;
- A picture is displayed on the page, and a new line of script is added to the upper right;
- Pause button in the toolbar at the top to stop recording;
- Select Java-JUnit in the upper right drop-down menu, and then click the Copy code to clipboard button to copy the code;
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.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。