我們以安卓自動(dòng)化為例來(lái)看一下:
1模她、首先:?jiǎn)?dòng)AppiumServer换帜,默認(rèn)監(jiān)聽端口:4723
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
2言沐、測(cè)試腳本基于Json Wire Protocol協(xié)議以json格式發(fā)送請(qǐng)求給AppiumServer端隆箩,其中有一個(gè)重要的信息就是Desired Capabilities:里面攜帶了測(cè)試的設(shè)備响驴、測(cè)試的平臺(tái)等
3、服務(wù)器通過Bootstrap.ar中間件移植到測(cè)試的設(shè)備
4捶码、Bootstrap監(jiān)聽端口4724過來(lái)的命令數(shù)據(jù)羽氮,解析后交給底層驅(qū)動(dòng)UIAutomator來(lái)完成
二、如何理解appium中的會(huì)話機(jī)制:我們可以通過appium.log來(lái)進(jìn)行這個(gè)過程的分析:
[HTTP] --> POST /wd/hub/session [HTTP] {"capabilities":{"alwaysMatch":{"platformName":"Android","appium:appPackage":"com.codemao.grow","appium:appActivity":".ui.splash.SplashActivity","appium:deviceName":"192.168.109.156:5555","appium:noReset":"true","appium:autoGrantPermissions":"true"},"firstMatch":[{}]},"desiredCapabilities":{"platformName":"Android","appPackage":"com.codemao.grow","appActivity":".ui.splash.SplashActivity","deviceName":"192.168.109.156:5555","noReset":"true","autoGrantPermissions":"true"}} [W3C] Calling AppiumDriver.createSession() with args: [BaseDriver] Session created with session id: 069c6a44-c7ae-4d6b-82bf-204171348e08 [WD Proxy] Matched '/session' to command name 'createSession' [debug] ?[35m[WD Proxy]?[39m Proxying [POST /session] to [POST http://localhost:8201/wd/hub/session] with body: {"capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","appPackage":"com.codemao.grow","appActivity":".ui.splash.SplashActivity","deviceName":"192.168.109.156:5555","noReset":true,"autoGrantPermissions":true},"platformName":"Android","appPackage":"com.codemao.grow","appActivity":".ui.splash.SplashActivity","deviceName":"192.168.109.156:5555","noReset":true,"autoGrantPermissions":true,"deviceUDID":"192.168.109.156:5555"}],"alwaysMatch":{}}} [debug] ?[35m[WD Proxy]?[39m Got response with status 200: {"sessionId":"ad4655dc-e331-4abe-b043-557e73704ea8","value":{"sessionId":"ad4655dc-e331-4abe-b043-557e73704ea8","capabilities":{"firstMatch":[{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","appPackage":"com.codemao.grow","appActivity":".ui.splash.SplashActivity","deviceName":"192.168.109.156:5555","noReset":true,"autoGrantPermissions":true},"platformName":"Android","appPackage":"com.codemao.grow","appActivity":".ui.splash.SplashActivity","deviceName":"192.168.109.156:5555","noReset":true,"autoGrantPermissions":true,"deviceUDID":"192.168.109.156:5555"}],"alwaysMatch":{}}}} [info] ?[35m[WD Proxy]?[39m Determined the downstream protocol as 'W3C' [debug] ?[35m[WD Proxy]?[39m Proxying [GET /appium/device/info] to [GET http://localhost:8201/wd/hub/session/ad4655dc-e331-4abe-b043-557e73704ea8/appium/device/info] with no body [debug] ?[35m[WD Proxy]?[39m Got response with status 200: {"sessionId":"ad4655dc-e331-4abe-b043-557e73704ea8","value":{"androidId":"d5ce8f0ade0e4106","manufacturer":"OPPO","model":"PEGM00","brand":"OPPO","apiVersion":"30","platformVersion":"11","carrierName":"","realDisplaySize":"1080x2400","displayDensity":480,"networks":[{"type":1,"typeName":"WIFI","subtype":0,"subtypeName":"","isConnected":true,"detailedState":"CONNECTED","state":"CONNECTED","extraInfo":"","isAvailable":true,"isFailover":false,"isRoaming":false,"capabilities":{"transportTypes":"NET_CAPABILITY_SUPL","networkCapabilities":"","linkUpstreamBandwidthKbps":59647,"linkDownBandwidthKbps":90375,"signalStrength":-57,"networkSpecifier":null,"SSID":null}}],"locale":"zh_CN","timeZone":"Asia\/Shanghai"}}?
server地址:http://27.0.0.1:4723/wd/hub
sever和測(cè)試設(shè)備是通過4724端口來(lái)進(jìn)行通信