Jenkins setup for executing Windows Forms automated tests

 

Introduction

 

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:

 

Creating Jenkins slave

 

After clicking on Manage Nodes link, you will be navigated to Jenkins nodes configuration:

 

Jenkins nodes configuration

 

In order to create new slave node, click on New Node link:

 

Creating new slave node

 

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:

 

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:

 

Manage Node page

 

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.

 

Agent Slave page

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:

 

executing command javaws

 

After executing the command, pop-up will appear indicating that Jenkins slave is connected:

 

A pop-up indicating that Jenkins slave is connected

 

Navigate to Jenkins on Agent page. Status should be changed to online as on the screenshot below.

 

Change of status as online

 

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

 

Extract files in particular location on the machine where tests will be executed and then register AutoIt

 

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.

 

Sample code that will perform mouse movements

 

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).

 

Go to Jenkins and click on “New Item”, select “Freestyle project”, enter name for project

 

Click on the “OK” button. Job configuration page should be displayed.

 

job configuration page

 

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 “General” section select checkbox “Restrict where this project can be run” and in the “Label Expression” text box enter “GUI_Tests”

 

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.

 

Build triggers section

 

In the “Build” section click on dropdown button and select “Execute Windows batch command”.

 

Select “Execute Windows batch command”

 

In text field enter path to the Visual Basic script, saved on location D:\MouseMove.vbs in this example.

 

Enter path to the Visual Basic script

 

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:

 

Jobs configuration on the Jenkins Slave, labeled as “GUI_Tests” that will execute “keep alive” job and main job for running Windows Forms test