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 🙂
All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates…
Regards Selenium training in chennai
Hi,
You have a nice blog here.
I have one question regarding this method. How does the runner.vbs select which test script to execute. I can see you have given the path for the test folder but it is unclear if it will run all tests within that folder? How or where does it choose which test to execute.
Many thanks
Ajay
My framework is little bit different – check this here – http://www.testautomationguru.com/hybrid-test-automation-framework/
If you have multiple tests, runner.vbs can be slightly modified to run all the tests.
Hey Great stuff, unfortunately I can’t make one piece work. Everything works except I cant read the passed in values in my QTP/UFT code. First, which of these below is SUPPOSED to work? ( I would guess TestArgs, but I tried all these.
1) msgbox “testargs env” &TestArgs(“env”)
2) msgbox “param(env) ” &Parameter(“env”) ‘ I tried this in Action0 and Action1
3) msgbox “env(env)= ” & Environment(“env”) ‘This is what LoadProperties is for, I know.
4) mjparam1= Services.GetEnvironmentAttribute(“env”) ‘I don’t know what this is, saw it somewhere, doesn’t work either.
msgbox mjparam1
Been fighting this 3 solid days. LoadProperties will create Environment vars, yay!. My runner.vbs script is getting the params passed into it.
Why would the values not make it into QTP?
Another way to state this is that it seems to just ignore the line:
qtpParams.Item(“env”).Value = LCase(WScript.Arguments.Item(0))
Item(0) has the value, but nowhere in QTP can I read that value.
Ideas?
Thanks,
Mark
I assume you have the properties set in the QTP/UFT. Comment all the ‘On error resume next’ statements & check. There is a chance that the error is just swallowed which prevents you from debugging.
I did comment out the Resume Next, there is no error.
One thing I am unclear about is WHERE to set the properties in QTP, so I set them everywhere I can think of.
1) what makes the most sense to me is: File > Settings >Parameters. I think if this is right, the value would be read with TestArgs(), right?
2) But the screenshot looks like the parameters are being set for an Action, I assume Action 0 or Action 1, so I also created the ‘env’ parameter for both of those. (In QTP: Edit > Action > Action Properties)
So I created the, ‘env’ parameter in all 3 places, with different default values for each. In QTP, I only get the default values returned, instead of what I attempted to pass in.
So:
1) msgbox “testargs env” &TestArgs(“env”)
–Displays, “mydefaultval”, but I wanted, “mypassedinval”
2) Likewise, msgbox “param(env) ” &Parameter(“env”) ‘ in Action0 and Action1 also display, “mydefaultval”, but I wanted, “mypassedinval”
So, in conclusion, as far as I can tell, the line that passes in the args just doesn’t work. Unless there is a DIFFERENT place I should be creating, ‘env’ and/or a different way I should be getting the passed in value? These details are not described in the instructions.
Identical behavior in QTP11 and in UFT 12.53
Why would this be?
Thanks,
Mark
Check this. This is how you need to create parameters. https://www.youtube.com/watch?v=CeQ9nEOU4eA If it still does not work, then upload the script somewhere. I will check
Glad that you made it work . I had uploaded updated script in github here – https://github.com/vinsguru/tag-qtp-jenkins-demo
Great post! I found this article a very informative. The information given in this article about QTP is very useful. Thanks for sharing such a wonderful information.. Great information on your site.Keep sharing such informative articles!!