In this use case, I want to simulate a user testing a website and i want to do this using selenium grid and selenium node. The basic approach is to write a selenium script at the grid server for testing my website and make the nodes walk these tests. There is one problem though, the Selenium Node needs a jar file to be running in the context of a user in a windows node. This may seem as a one time manual task, but somehow i found it difficult to allow a jar file running forever in my windows nodes for a long time as a concern that it could hog my test systems extremely precious memory and CPU or if my previous test was abrupt had un handled exception cases that could corrupt my next run and requires sanitation.
So here is how i managed to control this requirement.
Step 1: Getting a Remote Handle on a Windows Controller (Telnet service!, very insecure). Running telnet server on windows 7.
- Never run telnet in your Production environment, it not secure and is an easy backdoor. Having said that, my tests are just experiments. So i preferred enabling telnet as it is a windows system defaults free feature. To enable this on a windows 7 machine, navigate to
- 1. Control Panel > Programs > Turn On/Off Windows Features and then select and start the Telnet Server.
This however only installs the service and we will need to ensure that the service is running. So start run -> Services.msc -> Telnet Server -> Start Automatically.
Now that this is done, Telnet will still be restricted for logon. Windows is trying to protect you :), you will need to explicitly add a specific user that you need to test within the Group allocated for Telnet Users. Start -> Right Click on “My Computer” -> Manage -> Local Users and Groups -> Groups -> TelnetClients -> Add User and add your user with which you will use to login remotely via Telnet.
Validate that now telnet is up and running which is accessible on your client machine by running this command on the windows 7 machine -> netstat -ano | find “:23” You should see something like “0.0.0.0:23” in LISTENING State. Now you can log into a windows machine via a Linux machine using telnet.
Step 2: Preparing a Windows Service! for running the java jar file on demand.
We will next create a script with *.bat extension. it is easy as these are just the same commands that one would type on the command prompt. Please make sure you have the selenium jar file in the same folder as the commands included in the bat script file.
Note: I’m purposely including “VERSION=RAMNATH” to identify my windows node, so that my grid server can identify my specific windows client using the desired capability “version”.
Now that this is done, if we need to execute this bat file on demand. It can only be done using a task with appropriate windows rights. To create a windows task we need to do the following,
- Start -> Run -> “Task”, Right click on “Task Scheduler”
- Create a Basic Task , add Name and description as it fits your requirement. -> Next
- Trigger -> “When the computer Starts”
- What Action to perform -> “Start a program”
- Path of Program/Script -> C:\SecretAgent.bat & start in -> C:\
- Next and Finish
This will ensure that the Task is ready. However you will need to modify some rights so that this functions correctly. Hence, click on Task Schedule again -> Click on the task that is now added and change the General Setting to “Run whether user is logged on or not” and “Run with highest privileges”. Additionally, verify that this task can also be run on-demand. This will ensure that now you can start a task via telnet remotely from your test controller.
So from a Linux Terminal we can now start or stop this service on demand. Which Actually connects your selenium node to selenium hub on demand & java to run on demand.
In the grid now you have the node ready to simulate user.