appium - XCUITest does not always start with error ECONNREFUSED

3.1k views Asked by At

I am trying to run some appium tests on iOS and it seems about half the time the WebDriverAgent never starts up. I get this error over and over again in the appium logs:

[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100

After this happens for some time, I'll restart the server and try again. More often than not, I'll get that error a few times but then the WebDriverAgent server will start:

debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WebDriverAgent Log file for xcodebuild test: /Users/kroe761/Library/Developer/Xcode/DerivedData/WebDriverAgent-ciegwgvxzxdrqthilmrmczmqvrgu/Logs/Test/Test-WebDriverAgentRunner-2020.10.15_11-20-17--0500.xcresult/Staging/2_Test/Diagnostics/WebDriverAgentRunner-27B846BD-B71B-4DA7-910B-ABEB46E5890F/WebDriverAgentRunner-7B63C34A-8F4F-4B67-AD6F-3F34C50C4DF1/Session-WebDriverAgentRunner-2020-10-15_112018-MRGyT7.log
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[simctl] WD Proxy connect ECONNREFUSED 127.0.0.1:8100
[debug] [simctl] WD Proxy Matched '/status' to command name 'getStatus'
[debug] [simctl] WD Proxy Proxying [GET /status] to [GET http://127.0.0.1:8100/status] with no body
[debug] [simctl] WD Proxy Got response with status 200: {"value":{"message":"WebDriverAgent is ready to accept commands","state":"success","os":{"testmanagerdVersion":28,"name":"iOS","sdkVersion":"14.0","version":"14.0"},"ios":{"simulatorVersion":"14.0","ip":"172.21.99.125"},"ready":true,"build":{"upgradedAt":"1602686780985","time":"Oct 15 2020 10:58:44","productBundleIdentifier":"com.facebook.WebDriverAgentRunner"}},"sessionId":null}
[debug] [simctl] WebDriverAgent WebDriverAgent information:
[debug] [simctl] WebDriverAgent {
[debug] [simctl] WebDriverAgent   "message": "WebDriverAgent is ready to accept commands",
[debug] [simctl] WebDriverAgent   "state": "success",
[debug] [simctl] WebDriverAgent   "os": {
[debug] [simctl] WebDriverAgent     "testmanagerdVersion": 28,
[debug] [simctl] WebDriverAgent     "name": "iOS",
[debug] [simctl] WebDriverAgent     "sdkVersion": "14.0",
[debug] [simctl] WebDriverAgent     "version": "14.0"
[debug] [simctl] WebDriverAgent   },
[debug] [simctl] WebDriverAgent   "ios": {
[debug] [simctl] WebDriverAgent     "simulatorVersion": "14.0",
[debug] [simctl] WebDriverAgent     "ip": "172.xx.xx.xxx"
[debug] [simctl] WebDriverAgent   },
[debug] [simctl] WebDriverAgent   "ready": true,
[debug] [simctl] WebDriverAgent   "build": {
[debug] [simctl] WebDriverAgent     "upgradedAt": "1602686780985",
[debug] [simctl] WebDriverAgent     "time": "Oct 15 2020 10:58:44",
[debug] [simctl] WebDriverAgent     "productBundleIdentifier": "com.facebook.WebDriverAgentRunner"
[debug] [simctl] WebDriverAgent   }
[debug] [simctl] WebDriverAgent }
[debug] [simctl] WebDriverAgent WebDriverAgent successfully started after 5889ms
[debug] [simctl] BaseDriver Event 'wdaSessionAttempted' logged at 1602778820361 (11:20:20 GMT-0500 (Central Daylight Time))
[debug] [simctl] XCUITest Sending createSession command to WDA
[debug] [simctl] WD Proxy Matched '/session' to command name 'createSession'

I absolutely hate issues where "this sometimes happens" but I've been digging into this for days and have no answer. Any help would be appreciated!

Edit: Here are my caps:

caps = {
   platformName: :ios,
   deviceName: "iPhone 11",
   automationName: "XCUITest",
   app: "/path/to/app",
   sendKeyStrategy: "setValue",
   showXcodeLog: true,
   useNewWDA: true
}
1

There are 1 answers

0
user637338 On

Even though this is Tosca documentation, this might also be very helpful in explaining why @Vault23 might be right with his hint to use

useNewWDA: true and usePrebuiltWDA: true

https://documentation.tricentis.com/tosca/1340/en/content/engines_3.0/mobile/tbox_mobileweb_set_appium_capabilities.htm

Adding above two capabilities mad my local mobile tests using Appium and local simulator of an iPhone much more stable and repeatable. Though I must admit, I do not understand why.