This article outlines the integration of HP’s QTP (now it is called UFT) & Jenkins. This article provides the details in a very high level. I might not be able to cover all the benefits we could get, by integrating UFT with Jenkins, in this article. So, I have created separate posts in this site to provide more information for you and added links in this post. So, Please check out all the posts to get the detailed idea of UFT-Jenkins integration.
What is Jenkins?
While developing a software, developers might check-in their code very often a day (at least once). This integration should be verified (using build tools, unit & integration tests) to ensure that software is not broken/developers do not introduce any defect. This process is called Continuous Integration & It is development practice to detect these code integration related issues as early as possible in the software development life cycle. Jenkins is a Continuous Integration tool which does this verification periodically or whenever the developer pushes the code to the repository.
Have you ever used Windows Task Scheduler? For ex: If you need to backup a file daily @ 9PM / You need to delete some files periodically, You can come up with a batch file/VBScript to do these simple tasks. Then you can use Windows Scheduler to launch this script @ scheduled time (every hour/daily/weekly..etc). So that you do not need to invoke it manually.
Jenkins can act like this task scheduler which can pull the source code from your source code manager & do a specific task on it. Like compiling the source code, executing the scripts etc. Once the task is done, Jenkins can also archive the results, sending out an email to the team members.
Jenkins is a web based application, totally FREE & Open Source. Check this link to install.
Jenkins-QTP Setup:
- Automation engineers push their changes to the SVN/Git/ALM.
- Jenkins can trigger a test whenever a commit was made / periodically / manually by the user.
- Jenkins gets the latest code from the source control system, deploys it in the Slave machines.
- Jenkins executes the test in the Slave machines, archive the results.
- User can see the results in Jenkins directly.
To do the above setup, Lets do the following…
Creating a simple QTP script:
The very first step in this integration is to have a QTP script. Ensure that your QTP test script is working fine.
I have created a simple QTP script & uploaded in GitHub. You can use that as well. Please check here.
Creating a Simple runner file:
QTP can be automated programmatically using its COM interface. Using this COM interface we can launch QTP, run a test, store the results in a specific location etc. This COM library is registered in your machine when you install QTP.
I am creating a simple runner.vbs file as given below.
'Create QTP object Set QTP = CreateObject("QuickTest.Application") QTP.Launch QTP.Visible = TRUE 'Open QTP Test QTP.Open "QTP Test Path", TRUE 'Set the QTP test path 'Set Result location Set qtpResultsOpt = CreateObject("QuickTest.RunResultsOptions") qtpResultsOpt.ResultsLocation = "Result path" 'Set the results location 'Run QTP test QTP.Test.Run qtpResultsOpt 'Close QTP QTP.Test.Close QTP.Quit
- I save this as “runner.vbs” in this location “c:\workspace\qtp-jen\” in my machine.
- Open command prompt – Enter below command by updating the path for the runner.vbs.
CScript "c:\workspace\qtp-jen\runner.vbs"
Ensure that this runner.vbs works fine. It should launch QTP, runs the test and store the results in the specific location.
Creating a Jenkins job:
I assume you have installed Jenkins. If not, please check this link to install.
Create a simple freestyle job. I am naming this job as QTP_JOB
In Job details page, Add a build step as given below. It should be ‘Execute Windows Batch Command‘
Add the Batch Command. CScript ‘path of the runner’ [ CScript “c:\workspace\qtp-jen\runner.vbs” ]
It is basically the same command whatever you give in your command prompt to run the vbs file.
This should do to run the QTP test. (Jenkins can pull the QTP script from source code manager like ALM/SVN/Git etc. But I assume we have the script in the local machine. Our aim is just to run QTP script using Jenkins to see how it works. For version control system integration – please check here – Github / SVN integration for UFT scripts.
Running UFT Scripts:
Click on the Build Now to launch QTP & run the test. [Our aim here is to create a simple Jenkins job. We can also send parameters to the UFT scripts through Jenkins UI. Please check here – Passing Parameters to UFT test from Jenkins]
Archiving Test Results:
runner file can be updated to apply the xsl to covert the XML result to HTML. Once the result is created, Jenkins job we had created can be modified to archive the test results as given below. Files to archive should be relative path to the workspace. Under my workspace/project directory, I have my results in output folder in this file -> ‘TestResult.html ‘. It can be archived as shown here.
Jenkins will move the files to be archived to the Jenkins server and maintain it for future reference.
Sending Out Email with Test Results:
You can also send out test results in email to the entire team. Please check here for more details.
Remote Execution:
- To do remote execution, you need to have another machine in the same network with QTP installed.
- Follow this guide to connect the machine to the Jenkins master you had installed.
- Once the remote machine [Slave machine in Jenkins terms] is ready, Jenkins master can issue commands to the slave machines to do some tasks. [I have 16 machines connected to my Jenkins master]
- Update the QTP_JOB configuration.
- Click on Configure
- In the Jenkins job details page – ‘Restrict where this project can be run’ – Label expression should be the name of the slave you had given in the Jenkins.
- Lets assume you have the root directory set as ‘c:\jenkins‘ in the slave machine. The Job name we have created is ‘QTP_JOB’. Jenkins will execute this job by default under this location – ‘c:\jenkins\workspace\QTP_JOB‘ in the slave machine. [It can be overriden].
- Copy all your scripts to the slave machine manually to the location c:\jenkins\workspace\QTP_JOB. [that is runner.vbs is present in this location]
- ‘Windows Batch Command’ should be just ‘CScript runner.vbs’ as Jenkins will by default look for the executables under c:\jenkins\workspace\QTP_JOB.
- Click on Build in Jenkins.
- Jenkins will invoke the runner.vbs in the slave machine which in turn starts QTP & executes the script.
Great!! Now, you can just click on Build from Jenkins whenever you need to execute the script. Jenkins can take of the script execution remotely while you are busy doing something in your machine.
Note: Sometimes an existing QTP/IE/excel running process in the remote machine will affect new test we do. So update the runner file to kill all process first and start a fresh process. My runner.vbs is almost as shown here.
'To terminate all the processes in the machine Call KillProcess("UFT.exe") Call KillProcess("QtpAutomationAgent.exe") Call KillProcess("iexplore.exe") Call KillProcess("chrome.exe") Call KillProcess("firefox.exe") Call KillProcess("werfault.exe") 'Create QTP object Set QTP = CreateObject("QuickTest.Application") ConsoleOutput("Launching QTP Application") QTP.Launch QTP.Visible = TRUE 'Open QTP Test ConsoleOutput("Opening Test....") QTP.Open "QTP Test Path", TRUE 'Set the QTP test path 'Set Result location Set qtpResultsOpt = CreateObject("QuickTest.RunResultsOptions") qtpResultsOpt.ResultsLocation = "Result path" 'Set the results location 'Run QTP test ConsoleOutput("Starting to run....") QTP.Test.Run qtpResultsOpt 'Close QTP ConsoleOutput("Execution Completed Successfully!!!!!!!!!!") QTP.Test.Close ConsoleOutput("Terminating QTP....") QTP.Quit Sub KillProcess(ByVal ProcessName) On Error Resume Next Dim objWMIService : Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Dim colProcesses : Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='" & ProcessName & "'") ConsoleOutput("Terminating Process : " & ProcessName) For Each objProcess in colProcesses intTermProc = objProcess.Terminate Next On Error GoTo 0 End Sub Sub ConsoleOutput(ByVal MessageToBeDisplayed) WScript.StdOut.WriteLine Time() & " :: " & MessageToBeDisplayed End Sub
Version Control System:
We can not manually move all our scripts every time to the slave machines. So you can use VisualSVN server [It is FREE] as the source code repository. Jenkins can pull the latest code from the Subversion/Git/CVS/ALM etc & deploy it in the slave machines, execute the script for you.
Update the repository URL details under Source Code Management in the Jenkins Job [Ex: QTP_JOB].
- Check here for more details on using Source Code control system like GitHub.
Summary:
We saw a very basic jenkins-qtp setup.
We will be able to do many advanced things with qtp/uft-jenkins if we have a proper framework in place.
Example:
Running a set of tests in different browser or environment (like QA, DEV, PROD) using Jenkins. We can configure Jenkins to pass parameters to the QTP test as shown here.
Please check below posts to implement few process/productivity improvements in your organization/project.
- Passing Parameters to UFT test from Jenkins
- Github / SVN integration for UFT scripts
- Automated Smoke Test
- Continuous Regression Test
- Showing test execution progress in the Jenkins Console
Happy Testing 🙂