我们以安卓自动化为例来看一下:
1、首先:启动AppiumServer,默认监听端口:4723
[Appium] Appium REST http interface listener started on 0.0.0.0:4723
2、测试脚本基于Json Wire Protocol协议以json格式发送请求给AppiumServer端,其中有一个重要的信息就是Desired Capabilities:里面携带了测试的设备、测试的平台等
3、服务器通过Bootstrap.ar中间件移植到测试的设备
4、Bootstrap监听端口4724过来的命令数据,解析后交给底层驱动UIAutomator来完成
二、如何理解appium中的会话机制:我们可以通过appium.log来进行这个过程的分析:
[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和测试设备是通过4724端口来进行通信