We often face issues while running automated test cases on a Virtual Machine (VM). It is mainly due to the slow responsiveness. Running the scripts on VM requires us to change the data into configuration file (Browser, Server, Username, and Password) every time we access the VM.

However, the situation might get worse, as you might have to spend a lot of time fixing small changes. If you are using Jenkins as a CI tool for scheduling execution, you can find a solution for changing the data into configuration file using Jenkins.

Solution

A proper research can help in finding a solution and overcoming the problem. The above discussed situation can be resolved by following the steps mentioned below.

1. Install ‘EnvInject’ plug-in in the Jenkins CI tool.

2. After installing ‘EnvInject’ plug-in, you will see ‘Inject environment variables’ option under ‘Add Build Step’.

3. Configure the plug-in with Jenkins job by clicking on ‘Inject environment variables’ option.

4. You will see two fields: ‘Properties File Path’ and ‘Properties Content’ field after adding ‘Inject environment variables’.

5. In ‘Properties File Path’ field, provide the path of the properties file, i.e. where it exists in the Automation project and in ‘Properties Content’ field, provide all the information that you want to change in the run time, as shown below.

In ‘Properties File Path’ field, provide the path of the properties file

6. Now, run the Jenkins’s job to set all the ‘Properties Content’ field data into environment variable of target Virtual machine temporarily.

7. Get the properties data from the System environment variables and update the properties file.  This can be done by configuring the build.xml file, as shown below.

Get the properties data from the System environment variables and update the properties file.

The above lines of code fetch the value of “BROWSER” from environment variable using “${env.BROWSER}” and update the value in the properties file. In this way you can update all properties value.

‘EnvInject’ plug-in avoids the need to update the properties file manually. You can install any CI tool and configure with your Jenkin’s job.

You might also like: How to Create Jenkins job for a Ranorex Test suite?