Problem:

There does not appear to be a native way of returning the port number in use when doing distributed testing.

Resolution:

Agent.GetOption(OPT_SET_TARGET_MACHINE will return both the IP address and the port number in use for the target machine. You will then need to parse the string to separate the port number. The following sample testcase illustrates how to do this:-

[-] testcase getPortNumber() appstate none
 [ ] string sPortNo=""
 [ ] integer i=0
 [ ]
 [ ] Agent.SetOption(OPT_SET_TARGET_MACHINE,"127.0.0.1:2965")
 [ ]
 [ ] // Get the ipaddress and port number
 [ ] sPortNo=Agent.GetOption(OPT_SET_TARGET_MACHINE)
 [ ] // Get the position of the colon separater
 [ ] i=StrPos(chr(58),sPortNo)
 [ ] // Read the port number
 [ ] sPortNo=Right(sPortNo,len(sPortNo)-i)
 [ ]
 [ ] print("Port number in use is: "+sPortNo)

The result is

[-] Testcase getPortNumber - Passed
 [ ] Port number in use is: 2965