Python + Appium automated testing

First, prepare the environment

1. scripting languages: Python3.x     the IDE: Installation P ycharm

2. Install the Java JDK, Android SDK

3.adb environment, path to add E: \ Software \ Android_SDK \ platform-tools

4. Install Appium for windows, the official website address  http://appium.io/

 Click on the download page to download the GitHub button to select the corresponding platform download

 After the installation is complete, start Appium, host and port to default, then set the Java JDK and Android SDk   

 

 Then below that save and restart button, and then the first Start Server button, you will see

 Second, the real test

1. Connect your phone

Open developer mode, USB cable to connect your phone and computer, and developers among the options open USB Debugging

 Test whether the connection is successful, the executable command adb devices

 

  Appears on the map as evidenced by the success of mobile phones and computer connections. . .

 2. Click Start Inspector Session,

 

 Desired Capabilities configured as follows

 

 PlatformName  : statement ios or Android system

 platformVersion  : Android kernel version, can command adb shell getprop ro.build.version.release View

 

 deviceName  : the name of the device connected via adb devices -l command in the model view

  appPackage  : APK's package name

 appActivity: APK's launcherActivity, the command adb shell dumpsys activity | findstr "mResume " view (you must first open the phone application)

Note: You should use adb shell dumpsys activity before Android 8.1 | findstr "mFocus"

 3. Run Start Session, select the elements

 Selected Element three areas right buttons

  • Tap: Execute the selected element click event
  • Send Keys: a text box object by value, etc.
  • If it is a text input element, to clear the text

4. Record script

 Recording the generated python code is as follows:

# This sample code uses the Appium python client
# pip install Appium-Python-Client
# Then you can paste this into a file and simply run with Python

from appium import webdriver

caps = {}
caps["platformName"] = "Android"
caps["platformVersion"] = "9.0.0"
caps["deviceName"] = "Mi_Note_3"
caps["appPackage"] = "com.antfortune.wealth"
caps["appActivity"] = "com.alipay.mobile.quinox.LauncherActivity"
caps["resetKeyboard"] = True
caps["unicodeKeyboard"] = True

driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)

el1 = driver.find_element_by_id("com.antfortune.wealth.login:id/login_main_button")
el1.click()
el2 = driver.find_element_by_id("com.alipay.mobile.accountauthbiz:id/auth_login_btn")
el2.click()

driver.quit()

5. Establish project pycharm glued into the code, before running, need to install pip install Appium-Python-Client order dependencies by pip

 Finally, I remember a problem encountered in these processes (now resolved)

 When you run the Start Session in Appium-desktop, the emergence of

 Solution: In developer mode, open the usb debugging function and use simulate a click, two must be open, then re-run, you can solve

Guess you like

Origin www.cnblogs.com/jyd0124/p/appium.html