There is a delay in updating articles on this site, if you want to see articles about Python + Appium, please follow me over to Testhome. Testerhome.com/topics/2780…
Since I use Android devices for automatic testing, the following contents are arranged based on Android system
1. Start the APP
You need to set the Capability parameter to start your app, and the Capability parameter is put in the Desired Capalibity, which tells The automation platform and application that Appium wants, that this is a set of key-value pairs, It is used to inform the Appium server to establish the required session
Set the common part of the Capability
PlatformName Operating system (Android/iOS) platformVersion Version of the mobile phone (Android)10) deviceName Name of the connected device (emulator or real)Copy the code
Set the Android part of the Capability
AppActivity is obtained from the APK package. The method of obtaining appPackage is described belowCopy the code
Android complete case:
def start(self) :
caps = {"platformName": "Android"."deviceName": "U4AIUKFAL7W4MJLR"."platforVersion": "9"."appPackage": "com.sina.weibo"."appActivity": "com.sina.weibo.SplashActivity"."autoGrantPermissions": "true"."automationName": "UiAutomator2"
}
self.driver = webdriver.Remote("http://localhost:4723/wd/hub", caps)
Copy the code
1. PlateforName?
Operating system, such as Android, iOS, and FirefoxOS
2. What does deviceName do? (How to obtain the device name is described below.)
Device name, connected device name (real machine or emulator)
3. What does platforVersion do?
Operating system version: system version of the connected emulator or mobile phone
4. What are the functions of appActivity and appPackage? (How to obtain it is described below)
Let Appium know exactly which packages and activities should be launched for your application. Otherwise, Appium will try to automatically determine these from your application manifest.
5. What does autoGrantPermissions do?
Enable Appium to grant app permissions automatically. If noReset is True, this entry does not take effect (this parameter is unique to Android). The corresponding value can be True or False
6. What does automationName do?
Use the engine, which defaults to Appium, with Appium, UiAutomator2, Selendroid, Espresso for Android and XCUITest for iOS
7. Webdriver. Remote (” http://localhost:4723/wd/hub “, caps) what is the role of?
Webdriver. Remote is actually a subclass of native WebDriver, and the first argument to the Remote() constructor needs to show the port on which appium Server is listening
2. Exit the App
def teardown(self) :
driver.quit()
Copy the code
Iii. Implementation principle of APpium
The client (PC) sends code requests to the server through port 4723. The server and the mobile terminal (device: Mobile phone or simulator) communicates through port 4724. When the server receives the request, the bootstrap. jar package of the mobile terminal transmits the command to Uiautomator to perform click and slide operations.
Bootstrap enables socket communication and listens to port 4724
As shown below:
Appium is just a framework that calls the automation framework of Android or iOS itself. The default port number is 4723 and the local IP address is: http://127.0.0.1, or http://locahost
How to obtain deviceName?
On the mobile end, choose “Mobile phone -> Settings -> Developer Options” to open USB debugging. On the PC end, press [Windows+R], enter CMD, run CMD, and enter ADB Devices, as shown below:
The parameters in front of the device in the figure are the name of the device
How to get apK appActivity and appPackage
1. Go to the Android SDK folder and find aapt.exe under “D:\Android\SDK\build-tools\30.0.1”, as shown below:
2. Press [Windows+R], enter CMD, run CMD to go to the disk, and then go to the folder where appt. Exe is located. “CD D:\Android\SDK\build-tools\30.0.1”, you can enter the folder, enter “aapt dump badging APK path + APK name”, as shown in the following figure, it is successful. The following figure shows the appPackage of the obtained app
The following figure shows the appActivity of the obtained app
If there are mistakes in the above content, welcome to correct!