Appium principle and JsonWP protocol analysis of dry goods app automated testing

This article is excerpted from the internal textbook of Hogwarts Testing Institute

If you want to use appium for testing, you must first understand the principle of appium. Appium can not only implement JSONWP on the mobile end, but also extend to Selenium
JSONWP, which can control the behavior of different mobile devices, such as installing and uninstalling apps through sessions.

Appium principle

Dependency explanation in the figure:

  • You can write test scripts in Java and Python languages

  • Use Appium services to drive different devices to perform automated testing

  • Android APP uses UiAutomator driver and iOS APP uses WebDriverAgent driver

  • ADB is used to drive the AdbServer

  • ChromeDriver can be used to directly communicate with AdbServer, or remotely debug Chrome, WebView and wechat applets

  • AppCrawler open source framework also uses Appium Server services to complete automatic traversal testing

JsonWP protocol analysis

JSON wire protocol (JSON WP) is a communication protocol written by WebDriver developers. This communication protocol is a predefined special setting through
RESTful API exposes standard ports.

Here is an Appium log:

In the figure, send a POST request in the format of / session/{session id}/element and Webdriver
When the element to be located is parsed, it will be converted into the instruction of the location element that can be recognized by the mobile terminal, and go to the mobile terminal to locate this element.

Here are some URI templates used to connect mobile applications:

For more detailed template information, please refer to the following link:

The commands in the above table can be called on the mobile terminal. For example, use curl command to manually simulate sending a request to Appium, Session id
It can be accessed in the browser , see which sessions are available.

Next, use the curl command to create a session on Appium, and then use this session to send a find element request:

# use curl Command to send a http POST request, With -d The following parameters, that is Desired Capability set up# Create a Sessioncurl ' / WD / hub / session '\ - xpost - H "content type: application / JSON" \ - D' {capabilities': {value}} '# obtain session idsession after establishing connection_ id=$(curl ' '\ | awk - F \ "' {print $6} ') # use curl command to simulate locating curl by ID" ${session_id}/element" \ -H "Content-Type: Application/JSON" \-d  '{"using":"id","value":"user_profile_icon"}'
  • -d indicates the parameter passed in
  • -H join request header

The operation results are as follows:

# Create session $curl - L - H "content type: application / JSON" - x post - D \ '{"desiredcapabilities": {"platformname": "Android", \ "devicename": "", "platformversion": \ "6.0", "apppackage": "com. Xueqiu. Android", "appactivity": \ "com. Xueqiu. Android. Common. Mainactivity"}}' \ ' '  
# The result of the above command is {"value": {"platform": "Linux", "webstorageenabled": false, \ "takesscreen": true, "JavaScript enabled": true, \ "databaseenabled": false, "networkconnectionenabled": \ true, "locationcontextenabled": false, "warnings": {}, \"desired":{"platformName":"Android","deviceName":\"","platformVersion":"6.0",\"appPackage":"","appActivity":\""},"platformName":\"Android","deviceName":"","platformVersion":\"6.0","appPackage":"", "appActivity":\"","deviceUDID":\"","deviceApiLevel":23,"deviceScreenSize":\"1080x1920","deviceScreenDensity":420,"deviceModel":\"Google Nexus 5X","deviceManufacturer":"Genymotion",\"pixelRatio":2.625,"statBarHeight":63,"viewportRect":{\"left":0,"top":63,"width":1080,"height":1731}}, "sessionId":"1c0bda0f-1a60-4cab-8fe3-f7ee5a6c005b",\"status":0}%  
# Get session ID $session_ id=$(curl ' ' \    | awk -F\" '{print $6}')  
# Positioning element $curl“ ${session_id}/element" \-XPOST -H "Content-Type: Application/JSON" \-d  '{"using":"id","value":""}'  
# Get the result {"value":{"element-6066-11e4-a52e-4f735466cecf":\"ddd0261e-fff0-4642-b24d-bf64a708c916","ELEMENT":\"ddd0261e-fff0-4642-b24d-bf64a708c916"},"sessionId":\"1c0bda0f-1a60-4cab-8fe3-f7ee5a6c005b","status":0}%

In the above running process analysis, first create a Session with curl command, and then obtain the session id and save it to the session_id in this variable, and finally
curl sends an HTTP request to complete the search box first.

At this time, do you have a deeper understanding of Appuim?

** _
Come to Hogwarts test and development society to learn more advanced technologies of software testing and test development. The knowledge points include web automated testing, app automated testing, interface automated testing, test framework, performance testing, security testing, continuous integration / continuous delivery / DevOps, test left, test right, precision testing, test platform development, test management, etc, The course technology covers bash, pytest, junit, selenium, appium, postman, requests, httprunner, jmeter, jenkins, docker, k8s, elk, sonarqube, Jacobo, JVM sandbox and other related technologies, so as to comprehensively improve the technical strength of test and development engineers
QQ communication group: 484590337
The official account TestingStudio
Click for more information

Added by Corin on Mon, 10 Jan 2022 06:14:18 +0200