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

fix: assign deeply cloned processArguments for starting a WDA session #2245

Merged
merged 3 commits into from
Nov 21, 2023

Conversation

mwakizaka
Copy link
Contributor

I observed the following appium server log which appium-xcuitest-driver pushes language and locale arguments when retrying /session api call to WDA.

07:24:34:138 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Sending createSession command to WDA
07:24:34:139 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Matched '/session' to command name 'createSession'
07:24:34:140 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Proxying [POST /session] to [POST http://127.0.0.1:50201/session] with body: {"capabilities":{"firstMatch":[{"bundleId":"com.trident-qa.ScrollSleuth","arguments":["-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US"],"environment":{},"eventloopIdleDelaySec":0,"shouldWaitForQuiescence":true,"shouldUseTestManagerForVisibilityDetection":false,"maxTypingFrequency":60,"shouldUseSingletonTestManager":true,"shouldTerminateApp":true,"forceAppLaunch":true,"useNativeCachingStrategy":true,"forceSimulatorSoftwareKeyboardPresence":true}],"alwaysMatch":{}}}
07:24:34:592 i �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m socket hang up
07:24:34:910 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: socket hang up). Retrying...
07:24:35:913 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Event 'wdaSessionAttempted' logged at 1699914275912 (07:24:35 GMT+0900 (Japan Standard Time))
07:24:35:914 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Sending createSession command to WDA
07:24:35:915 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Matched '/session' to command name 'createSession'
07:24:35:917 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Proxying [POST /session] to [POST http://127.0.0.1:50201/session] with body: {"capabilities":{"firstMatch":[{"bundleId":"com.trident-qa.ScrollSleuth","arguments":["-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US","-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US"],"environment":{},"eventloopIdleDelaySec":0,"shouldWaitForQuiescence":true,"shouldUseTestManagerForVisibilityDetection":false,"maxTypingFrequency":60,"shouldUseSingletonTestManager":true,"shouldTerminateApp":true,"forceAppLaunch":true,"useNativeCachingStrategy":true,"forceSimulatorSoftwareKeyboardPresence":true}],"alwaysMatch":{}}}
07:24:35:921 i �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m connect ECONNREFUSED 127.0.0.1:50201
07:24:35:924 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:50201). Retrying...
07:24:36:926 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Event 'wdaSessionAttempted' logged at 1699914276925 (07:24:36 GMT+0900 (Japan Standard Time))
07:24:36:927 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Sending createSession command to WDA
07:24:36:928 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Matched '/session' to command name 'createSession'
07:24:36:930 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Proxying [POST /session] to [POST http://127.0.0.1:50201/session] with body: {"capabilities":{"firstMatch":[{"bundleId":"com.trident-qa.ScrollSleuth","arguments":["-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US","-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US","-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US"],"environment":{},"eventloopIdleDelaySec":0,"shouldWaitForQuiescence":true,"shouldUseTestManagerForVisibilityDetection":false,"maxTypingFrequency":60,"shouldUseSingletonTestManager":true,"shouldTerminateApp":true,"forceAppLaunch":true,"useNativeCachingStrategy":true,"forceSimulatorSoftwareKeyboardPresence":true}],"alwaysMatch":{}}}
07:24:36:934 i �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m connect ECONNREFUSED 127.0.0.1:50201
07:24:36:937 d �[38;5;64m[XCUITestDriver@68b6 (5cc2d54a)]�[0m Failed to create WDA session (An unknown server-side error occurred while processing the command. Original error: Could not proxy command to the remote server. Original error: connect ECONNREFUSED 127.0.0.1:50201). Retrying...

so that it does not push language and locale arguments twice
@mwakizaka
Copy link
Contributor Author

https://github.com/appium/appium-xcuitest-driver/actions/runs/6917960477/job/18819707172?pr=2245

npm ERR! code EIDLETIMEOUT
npm ERR! Idle timeout reached for host `registry.npmjs.org:443`
npm ERR! A complete log of this run can be found in: /Users/runner/.npm/_logs/2023-11-19T02_59_54_252Z-debug-0.log

unfortunately the test failed but it does not likely relate to this PR.

@KazuCocoa
Copy link
Member

Do you mean even when you do not set these language/locale, these were added? For example the expected value was "arguments":[],"environment":{}.

@KazuCocoa
Copy link
Member

KazuCocoa commented Nov 19, 2023

oo, i see.

"arguments":["-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US"],"environment":{}
"arguments":["-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US","-AppleLanguages","(en)","-NSLanguages","(en)","-AppleLocale","en_US"],"environment":{}
...

so keep growing the arguments

lib/driver.js Outdated
@@ -892,7 +892,7 @@ class XCUITestDriver extends BaseDriver {
try {
this.cachedWdaStatus =
this.cachedWdaStatus || (await this.proxyCommand('/status', 'GET'));
await this.startWdaSession(this.opts.bundleId, this.opts.processArguments);
await this.startWdaSession(this.opts.bundleId, _.cloneDeep(this.opts.processArguments));
Copy link
Member

Choose a reason for hiding this comment

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

I think startWdaSession method side should take care of that instead of the caller. Something like:

--- a/lib/driver.js
+++ b/lib/driver.js
@@ -1343,7 +1343,7 @@ class XCUITestDriver extends BaseDriver {
   }
 
   async startWdaSession(bundleId, processArguments) {
-    const args = processArguments ? processArguments.args || [] : [];
+    const args = processArguments ? _.cloneDeep(processArguments.args) || [] : [];
     if (!_.isArray(args)) {
       throw new Error(
         `processArguments.args capability is expected to be an array. ` +
diff --git a/test/unit/language-specs.js b/test/unit/language-specs.js
index 9014b4d5..7a0e98a8 100644
--- a/test/unit/language-specs.js
+++ b/test/unit/language-specs.js
@@ -121,6 +121,7 @@ describe('language and locale', function () {
       proxySpy.calledOnce.should.be.true;
       proxySpy.firstCall.args[0].should.eql('/session');
       proxySpy.firstCall.args[1].should.eql('POST');
+      desiredCapabilities.processArguments.should.equal(processArguments);
       /** @type {any} */ (proxySpy.firstCall.args[2]).should.eql(expectedWDACapabilities);
     });
   });

then, test case can take care of it as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you! Updated based on your comment

so that it does not affect processArguments at caller side
@KazuCocoa KazuCocoa merged commit 2e6f273 into appium:master Nov 21, 2023
17 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 21, 2023
## [5.9.1](v5.9.0...v5.9.1) (2023-11-21)

### Bug Fixes

* assign deeply cloned processArguments for starting a WDA session ([#2245](#2245)) ([2e6f273](2e6f273))
Copy link
Contributor

🎉 This PR is included in version 5.9.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mwakizaka mwakizaka deleted the fix/passDeepCloneCaps branch November 21, 2023 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants