While configuring Jenkins for running web automated tests on both Windows and Linux installations is quite simple, configuring Jenkins for automated execution of Windows Forms automated tests requires additional configurations as well as â€śhelperâ€ť jobs that will keep login session live, so tests can be scheduled and executed without any human intervention.
On Windows OS, the installation of Jenkins is almost as standard as Windows Service, so it starts automatically without requiring a user to log in. However, when Jenkins is running as a windows service, GUI tests (either web or Windows Forms) canâ€™t be run on the Jenkins master and it will require configuration of Jenkins slave on which GUI tests will be executed.
Another problem for automatically ran Windows Forms tests on Jenkins is that those will require established active desktop session. However, in most situations a user session, after some time of inactivity, is disconnected on the machine where tests are ran. This lead to a problem of scheduling â€śnightly runsâ€ť of Windows Forms tests on Jenkins and their triggering without any user login before running the tests. In order to solve this problem, user session is kept alive by executing simple mouse movement test periodically.
In summary, in order to run Windows Forms test, efficiently using Jenkins:
- Tests need to be run on Jenkins slave
- There is a need of periodic tests that will keep desktop session alive
Below are described the configuration steps in details, that will enable running Windows Forms automated tests on Jenkins.
Configuring Jenkins Slave
Create Jenkins Slave
In order to create Jenkins Slave, from Home page, click on Manage Jenkins link. From displayed Manage Page, click on â€śManage Nodesâ€ť link:
After clicking on Manage Nodes link, you will be navigated to Jenkins nodes configuration:
In order to create new slave node, click on New Node link:
On the displayed form, enter the name of the slave node (in this case â€śSlaveâ€ť), select the â€śPermanent Agentâ€ť option and click on the OK button which should take you to a slave configuration page:
On Slave configuration node, populate fields as on the picture above. After clicking the Save button, you are navigated back to the â€śManage Nodeâ€ť page, where newly created Slave node is listed:
By clicking on Slave link, Agent Slave page is displayed, indicating that there is no connection to the slave node, since it is not started.
Start Jenkins Slave
As it can be seen on the above image, there are two options to start a Jenkins slave, and for the purpose of this article we have used the first option by starting the slave though the .jnlp file, i.e. executing command javaws http://localhost:8080/computer/Slave/slave-agent.jnlp at the command prompt:
After executing the command, pop-up will appear indicating that Jenkins slave is connected:
Navigate to Jenkins on Agent page. Status should be changed to online as on the screenshot below.
Keeping session alive on Windows test machine
Taking in consideration that in most Windows configurations there is a setup on OS level that disconnects user session after some time of inactivity, a problem that arises is how to trigger and run automated Windows Forms tests when no user is logged into the machine and there is no established active desktop session.
One possible solution for this problem is to create periodic Jenkins job that will execute simple actions like mouse movement or pressing some key, so it will keep desktop session alive. This can be implemented in multiple ways, however in this example we are using AutoIt in combination with VB script that perform mouse movement.
Configuration of AutoIt
Download â€śAutoItâ€ť from: https://www.AutoItscript.com/site/AutoIt/downloads/ as .zip installation files. Extract files in particular location, on the machine where tests will be executed and then register AutoIt (Note: Start command prompt with Administrative privileges):
If you are using â€śJava 32bitâ€ť, run following in the command: regsvr32.exe AutoItX3.dll
If you are using â€śJava 64bitâ€ť, run following in the command: regsvr32.exe AutoItX3_x64.dll
Create Visual Basic script that will perform mouse movements
To keep the session alive create Visual Basic Script that will perform mouse movements. Below is the sample code.
Save the above code in file with .vbs extension, for example: â€śMouseMove.vbsâ€ť.
Create Jenkins Job that will execute periodically keep alive Visual Basic script
The Jenkins job that will execute â€śkeep aliveâ€ť VB script for mouse movement should be configured on the configured Slave machine, where â€śmainâ€ť Windows Forms tests will be executed.
Go to Jenkins and click on â€śNew Itemâ€ť, select â€śFreestyle projectâ€ť, enter name for project ex. â€śKeep alive Jenkins VMâ€ť as it is displayed on the image below. (Note: In this example, Windows Forms tests are executed on the same machine where Jenkins is running).
Click on the â€śOKâ€ť button. Job configuration page should be displayed.
In the â€śGeneralâ€ť section select checkbox â€śRestrict where this project can be runâ€ť and in the â€śLabel Expressionâ€ť text box enter â€śGUI_Testsâ€ť i.e. the label name of Slave.
In the â€śBuild Triggersâ€ť section select â€śBuild periodicallyâ€ť checkbox, in the text box enter valueÂ Â Â Â Â Â Â H/3 * * * *. The build will be scheduled to run every 3 minutes.
In the â€śBuildâ€ť section click on dropdown button and select â€śExecute Windows batch commandâ€ť.
In text field enter path to the Visual Basic script, saved on location D:\MouseMove.vbs in this example.
Click on â€śSaveâ€ť button and job will be configured.
Finally, jobs configuration on the Jenkins Slave, labeled as â€śGUI_Testsâ€ť that will execute â€śkeep aliveâ€ť job and main job for running Windows Forms test should look like: