PHP建立与Testlink的接口(Mark一下_还未验证_5/22)

We use compuware testpartner and Watir/Ruby for test automation, I created a common PHP page that can be called by either to update TL status.
It is a simple straight forward PHP file that accepts query string values to pass to the DB execution table.
(I am sure there is a better way to write this, but I am a PHP noob)

Copy the code below and save it as tlupdate.php off the the root testlink web dir.

You will need to know the Testplan ID of the TP you want to execute against.


The Test Case id of the test case the script validates.


If you navigate to this page without any option.. there are two sample links at the bottom that will build a sample Query String.

Assumptions --
-it will figure out the most current build number for the testplanid passed in.
-If no date/time is passed it will grab NOW from the hosting server.
-You will need to assign an tester ID: Just right click and select properties on the tester name in the admin section of testlink look for.. userid=
-In my scripts I have testplan set as a global variable or runtime parm.. set it once -- change when needed.
-you will need to know your DB connection information - replace it in the page below.


In our automated tests I wrote two routines.. one that builds a passed URL
and one that builds a failed URL with error text.
if a script passed I call the
TLPass(testcaseID,testplanID,notes)
which builds
ie.goto('http://qatestcase.frp.com/tlupdate.php?tc=[tcid]&tp=[testplan]&status=[p]&notes=[passed: Automation]'

TLFail(exception,testcaseID,testplanID)
-which builds
ie.goto('http://qatestcase.frp.com/tlupdate.php?tc=[tcid]&tp=[testplan]&status=[f]&notes=[exception message]'
TLFail is included in my standard error handling routine so when handle_error is called it is executed.

<?php
echo "<B>Required Values Passed</B> <br>";
echo "Status :".$_GET['status']."<br>";
echo "Test Case :".$_GET['tc']."<br>";
echo "Test Plan :".$_GET['testplan']."<br>";
echo "Time Stamp :".$_GET['tstamp']."<br>";
echo "Notes :".$_GET['notes']."<br>";


# Set Data Parms
$debug = 0;
$tester = '7';
$testplanid = $_GET['testplan'];
$status = $_GET['status'];
$tstamp = $_GET['tstamp'];
$notes = $_GET['notes'];
$time = time();
$exectime = date('Y-m-d h:m:s');
$dbname = 'testlink170';

#Build Query
$tcidquery = "SELECT tcversion_id FROM testplan_tcversions where testplan_id = ".$testplanid." and tcversion_id in (select id from nodes_hierarchy where parent_id = ".$_GET['tc']." order by id desc)";
#$tcidquery = "select id from nodes_hierarchy where parent_id = ".$_GET['tc']." order by id desc";
$buildidquery = "select id from Builds where testplan_id = ".$testplanid." order by id desc";

echo "<hr><p><b>Connect to DB</b><br>";
$link = mysql_connect('localhost', 'yourusername', 'yourpass');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db($dbname);
echo "<hr><p><b>Get the Current TCversionID for Test Case</b><br>";
$tcresult = mysql_query($tcidquery);
$get = mysql_fetch_row($tcresult);
$tcid = $get[0];

print "<br> Returned Test Case Version ID: <B>".$tcid."</B><br>";

echo "<hr><p><b>Get most current Build ID for Testplan</b><br>";
$result = mysql_query($buildidquery);
$get1 = mysql_fetch_row($result);
$buildid = $get1[0];
print "<br> Using Buid ID".$buildid." for Testplan:".$testplanid;

#loop to display other choices
print "<p> Other Choices available (older builds):";
while ($row = mysql_fetch_assoc($result)) {
$out = $row['id'];
print "<br>TestPlan: ".$testplanid." Available Older Build: ".$out;
}


echo "<hr><p><B>Parm to pass to update</B>";
if ($tstamp == ''){
print '<p><B><I>NO DATE PASSED USING SERVER TIME</I></B>';
$tstamp = $exectime;
}

?>

<p>
<ul>
<li>TestPlan: <B><?php echo $testplanid; ?></B>
<li>Build: <B><?php echo $buildid; ?></B>
<li>TCversion: <B><?php echo $tcid; ?></B>
<li>Status: <B><?php echo $status; ?></B>
<li>TestUser: <B><?php echo $tester; ?></B>
<li>Date: <B><?php echo $tstamp; ?></B>
<li>ServerTime: <B><?php echo $exectime; ?></B>
<li>Notes: <B><?php echo $notes; ?></B>
</ul>

<hr><p><B>TESTLINK:</B>
<p>
<a href = "https://dev-4/testlink17/testlink.php?testplan=1095&tc=604&status=p&tstamp=2007-12-06 12:15:30&notes=This is a sample with passing"> Test Link: (Pass with date)<a> Will build a sample url string with all required parms
<p><a href = "https://dev-4/testlink17/testlink.php?testplan=1095&tc=604&status=f&notes=This is a sample FAIL: TestCase 2559 - Validation of Save Text Failed: Line 323"> Test Link:( Fail without date-user server date) <a> Will build a sample url string failing with no date passed in. Exp: user server date for timestamp.


<hr><p><B>Update Query:</B>
<p>
<?php
$updatequery = "INSERT INTO executions(build_id,tester_id,status,testplan_id,tcversion_id,execution_ts,notes) VALUES('".$buildid."','".$tester."','".$status."','".$testplanid."','".$tcid."','".$tstamp."','".$notes."')";
echo $updatequery;


if ($debug == 0){
mysql_db_query($dbname, $updatequery) or die("<BR><B>Failed Update Query of </B>" . $updatequery);
echo "<P><B>Update Complete!</B>";
}else echo "<P><B>DEBUG ON - NO UPDATE RUN!</B>";
mysql_close($link);
?>shaw557
TestLink user

Posts: 6
Joined: Thu Aug 02, 2007 1:44 pm
YIMTop
--------------------------------------------------------------------------------

by havlatm » Fri Dec 21, 2007 12:28 am

I would like to announce, that the next version (1. will have xml/rpc interface to add results from automated tools more easily.
You can download the latest CVS code to try it.

Anyway, thank you for the contribution.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值