• Download and install Appium
  • Configure and use Appium
  • The configuration of engineering

1. Download and install Appium

To download the MAC version of Appium-Desktop, I chose to use version 1.17.1, the latest version 1.22.0, to split a desktop application into two desktop applications, one called Appium Server and the other AppiumInspector.

Download link: github.com/appium/appi…

UI Automator, Google’s automated testing framework, is integrated with Appium. Details are as follows: developer. The android. Google. Cn/training/te…

2. Configure and use Appium

A. Configure adb, JDK, and SDK environment variables on the computer, and open the Appium application.

Host and port do not need to be modified. Click Start and the page is as follows. Click the arrow position to configure app information.

B. Configure appium

C. Adb commands involved

adb devices -l
Copy the code
adb shell dumpsys activity | grep "mResume"
Copy the code

The Json information should be configured according to the information of the specific mobile phone and the app to be tested. The first rectangle is the content of appPackage and the second rectangle is the content of appActivity. Enter the following command to obtain the required information.

adb shell dumpsys activity | grep “mResume”

Enter the following command to obtain the contents of the rectangle and populate the deviceName option in Json

adb devices -l

D. After clicking Start Session, appium is officially used, indicating that the configuration is successful. The interface is as follows:

3. Configure the projectA. Click Record

B. To generate the UI automation script, click 1- “Interface control -” 2- “3 to copy the script in 3

C. Create a new project using AS, such AS Java project, and download three dependent JAR packages from Maven-resposity. Download the commons-lang3-3.1.jar, Java-client-7.3.0.jar, and Selenium-server-standalone 3.141.59.jar libraries in the libs directory of the new module. Build. gradle configuration relies on junit and JAR packages. Create a new app folder and copy the apK to this directory. The corresponding APK must be set to false. Otherwise, an error will occur.

D. Finally, write the test code and execute it as a common console program, the code is as follows:

package com.mobile.searchandclick; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.remote.DesiredCapabilities; import java.io.File; import java.net.MalformedURLException; import java.net.URL; import io.appium.java_client.MobileElement; import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.AndroidElement; public class MyClass { private AndroidDriver<AndroidElement> driver; @Before public void init() { File classpathRoot = new File(System.getProperty("user.dir")); AppDir = new File(classpathRoot, "/app/"); File app = new File(appDir, "app.apk"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("platformName","Android"); / / system platform version "capabilities. SetCapability (" platformVersion", "10"); / / device name, here is the device name "capabilities of the simulator. The setCapability (" deviceName", "ONEPLUS_A6000"); capabilities.setCapability("app", app.getAbsolutePath()); Measured application package name "capabilities. / / set the setCapability (" appPackage", "com. Example. Android. Navigationsample"); / / app entrance to start the activity "capabilities. The setCapability (" appActivity", "MainActivity"); / / connect appium start corresponding app try {driver = new AndroidDriver < > (new URL (" http://127.0.0.1:4723/wd/hub "), "capabilities); } catch (MalformedURLException e) { e.printStackTrace(); } System.out.println("App is launched!" ); } // Copyright notice: This article is originally published BY CSDN blogger "Yu Le You Xi". It follows CC 4.0 BY-SA copyright agreement. Please attach the source link of the original article and this statement. // Original link: https://blog.csdn.net/yjf611/article/details/104470449 @Test public void sampleTest() throws InterruptedException { Thread.sleep(2000); MobileElement el2 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/play_btn"); el2.click(); Thread.sleep(2000); MobileElement el3 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/username_text"); el3.sendKeys("haha"); Thread.sleep(2000); MobileElement el4 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/email_text"); el4.sendKeys("[email protected]"); Thread.sleep(2000); MobileElement el5 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/password_text"); el5.sendKeys("111"); Thread.sleep(2000); MobileElement el6 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/signup_btn"); el6.click(); Thread.sleep(2000); MobileElement el7 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/play_btn3"); el7.click(); Thread.sleep(2000); MobileElement el8 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/checkBox"); el8.click(); Thread.sleep(2000); MobileElement el9 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/play_btn4"); el9.click(); Thread.sleep(2000); MobileElement el10 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/play_btn3"); el10.click(); Thread.sleep(2000); MobileElement el11 = (MobileElement) driver.findElementById("com.example.android.navigationsample:id/checkBox3"); el11.click(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); driver.navigate().back(); Thread.sleep(2000); System.out.println("App is done!" ); } @After public void end() throws InterruptedException{ driver.quit(); }}Copy the code

The warehouse address of the project is as follows: gitee.com/Greny/Appiu…