Testing Applications in Multiple UI Sessions on a Single Machine

To test applications in multiple UI sessions on a single machine or to test multiple agents on a single machine, connect to multiple Open Agent instances on the machine. Every agent runs in its own UI-session. A UI session can be a Remote Desktop Protocol (RDP) connection or a Citrix-based connection.

  1. Create the UI sessions.
  2. Open a command line window.
  3. Navigate to the folder /ng/agent in the Silk Test installation directory. For example, the default folder path might look like the following: C:\Program Files (x86)\Silk\SilkTest\ng\agent.
  4. In each UI session, execute the following command: openAgent.exe -infoServicePort=<port> -infoServiceSecurePort=<securePort>.
    Note: Use unique port numbers, because these ports will be used in your Silk4NET script to identify the Open Agent and the UI session in which the agent is running. The port set with the infoServicePort option will be used for unencrypted HTTP communication between the Open Agent and the Information Service, and the port set with the infoServiceSecurePort option will be used for encrypted HTTPS communication.
  5. Change your Silk4NET scripts to connect to the Open Agent instances. To connect to an Open Agent instance, add the following line to the script:
    // VB .NET code
    Private agent As RemoteAgent = Agent.Connect("hostname:port")
    // C# code
    private RemoteAgent agent = Agent.Connect("hostname:port");
    Where hostname is the name of the machine on which the agent is running, and port is the unique port that you have specified, which can be either the HTTP or the HTTPS port.
The resulting objects are independent of each other and can be used either in one thread or in multiple threads.
Note: If you want to launch an application in multiple UI sessions, you have to execute the base state for each UI session.
The following classes include overloaded methods for multi-agent or multi-session testing:
  • Agent
  • BaseState
  • BrowserBaseState
  • Clipboard
  • ConsoleWindow
  • Desktop
  • DllCall
Note: To use TrueLog when testing applications in multiple UI sessions on a remote machine, you need to manually copy any generated TrueLog files from the remote machine to your local machine.

Example

Assume that the server machine that is hosting the UI sessions is named ui-srv. You can create three UI sessions by using the ports 22903/48563, 22904/48564, and 22905/48565.

In the first session, open the command line window, navigate to the agent directory, and type the following:
openAgent.exe -infoServicePort=22903 -infoServiceSecurePort=48563

Do the same for the other two sessions with the respective ports 22904/48564 and 22905/48565.

To connect to the Open Agent instances, add the following code to your script:
// VB .NET code
Private agent1 As RemoteAgent = Agent.Connect("ui-srv:22903") ' or 48563 for secure HTTPS communication
Private agent2 As RemoteAgent = Agent.Connect("ui-srv:22904") ' or 48564 for secure HTTPS communication
Private agent3 As RemoteAgent = Agent.Connect("ui-srv:22905") ' or 48565 for secure HTTPS communication
// C# code
private RemoteAgent agent1 = Agent.Connect("ui-srv:22903"); // or 48563 for secure HTTPS communication
private RemoteAgent agent2 = Agent.Connect("ui-srv:22904"); // or 48564 for secure HTTPS communication
private RemoteAgent agent3 = Agent.Connect("ui-srv:22905"); // or 48565 for secure HTTPS communication
The following sample script prints a simple text to each of the three UI sessions:
// VB .NET code
<SilkTestClass()> Public Class TestMultiSession

  Private agent1 As RemoteAgent = Agent.Connect("ui-srv:22903")
  Private agent2 As RemoteAgent = Agent.Connect("ui-srv:22904")
  Private agent3 As RemoteAgent = Agent.Connect("ui-srv:22905")

  <TestMethod()> Public Sub Test()
    Dim d1 As Desktop = agent1.Desktop
    Dim d2 As Desktop = agent2.Desktop
    Dim d3 As Desktop = agent3.Desktop

    Dim baseState = New BaseState()
    agent1.ExecuteBaseState(baseState)
    agent2.ExecuteBaseState(baseState)
    agent3.ExecuteBaseState(baseState)

    d1.Window("@caption='My Application'").TypeKeys("Hello to session 1!")
    d2.Window("@caption='My Application'").TypeKeys("Hello to session 2!")
    d3.Window("@caption='My Application'").TypeKeys("Hello to session 3!")
  End Sub
End Class
// C# code
[SilkTestClass]
  public class TestMultiSession {

    private RemoteAgent agent1 = Agent.Connect("ui-srv:22903");
    private RemoteAgent agent2 = Agent.Connect("ui-srv:22904");
    private RemoteAgent agent3 = Agent.Connect("ui-srv:22905");

    [TestMethod]
    public void Test() {
      Desktop d1 = agent1.Desktop;
      Desktop d2 = agent2.Desktop;
      Desktop d3 = agent3.Desktop;
      
      BaseState basestate = new BaseState();
      agent1.ExecuteBaseState(basestate);
      agent2.ExecuteBaseState(basestate);
      agent3.ExecuteBaseState(basestate);
      
      d1.Window("@caption='My Application'").TypeKeys("Hello to session 1!");
      d2.Window("@caption='My Application'").TypeKeys("Hello to session 2!");
      d3.Window("@caption='My Application'").TypeKeys("Hello to session 3!");
    }
  }