设为首页 收藏本站
查看: 698|回复: 0

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

[复制链接]

尚未签到

发表于 2017-4-12 10:44:42 | 显示全部楼层 |阅读模式
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.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-363816-1-1.html 上篇帖子: PHP 数组元素值为NULL 与isset的坑 下篇帖子: php json_encode不支持gbk gb2312编码的处理方法
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表