@suroit
I am not sure what script you mean, but i will try to answer.
If you have two Nodes AND you need to run your tests on two different machines. (for example - you have connected devices on Mac1, and another on Mac2).
What are your steps then?
1. You need to run a Grid Server on any machine.
2. You need to run command to start two nodes for Mac1 and Mac2.
- First Node will have an IP address of Mac1 and a port were the appium will start working.
- Second Node will have an IP address of Mac2 and a port were the appium of that machine will start.
(in the main document i have sent in step 3 we run both nodes on the same machine with local-127.0.0.1 IP. For your case it will be Mac1 Ip address and Mac2 ip address accordingly).
3. You need then to start an appium on Mac1 and Mac2 with the same port that you mentioned for each machine on each node.
4. And you may already have mentioned the tests in testng.xml document describing which test script will run on which device.
Now the key point.
When you instantiate the driver you give some Version value and deviceId value.
It is mandatory for versions to be different. Why? Selenium Grid need to know to which Node it needs to stream the current script. This is done by three values "browserName", "platform" and "version". The combination of these three SHOULD BE UNIQUE. As for appium node you must leave blank the "browserName" value and the "platform" value for both is "MAC" it is mandatory to set different "version" values to somehow keep the Node uniqueness.
Before each test (BeforeTest annotation) you instantiate a driver/device. Now, when you instantiate the driver defore each test, along with the deviceId you need to send the "version" so the Grid knows on which Node to run this current test.
Summarizing overall:
The code does the following in general:
1. Reads testng.xml file. Takes deviceId parameter. It will run the tests under this parameter on the mentioned device.
2. Instantiate appropriate driver. In the capabilities along with device1 you mentioned version1 then it will know that it should invoke node1 that is Mac1 machine correspondingly.
3. And send the tests related to this device (in fact node version) to this machine.