Aim:
To run the QTP/UFT script on any given test environment using Jenkins by passing the environment as a parameter to the QTP/UFT test.
Please read this post first to get a high level idea of basic QTP/UFT + Jenkins integration.
Creating Simple Test Script with Test Parameters:
- Create a simple QTP/UFT test script for your application
- Modify the QTP/UFT script to accept input parameters.
- In my test, I am going to pass 2 parameters
- env -> A short name of the Test Environment which QTP script has to test
- browser -> Browser to be used by QTP/UFT script to invoke and test
Using Property Files:
- Create a separate property files for each environment as shown below.
- This property file should contain the environment specific information like URL, username and password etc
- I am going to assume we have 4 environments in which we might run our test. Let them be qa1, qa2, uat and prod.
QTP/UFT Test Folder Structure:
Our QTP/UFT test will contain below folders at least.
- functions -> will contain all the vbs files
- properties -> will contain all the properties files
- qtpTestFolder -> this is your actual qtp test folder – the name can be anything
- runner.vbs -> this is a vbs file which uses QTP AOM to invoke QTP
Reading Property Files:
These properties will be stored as Environment Values of the QTP/UFT script. For that, We need to attach a separate vbs file which reads the property file to the QTP/UFT test.
- Lets create a ‘TestInitialize.vbs‘ to read the property file and convert them as Environment Variables.
- Attach this vbs file to the test.
- Now in your test you should be able to use all those variables present in the Property Files.
- Environment.Value(“APPLICATION_URL”) will return https://qa1.testsite.com
- Ensure that your test works fine by reading the property files.
Updating runner.vbs to accept arguments from command line:
We need a separate vbs file which uses QTP/UFT Automation Object Model to invoke QTP, open the test and run. I name the file as runner.vbs – it will be created as shown below to accept arguments from the command line.
At this point, you should be able to run your test through command line on any test environment as shown here.
QTP/UFT should invoke successfully and run the test on the given environment. Ensure that it works before integrating with Jenkins. [If it fails, executing through jenkins is not possible]
Jenkins – Creating a Job with Parameters:
- Create a simple freestyle job in jenkins
- Let the job accept parameters from the users.
- I need 2 parameters for my test. Environment and Browser
- Build step should be ‘Execute Windows Batch Command’
- Enter the command: CScript <path to the runner> %ENVIRONMENT% %BROWSER%
- Select any test environment and browser from the drop down and click on Build.
- We can see these values are being passed to the runner in the console and QTP/UFT executes the test in the corresponding environment and the browser.
Happy Testing & Subscribe 🙂