A CGI Script to Launch QTP Tests
Friday, September 29th, 2006This 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.

