Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

feat: Allow to configure host/port/app path for Appium for mac app in appium-mac-driver #42

Merged
merged 7 commits into from
Jan 19, 2020

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Jan 4, 2020

[updated]
This PR allows users to configure port/host/path to connect to appium-for-mac. Users must build a4m after changing https://github.com/appium/appium-for-mac/blob/2356957dc73b6275262c918ca8f4184ef4a25af0/AppiumForMac/AppiumForMacAppDelegate.m#L36 . So, this usage is a more advanced one.


Related to appium/appium-for-mac#79

@sankalpphirke
What about with this branch?
You can configure the host/port with a4mHost and a4mPort capabilities.

i.e.

[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"automationName":"mac","platformName":"mac","a4mHost":"localhost","a4mPort":9090},"capabilities":{"firstMatch":[{"appium:automationName":"mac","platformName":"mac","appium:a4mHost":"localhost","appium:a4mPort":9090}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"automationName":"mac","platformName":"mac","a4mHost":"localhost","a4mPort":9090},null,{"firstMatch":[{"appium:automationName":"mac","platformName":"mac","appium:a4mHost":"localhost","appium:a4mPort":9090}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1578150445992 (00:07:25 GMT+0900 (Japan Standard Time))
[Appium] Appium v1.16.0-beta.3 creating new MacDriver (v1.8.0) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver]   "alwaysMatch": {
[debug] [BaseDriver]     "platformName": "mac",
[debug] [BaseDriver]     "appium:automationName": "mac",
[debug] [BaseDriver]     "appium:a4mHost": "localhost",
[debug] [BaseDriver]     "appium:a4mPort": 9090
[debug] [BaseDriver]   },
[debug] [BaseDriver]   "firstMatch": [
[debug] [BaseDriver]     {}
[debug] [BaseDriver]   ]
[debug] [BaseDriver] }
[BaseDriver] Session created with session id: 49941c74-9178-4e07-aa22-bdbf6da7445e
[MacDriver] Killing any old AppiumForMac
[MacDriver] Successfully cleaned up old Appium4Mac servers
[MacDriver] Spawning AppiumForMac with: undefined
[Appium4Mac] [STDERR] 2020-01-05 00:07:26:914 AppiumForMac[59877:307] HTTPServer: Started HTTP server on port 4622
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://localhost:9090/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"mac","automationName":"mac","a4mHost":"localhost","a4mPort":9090}}
[WD Proxy] Got an unexpected response with status undefined: {"errno":"ECONNREFUSED","code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9090}
[debug] [MacDriver] Deleting AppiumForMac session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1578150446934 (00:07:26 GMT+0900 (Japan Standard Time))
[debug] [W3C] Encountered internal error running command: UnknownError: 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:9090
[debug] [W3C]     at JWProxy.command (/Users/kazu/GitHub/appium-mac-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:270:13)
[HTTP] <-- POST /wd/hub/session 500 957 ms - 574

You can:

git clone git@github.com:appium/appium.git
cd appium && npm install
git clone git@github.com:KazuCocoa/appium-mac-driver.git
cd appium-mac-driver && git checkout make-port-configuable && npm install && npm link

cd appium && npm link appium-mac-driver
node . # in appium directory

@sankalphirke
Copy link

Hello Kazu,
i am getting strange error on adding new capabilities

[HTTP] {"desiredCapabilities":{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"localhost","platformName":"Mac","deviceName":"Mac"},"capabilities":{"firstMatch":[{"a4mHost":"localhost","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"Mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"localhost","platformName":"Mac","deviceName":"Mac"},null,{"firstMatch":[{"a4mHost":"localhost","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"Mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1578288396168 (10:56:36 GMT+0530 (India Standard Time))
[BaseDriver] The capabilities ["a4mHost","a4mPort"] are not standard capabilities and should have an extension prefix
[Appium] Appium v1.16.0 creating new MacDriver (v1.7.0) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver] "alwaysMatch": {
[debug] [BaseDriver] "appium:a4mHost": "localhost",
[debug] [BaseDriver] "appium:a4mPort": 9092,
[debug] [BaseDriver] "platformName": "mac",
[debug] [BaseDriver] "appium:app": "Switchboard - Dev",
[debug] [BaseDriver] "appium:deviceName": "Mac",
[debug] [BaseDriver] "appium:newCommandTimeout": 30000,
[debug] [BaseDriver] "appium:noReset": "false",
[debug] [BaseDriver] "appium:platformVersion": "10.15.1"
[debug] [BaseDriver] },
[debug] [BaseDriver] "firstMatch": [
[debug] [BaseDriver] {}
[debug] [BaseDriver] ]
[debug] [BaseDriver] }
[debug] [MacDriver] Deleting AppiumForMac session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1578288396214 (10:56:36 GMT+0530 (India Standard Time))
[debug] [W3C] Encountered internal error running command: Error: Unknown validator platformName
[debug] [W3C] at Function.runValidations (/usr/local/lib/node_modules/appium/node_modules/validate.js/validate.js:109:19)

@KazuCocoa
Copy link
Member Author

Hmm.
Could you try to build the appium environment from git clone git@github.com:appium/appium.git as I addressed in the above description or uninstall/install npm -g appium once?

btw, my working branch should be MacDriver 1.8.0 base.
(Yours was [Appium] Appium v1.16.0 creating new MacDriver (v1.7.0) session)

@sankalphirke
Copy link

sankalphirke commented Jan 6, 2020

@KazuCocoa
I update the driver to current branch and reinstalled appium. Both capabilities are being captured but not used.

[HTTP] {"desiredCapabilities":{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"127.0.0.1","platformName":"mac","deviceName":"mac"},"capabilities":{"firstMatch":[{"a4mHost":"127.0.0.1","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"127.0.0.1","platformName":"mac","deviceName":"mac"},null,{"firstMatch":[{"a4mHost":"127.0.0.1","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1578327887985 (21:54:47 GMT+0530 (India Standard Time))
[BaseDriver] The capabilities ["a4mHost","a4mPort"] are not standard capabilities and should have an extension prefix
[Appium] Appium v1.16.0 creating new MacDriver (v1.8.0) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver] "alwaysMatch": {
[debug] [BaseDriver] "appium:a4mHost": "127.0.0.1",
[debug] [BaseDriver] "appium:a4mPort": 9092,
[debug] [BaseDriver] "platformName": "mac",
[debug] [BaseDriver] "appium:app": "Switchboard - Dev",
[debug] [BaseDriver] "appium:deviceName": "mac",
[debug] [BaseDriver] "appium:newCommandTimeout": 30000,
[debug] [BaseDriver] "appium:noReset": "false",
[debug] [BaseDriver] "appium:platformVersion": "10.15.1"
[debug] [BaseDriver] },
[debug] [BaseDriver] "firstMatch": [
[debug] [BaseDriver] {}
[debug] [BaseDriver] ]
[debug] [BaseDriver] }
[BaseDriver] Capability 'noReset' changed from string to boolean. This may cause unexpected behavior
[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver] a4mHost
[BaseDriver] a4mPort
[BaseDriver] app
[BaseDriver] Session created with session id: ed7ab8ea-e14d-4e03-ab60-afc2740cb40e
[MacDriver] Killing any old AppiumForMac
[MacDriver] Successfully cleaned up old Appium4Mac servers
[MacDriver] Spawning AppiumForMac with: undefined
[Appium4Mac] [STDERR] 2020-01-06 21:54:48:199 AppiumForMac[27673:307] HTTPServer: Started HTTP server on port 4622
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4622/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"mac","a4mHost":"127.0.0.1","a4mPort":9092,"app":"Switchboard - Dev","deviceName":"mac","newCommandTimeout":30000,"noReset":false,"platformVersion":"10.15.1"}}
[debug] [WD Proxy] Got response with status 200: {"status":0,"sessionId":"sp6dZvJH","value":{"locationContextEnabled":false,"webStorageEnabled":false,"browserName":"Mac","platform":"Mac","databaseEnabled":false,"version":"10.15.1","javascriptEnabled":true,"takesScreenshot":true,"nativeEvents":true}}
[WD Proxy] Determined the downstream protocol as 'MJSONWP'
[MacDriver] Automatically navigating to app 'Switchboard - Dev'
[debug] [WD Proxy] Matched '/url' to command name 'setUrl'
[debug] [WD Proxy] Proxying [POST /url] to [POST http://127.0.0.1:4622/wd/hub/session/sp6dZvJH/url] with body: {"url":"Switchboard - Dev"}
[debug] [WD Proxy] Got response with status 200: {"status":0,"sessionId":"sp6dZvJH"}
[Appium] New MacDriver session created successfully, session ed7ab8ea-e14d-4e03-ab60-afc2740cb40e added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1578327888775 (21:54:48 GMT+0530 (India Standard Time))
[debug] [W3C (ed7ab8ea)] Cached the protocol value 'W3C' for the new session ed7ab8ea-e14d-4e03-ab60-afc2740cb40e
[debug] [W3C (ed7ab8ea)] Responding to client with driver.createSession() result: {"capabilities":{"platformName":"mac","a4mHost":"127.0.0.1","a4mPort":9092,"app":"Switchboard - Dev","deviceName":"mac","newCommandTimeout":30000,"noReset":false,"platformVersion":"10.15.1"}}
[HTTP] <-- POST /wd/hub/session 200 792 ms - 252

@KazuCocoa
Copy link
Member Author

git clone can do in another directory. npm link changes references in appium.
If you would like to link in global installed appium, you should call the npm link in the global appium's root directory like /Users/kazu/.nvm/versions/node/v10.16.0/lib/node_modules/appium

@sankalphirke
Copy link

4622

git clone can do in another directory. npm link changes references in appium.
If you would like to link in global installed appium, you should call the npm link in the global appium's root directory like /Users/kazu/.nvm/versions/node/v10.16.0/lib/node_modules/appium

@KazuCocoa :- i updated the driver, both caps are taken as input but not used, i have attached logs.

@KazuCocoa
Copy link
Member Author

Could you attach steps you did?
Your new log had below lines. It meant your environment did not have this working branch's change.

[BaseDriver] The following capabilities were provided, but are not recognized by Appium:
[BaseDriver] a4mHost
[BaseDriver] a4mPort

@sankalphirke
Copy link

@KazuCocoa , I performed below steps

  1. Git download mac driver 1.8 , rename the folder it to appium-mac-driver
  2. cd Appium and npm link to the downloaded appium-mac-driver folder

it picked the assigned port but failed to start the server as appium for mac application is still running on 4622 as per line
[Appium4Mac] [STDERR] 2020-01-07 11:58:06:388 AppiumForMac[6684:307] HTTPServer: Started HTTP server on port 4622

And can we keep the port to get assigned on run time, like we have for appium -->builder.usingAnyFreePort();

[Appium] a4mHost: 127.0.0.1
[Appium] a4mPort: 9092
[Appium] app: Switchboard - Dev
[Appium] deviceName: mac
[Appium] newCommandTimeout: 30000
[Appium] noReset: false
[Appium] platformName: mac
[Appium] platformVersion: 10.15.1
[Appium] Appium REST http interface listener started on 127.0.0.1:22610
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [GENERIC] Calling AppiumDriver.getStatus() with args: []
[debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.16.0"}}
[HTTP] <-- GET /wd/hub/status 200 4 ms - 68
[HTTP]
[HTTP] --> GET /wd/hub/status
[HTTP] {}
[debug] [GENERIC] Calling AppiumDriver.getStatus() with args: []
[debug] [GENERIC] Responding to client with driver.getStatus() result: {"build":{"version":"1.16.0"}}
[HTTP] <-- GET /wd/hub/status 200 1 ms - 68
[HTTP]
[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"127.0.0.1","platformName":"mac","deviceName":"mac"},"capabilities":{"firstMatch":[{"a4mHost":"127.0.0.1","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"Switchboard - Dev","noReset":"false","a4mPort":9092,"newCommandTimeout":30000,"platformVersion":"10.15.1","a4mHost":"127.0.0.1","platformName":"mac","deviceName":"mac"},null,{"firstMatch":[{"a4mHost":"127.0.0.1","a4mPort":9092,"appium:app":"Switchboard - Dev","appium:deviceName":"mac","appium:newCommandTimeout":30000,"appium:noReset":"false","platformName":"mac","appium:platformVersion":"10.15.1"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1578378485718 (11:58:05 GMT+0530 (India Standard Time))
[BaseDriver] The capabilities ["a4mHost","a4mPort"] are not standard capabilities and should have an extension prefix
[Appium] Appium v1.16.0 creating new MacDriver (v1.8.0) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver] "alwaysMatch": {
[debug] [BaseDriver] "appium:a4mHost": "127.0.0.1",
[debug] [BaseDriver] "appium:a4mPort": 9092,
[debug] [BaseDriver] "platformName": "mac",
[debug] [BaseDriver] "appium:app": "Switchboard - Dev",
[debug] [BaseDriver] "appium:deviceName": "mac",
[debug] [BaseDriver] "appium:newCommandTimeout": 30000,
[debug] [BaseDriver] "appium:noReset": "false",
[debug] [BaseDriver] "appium:platformVersion": "10.15.1"
[debug] [BaseDriver] },
[debug] [BaseDriver] "firstMatch": [
[debug] [BaseDriver] {}
[debug] [BaseDriver] ]
[debug] [BaseDriver] }
[BaseDriver] Capability 'noReset' changed from string to boolean. This may cause unexpected behavior
[BaseDriver] Session created with session id: a8691890-92b4-4d8f-aff1-bce2da27f512
[MacDriver] Killing any old AppiumForMac
[MacDriver] Successfully cleaned up old Appium4Mac servers
[MacDriver] Spawning AppiumForMac with: undefined
[Appium4Mac] [STDERR] 2020-01-07 11:58:06:388 AppiumForMac[6684:307] HTTPServer: Started HTTP server on port 4622
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9092/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"mac","a4mHost":"127.0.0.1","a4mPort":9092,"app":"Switchboard - Dev","deviceName":"mac","newCommandTimeout":30000,"noReset":false,"platformVersion":"10.15.1"}}
[WD Proxy] Got an unexpected response with status undefined: {"errno":-61,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":9092}
[debug] [MacDriver] Deleting AppiumForMac session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1578378486402 (11:58:06 GMT+0530 (India Standard Time))
[debug] [W3C] Encountered internal error running command: UnknownError: 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:9092
[debug] [W3C] at JWProxy.command (/Users/sankalp/Downloads/appium-mac-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:270:13)
[HTTP] <-- POST /wd/hub/session 500 696 ms - 580
[HTTP]
org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: 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:9092
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'INFPUMAC07.local', ip: 'fe80:0:0:0:1ce0:dc18:ca3b:efa6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.1', java.version: '1.8.0_231'
Driver info: driver.version: AppiumDriver
remote stacktrace: UnknownError: 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:9092
at JWProxy.command (/Users/sankalp/Downloads/appium-mac-driver/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:270:13)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'INFPUMAC07.local', ip: 'fe80:0:0:0:1ce0:dc18:ca3b:efa6%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.1', java.version: '1.8.0_231'
Driver info: driver.version: AppiumDriver

@KazuCocoa
Copy link
Member Author

KazuCocoa commented Jan 7, 2020

Thanks.
The latest log worked expectedly.

This PR fixes below line in appium/appium-for-mac#79

[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:4622/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"mac","app":"Convo Dev","deviceName":"Mac","newCommandTimeout":300,"noReset":false}}
[WD Proxy] Got an unexpected response with status undefined: {"errno":-61,"code":"ECONNREFUSED","syscall":"connect","address":"127.0.0.1","port":4622}

In the issue, Appium tried to communicate with server running on mac as [Appium4Mac] [STDERR] 2019-12-23 13:53:40:165 AppiumForMac[1768:307] HTTPServer: Started HTTP server on port 50369, but Appium's http request was for http://127.0.0.1:4622 (default value).
With this PR, you could configure the port as 9092. Then, Appium tried to communicate with the server via http://127.0.0.1:9092. Once you set the a4mPort as 50369, Appium can talk with the server listening the port 50369 in appium/appium-for-mac#79

[debug] [BaseDriver] "appium:a4mHost": "127.0.0.1",
[debug] [BaseDriver] "appium:a4mPort": 9092,
...
[debug] [WD Proxy] Matched '/session' to command name 'createSession'
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:9092/wd/hub/session] with body: {"desiredCapabilities":{"platformName":"mac","a4mHost":"127.0.0.1","a4mPort":9092,"app":"Switchboard - Dev","deviceName":"mac","newCommandTimeout":30000,"noReset":false,"platformVersion":"10.15.1"}}

it picked the assigned port but failed to start the server as appium for mac application is still running on 4622 as per line
[Appium4Mac] [STDERR] 2020-01-07 11:58:06:388 AppiumForMac[6684:307] HTTPServer: Started HTTP server on port 4622

The Appium4Mac was not this PR's scope. You changed the port by yourself in appium/appium-for-mac#79 as port 50369.

@sankalphirke
Copy link

@KazuCocoa :- the main issue still remains, Mac driver is not able to establish connection with AppiumforMac server as they are not listening to same port.
I could make AppiumforMac to run on any open port, but i still need that port to get assigned to appium for mac driver.
In previous attempts I tried to capture the running port of AppiumforMac application and assign it to MacDriver and it failed to capture it for current session .
Would it be possible tonmake this driver to listen to the port on which AppiumforMac is running and connect?

@KazuCocoa
Copy link
Member Author

Would it be possible tonmake this driver to listen to the port on which AppiumforMac is running and connect?

Ah... do you expect MacDriver will detect the port used by AppiumforMac inside this driver?

MacDriver expects users to set communication port properly as capabilities by themselves like other Appium's drivers.

So, for example:

@sankalphirke
Copy link

Both look absolutely right(literally was looking for this,thank you!!!), so in this way AppiumforMac run on any port and driver get what port it is running and connect to that , same way in next round it will different port and hence parallel execution will be possible.(at least my idea of it, what are your thoughts?)
How did you achieve Appiumformac to run on that port? I changed AppiumForMacAppDelegate.m file and set self.afmHTTPServer setPort: value to 0 to run on any open port.

@KazuCocoa
Copy link
Member Author

I hardcoded the port in https://github.com/appium/appium-for-mac/blob/2356957dc73b6275262c918ca8f4184ef4a25af0/AppiumForMac/AppiumForMacAppDelegate.m#L36 and build the app.
You should find a way to set port from outside the app

@sankalphirke
Copy link

@KazuCocoa , would it be possible to do something with driver, or build multiple apps with specific port , like you did in second example? that way each app will be responsible for one session.
is that change available for users?

@KazuCocoa
Copy link
Member Author

build multiple apps with specific port

This way, for now since the a4mac app does not have dynamic listening port change feature.
You can run xcodebuild (Xcode 10.x) command in https://github.com/appium/appium-for-mac 's top directory. Then the app appears in build/Release/. You can put the app in /Applications for example and run it. You can rename the app. Then, a4mAppPath helps to set the app to launch.

@sankalphirke
Copy link

sankalphirke commented Jan 8, 2020

@KazuCocoa . Thanks for the updates, are these changes available to master? * a4mAppPath related changes.
Got it.. thanks. it think we can close this one then. This looks like to be the most feasible way of doing it.

@sankalphirke
Copy link

build multiple apps with specific port

This way, for now since the a4mac app does not have dynamic listening port change feature.
You can run xcodebuild (Xcode 10.x) command in https://github.com/appium/appium-for-mac 's top directory. Then the app appears in build/Release/. You can put the app in /Applications for example and run it. You can rename the app. Then, a4mAppPath helps to set the app to launch.

Appium old session will be killed by the new one or will different Appium4Mac application names wont kill anything which dont match?

@KazuCocoa
Copy link
Member Author

KazuCocoa commented Jan 8, 2020

ah, currently killAll is called to stop the a4MacApps which has the same application name.
Should tweak the logic.

a4mAppPath related change is in this branch.

| `a4mPort` | Specify the port to the app for mac application. Defaults to `4622` | e.g, `4622`, `8080` |
| `a4mAppPath` | Specify the path to the app for mac application. It helps to launch `AppiumForMac` application in a custom path. Defaults to `/Applications/AppiumForMac.app` | e.g, `/Applications/CustomAppiumForMac.app` |
| `killAllA4MAppBeforeStart` | Kill all running processes named `AppiumForMac` not to remain the process in next Appium session run. Please disable this value when you run multiple `AppiumForMac` on the machine. Defaults to `true` | `false`, `true` |
| `implicitTimeout` | | |
Copy link
Member Author

Choose a reason for hiding this comment

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

will update other capabilities after this PR

@@ -55,7 +59,7 @@ class AppiumForMac {
`signal ${signal}`;
log.error(msg);
});
log.info(`Spawning AppiumForMac with: ${this.appium4macdriver}`);
Copy link
Member Author

Choose a reason for hiding this comment

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

Anyone did not use this. appium4macdriver. So, the value was always undefined.

Copy link

@sankalphirke sankalphirke Jan 13, 2020

Choose a reason for hiding this comment

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

Why where we spawning? And is there a way we can close the app after test, i mean another capability to kill /close the app on OS/machine?

Copy link
Member Author

Choose a reason for hiding this comment

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

Handled the process by https://github.com/appium/node-teen_process/blob/56a139cbf86b819398d7736a442b6c4a985bc716/lib/subprocess.js#L23

The process will stop in delete the session in general.
https://github.com/appium/appium-mac-driver/blob/master/lib/driver.js#L58
So, the kill all process aims to make a new process run safer.

@KazuCocoa KazuCocoa changed the title [WIP] Make port/host name configurable Make port/host name configurable Jan 13, 2020
@KazuCocoa KazuCocoa requested a review from jlipps January 13, 2020 09:26
@KazuCocoa KazuCocoa changed the title Make port/host name configurable feat: Allow to configure host/port/app path for Appium for mac app in appium-mac-driver Jan 14, 2020
@KazuCocoa KazuCocoa merged commit d74eaf7 into appium:master Jan 19, 2020
@KazuCocoa KazuCocoa deleted the make-port-configuable branch January 19, 2020 03:38
|----------|-----------|------|
| `AppiumForMac` | Specify the host name to the app for mac application. Defaults to `127.0.0.1` | e.g., `localhost` |
| `a4mPort` | Specify the port to the app for mac application. Defaults to `4622` | e.g, `4622`, `8080` |
| `a4mAppPath` | Specify the path to the app for mac application. It helps to launch `AppiumForMac` application in a custom path. Defaults to `/Applications/AppiumForMac.app` | e.g, `/Applications/CustomAppiumForMac.app` |
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be smarter to find the app by its bundle id using searchd automatically if this cap is not set: https://apple.stackexchange.com/questions/115947/locating-an-app-by-its-bundle-identifier-from-the-command-line

| `AppiumForMac` | Specify the host name to the app for mac application. Defaults to `127.0.0.1` | e.g., `localhost` |
| `a4mPort` | Specify the port to the app for mac application. Defaults to `4622` | e.g, `4622`, `8080` |
| `a4mAppPath` | Specify the path to the app for mac application. It helps to launch `AppiumForMac` application in a custom path. Defaults to `/Applications/AppiumForMac.app` | e.g, `/Applications/CustomAppiumForMac.app` |
| `killAllA4MAppBeforeStart` | Kill all running processes named `AppiumForMac` not to remain the process in next Appium session run. Please disable this value when you run multiple `AppiumForMac` on the machine. Defaults to `true` | `false`, `true` |
Copy link
Contributor

Choose a reason for hiding this comment

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

we would need some separate tutorial on how to run parallel a4m sessions

You can launch multiple `AppiumForMac` on a same machine to run tests in parallel.
Please consider to set `a4mPort`, `a4mAppPath` and `killAllA4MAppBeforeStart` as their capabilities to handle multiple Appium sessions on the machine.
You must modify [the port number in appium-for-mac](https://github.com/appium/appium-for-mac/blob/2356957dc73b6275262c918ca8f4184ef4a25af0/AppiumForMac/AppiumForMacAppDelegate.m#L36) and build the app to coordinate the port number on `AppiumForMac`. Appium-mac-driver tries to establish a session to the host/port referencing `a4mPort` and `a4mAppPath`.
Do not forget to handle your test scenarios properly not to conflict each other since the scenarios runs on the machine.
Copy link
Contributor

Choose a reason for hiding this comment

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

on the same machine

Copy link
Contributor

Choose a reason for hiding this comment

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

the scenario runs or scenarios run

if (!await fs.exists(REQ_A4M_APP_PATH)) {
throw new Error('Could not verify AppiumForMacDriver install; please install to your /Applications folder');
if (!await fs.exists(this.a4mAppPath)) {
throw new Error(`Could not verify AppiumForMacDriver install in ${this.a4mAppPath}; please install it to ${this.a4mAppPath}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

it is a good practice to put variable values in quotes, so people could easily extract them if they contain spaces

Copy link
Contributor

Choose a reason for hiding this comment

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

same below

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

Successfully merging this pull request may close these issues.

None yet

3 participants