Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

return current status to ensure appium uses cached WDA #909

Merged
merged 3 commits into from
Mar 23, 2019

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Mar 23, 2019

Fix appium/appium#12259

Based on current behaviour in re-use WDA is below. Try to call [XCUITest] Using provided WebdriverAgent at 'http://localhost:8100/' even if Appium already ensured the response like Got response with status 200.

debug] [XCUITest] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[debug] [WD Proxy] Got response with status 200: "{\n  \"value\" : {\n    \"state\" : \"success\",\n    \"os\" : {\n      \"name\" : \"iOS\",\n      \"version\" : \"12.1.4\",\n      \"sdkVersion\" : \"12.0\"\n    },\n    \"ios\" : {\n      \"simulatorVersion\" : \"12.1.4\",\n      \"ip\" : \"172.254.99.33\"\n    },\n    \"build\" : {\n      \"upgradedAt\" : \"1552566621411\",\n      \"time\" : \"Mar 23 2019 14:00:27\",\n      \"productBundleIdentifier\" : \"com.trident.WebDriverAgentRunner\"\n    }\n  },\n  \"sessionId\" : \"EC8A8715-502E-4087-A282-98ED454CD050\",\n  \"status\" : 0\n}"
[debug] [XCUITest] Upgrade timestamp of the currently bundled WDA: 1552566621411
[debug] [XCUITest] Upgrade timestamp of the WDA on the device: 1552566621411
[XCUITest] Will reuse previously cached WDA instance at 'http://localhost:8100/' with 'com.trident.WebDriverAgentRunner'. Set the wdaLocalPort capability to a value different from 8100 if this is an undesired behavior.
[debug] [XCUITest] Trying to start WebDriverAgent 1 times with 10000ms interval
[debug] [XCUITest] These values can be customized by changing wdaStartupRetries/wdaStartupRetryInterval capabilities
[debug] [BaseDriver] Event 'wdaStartAttempted' logged at 1553318314574 (14:18:34 GMT+0900 (Japan Standard Time))
[XCUITest] Using provided WebdriverAgent at 'http://localhost:8100/'
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553318314575 (14:18:34 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[WD Proxy] Got an unexpected response: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":8100}
[debug] [XCUITest] Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: connect ECONNREFUSED 127.0.0.1:8100). Retrying...
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553318315591 (14:18:35 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[WD Proxy] Got an unexpected response: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":8100}
[debug] [XCUITest] Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: connect ECONNREFUSED 127.0.0.1:8100). Retrying...
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553318316600 (14:18:36 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[WD Proxy] Got an unexpected response: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":8100}
[debug] [XCUITest] Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: connect ECONNREFUSED 127.0.0.1:8100). Retrying...
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553318317609 (14:18:37 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[WD Proxy] Got an unexpected response: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":8100}
[debug] [XCUITest] Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to remote server. Original error: Error: connect ECONNREFUSED 127.0.0.1:8100). Retrying...
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553318318616 (14:18:38 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[WD Proxy] Got an unexpected response: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":8100}

return await this.xcodebuild.start(); called in async launch (sessionId) { returns current /status, but the launch function does not retun such status if this.webDriverAgentUrl is set.

It means this.cachedWdaStatus in

this.cachedWdaStatus = await retry(retries, this.wda.launch.bind(this.wda), sessionId, realDevice);
never be not undefined if await this.wda.setupCaching(this.opts.updatedWDABundleId); in
await this.wda.setupCaching(this.opts.updatedWDABundleId);
works.

After this PR, the this.cachedWdaStatus can get current running WDA status like below. As the result, xcuitest-driver can use existing WDA instance in the new session.

[XCUITest] Setting up real device
[XCUITest] Using WDA path: '/Users/kazu/GitHub/ruby_lib_core/tmp/9U4PT397Q4/Build/Products'
[XCUITest] Using WDA agent: '/Users/kazu/GitHub/ruby_lib_core/tmp/9U4PT397Q4/Build/Products/WebDriverAgent.xcodeproj'
[debug] [XCUITest] No obsolete cached processes from previous WDA sessions listening on port 8100 have been found
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[debug] [XCUITest] recv failed: Operation not permitted
[debug] [XCUITest] Connection to WDA timed out
[debug] [iProxy] recv failed: Operation not permitted
[debug] [WD Proxy] Got response with status 200: "{\n  \"value\" : {\n    \"state\" : \"success\",\n    \"os\" : {\n      \"name\" : \"iOS\",\n      \"version\" : \"12.1.4\",\n      \"sdkVersion\" : \"12.0\"\n    },\n    \"ios\" : {\n      \"simulatorVersion\" : \"12.1.4\",\n      \"ip\" : \"172.254.99.33\"\n    },\n    \"build\" : {\n      \"upgradedAt\" : \"1552566621411\",\n      \"time\" : \"Mar 23 2019 13:54:25\",\n      \"productBundleIdentifier\" : \"com.trident.WebDriverAgentRunner\"\n    }\n  },\n  \"sessionId\" : \"07F6E3F2-AE16-46A8-BF50-4AED358BB064\",\n  \"status\" : 0\n}"
[debug] [XCUITest] Upgrade timestamp of the currently bundled WDA: null
[debug] [XCUITest] Upgrade timestamp of the WDA on the device: 1552566621411
[XCUITest] Will reuse previously cached WDA instance at 'http://localhost:8100/' with 'com.trident.WebDriverAgentRunner'. Set the wdaLocalPort capability to a value different from 8100 if this is an undesired behavior.
[debug] [XCUITest] Trying to start WebDriverAgent 1 times with 10000ms interval
[debug] [XCUITest] These values can be customized by changing wdaStartupRetries/wdaStartupRetryInterval capabilities
[debug] [BaseDriver] Event 'wdaStartAttempted' logged at 1553319931916 (14:45:31 GMT+0900 (Japan Standard Time))
[XCUITest] Using provided WebdriverAgent at 'http://localhost:8100/'
[debug] [WD Proxy] Matched '/status' to command name 'getStatus'
[debug] [WD Proxy] Proxying [GET /status] to [GET http://localhost:8100/status] with no body
[debug] [WD Proxy] Got response with status 200: "{\n  \"value\" : {\n    \"state\" : \"success\",\n    \"os\" : {\n      \"name\" : \"iOS\",\n      \"version\" : \"12.1.4\",\n      \"sdkVersion\" : \"12.0\"\n    },\n    \"ios\" : {\n      \"simulatorVersion\" : \"12.1.4\",\n      \"ip\" : \"172.254.99.33\"\n    },\n    \"build\" : {\n      \"upgradedAt\" : \"1552566621411\",\n      \"time\" : \"Mar 23 2019 13:54:25\",\n      \"productBundleIdentifier\" : \"com.trident.WebDriverAgentRunner\"\n    }\n  },\n  \"sessionId\" : \"07F6E3F2-AE16-46A8-BF50-4AED358BB064\",\n  \"status\" : 0\n}"
[debug] [BaseDriver] Event 'wdaSessionAttempted' logged at 1553319931935 (14:45:31 GMT+0900 (Japan Standard Time))
[debug] [XCUITest] Sending createSession command to WDA
[debug] [WD Proxy] Matched '/session' to command name 'createSession'

lib/wda/webdriveragent.js Outdated Show resolved Hide resolved
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch @KazuCocoa
Thanks

@imurchie imurchie merged commit 95161a2 into appium:master Mar 23, 2019
@KazuCocoa KazuCocoa deleted the km/fix-cache-wda branch March 23, 2019 15:27
khanayan123 pushed a commit to khanayan123/appium-xcuitest-driver that referenced this pull request May 10, 2021
* return current status to ensure appium uses cached WDA

* update docstring

* add await
@danyansun
Copy link

if I set WDA_LOCAL_PORT which not default port: 8100, it seems the useNewWDA not working? could you please help to check?

@KazuCocoa
Copy link
Member Author

Do you mean appium:wdaLocalPort in the capability?
The useNewWDA is just to uninstall installed WDA as

if (this.opts.useNewWDA) {
this.log.debug(`Capability 'useNewWDA' set to true, so uninstalling WDA before proceeding`);
await this.wda.quitAndUninstall();
this.logEvent('wdaUninstalled');
in the latest version. Others may work from the clean installation

@danyansun
Copy link

Here is the scene:
I want to run ios parallel test, which mean I should use different wdaLocalPort for each ios devices, can I reuse cached WDA if I set capability like {"useNewWDA":"false"}?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Could not reuse existing WDA on real iPhone device.
4 participants