A CGI Script to Launch QTP Tests
This script is tightly coupled with the QTP.pm module in a previous post.
Note that the action refers to "ExecQTPTest.plx". I'm using the PLX extension because that's how you get IIS to use the Perl DLL instead of the executable. For some vague reason I've had a ton of trouble using the executable--I believe it has to do with Win32::OLE. It ends up executing the QTP code twice through, and I just don't know why. After much tinkering, I found the PLX solution and it seems to work much better.
Like I said before, I don't know of any reason you couldn't use Apache as your web server, but I haven't actually tested it.
There are a couple pieces of information missing from here: what is the big textarea called "XML"? How does the stylesheet get passed in? What's all this XSLT nonsense?
The answers for some of these questions are already up, some others only drafted, but I've just got to face the fact that we have a lot of information to put out there, and it's a slow process to turn it from in-house slop-code to polished, ready-for-primetime Open Source software. Our apologies in advance for the inevitable delays...
We launch by pointing a web browser to this URL:
http://servername/qtp/ExecQTPTest.plx?testname=LoginTest&dest=outputDirectory/results.html&redirect_results=1
After the test is finished (give it a minute or two), the browser is redirected to the html output generated by QTP.pm.
-
use strict;
-
use QTP;
-
use FileHandle;
-
-
# PARAMS TO EXPECT
-
# SiteName - unique name of site to deploy
-
# testpath - path of the test to be run
-
# visible - whether or not to run QTP in "Visible" mode
-
-
my $results;
-
my $quick_results;
-
-
my $q = new CGI;
-
my $default_test = 'C:\dev\qtp\LoginTest';
-
my $test = $q->param('test');
-
my $redirect_results = $q->param('redirect_results');
-
my $stylesheet = $q->param('stylesheet');
-
my $args =
-
{
-
testpath => $test,
-
visible => $q->param('visible'),
-
};
-
-
my $xml = $q->param('xml');
-
if ($xml)
-
{
-
my $xml_file = 'QTP_Script.xml';
-
my $ofh = FileHandle->new(">$xml_file");
-
$ofh->close;
-
my $qtp = QTP->new($args);
-
$qtp->generate_new_test($xml_file);
-
}
-
-
if ($test)
-
{
-
my $qtp = QTP->new($args);
-
$qtp->run_test(Test => $test);
-
$quick_results = $qtp->{last_status};
-
-
my $file_identifier = $time_stamp[4] . $time_stamp[3] . 'a';
-
-
$results = $qtp->get_results($stylesheet, $file_identifier);
-
-
if ($redirect_results)
-
{
-
if ( -e $results )
-
{
-
exit;
-
}
-
}
-
}
-
-
print "<body bgcolor=#FFFFFF text=#000000 link=Blue " .
-
"vLink=MediumSpringGreen aLink=Purple>";
-
-
-
if (-e $results)
-
{
-
$q->br,
-
$q->a({-href=>$results,-target=>$results},
-
"View Results");
-
-
}
-
-
print <<HERE;
-
<form method=GET action="ExecQTPTest.plx">
-
<h3>Test</h3>
-
<input type=text name=test size=80 value=$default_test />
-
<!-- <input type=text name=starting_url size=80><p> -->
-
-
Stylesheet:
-
<select name=results_stylesheet>
-
<option value="C:\<path-to-QTP>\dat\PShort.xsl" selected>Short
-
<option value="C:\<path-to-QTP>\dat\PDetails.xsl">Details
-
<option value="C:\<path-to-QTP>\dat\PSelection.xsl">Selection
-
</select>
-
<input type=checkbox name=redirect_results value=1>Redirect to results<p>
-
-
<p>
-
<input type=submit value="Submit"> * <input type=reset>
-
<h3>XML:</h3>
-
<textarea name=xml rows=30 cols=100 value=$default_test></textarea>
-
</form>
-
HERE
-
There may be bugs in there, because I had to strip out some company-proprietary stuff, so let me know if you have problems.
By the way, this is a good solution for executing tests in a targeted, specific manner, but we only use this rarely nowadays. The new methodology involves a queueing system, test harness-independent test execution, web service result reporting, and dynamic QTP script generation. It's awesome, but it's not ready for public consumption yet.
Tags: QTP-API, QTP-Automation, QuickTest-Pro-API, Reporting, Software-Testing


June 15th, 2007 at 11:41 am
This is some excellent information, thank you alot!
Reply to Dan
January 23rd, 2008 at 6:59 am
simple but quality, thanks!
Reply to dik
March 17th, 2008 at 4:18 pm
Hello!
I think this try.
Reply to Floroskop
April 30th, 2008 at 10:05 am
Hi!
This is very cool. I’ve got all the dependencies running and my cgi scripts are running successfully from the command line. However, I can’t shake the following error:
Win32::OLE(0.1707) error 0×80004002: “No such interface supported”
The IIS anonymous user is an administrator…
How did you configure IIS to be able to launch QTP?
Reply to Martin
April 30th, 2008 at 11:06 am
I’ve not tried this via IIS before. We’re running this set of scripts in Apache, and only had to go through the usual httpd.conf file stuff.
Can you use any other cgi script to access any other OLE objects? Microsoft Word or the like?
Reply to Marcus Merrell
May 1st, 2008 at 1:19 pm
Thanks! I’ve moved to Apache and I can run the scripts when Apache is run in userland, not when it is installed as a service… When run as a service, I get the same error as with IIS.
Reply to Martin