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: