如何将RobotFramework中case的执行结果上传到TestLink中。
公司的需求是: 用RobotFrameworjk框架执行case,用Testlink管理case和测试任务。需要持续统计每个版本的测试结果。
我觉得用Jenkins+Robot也行,Testlink+Robot也行。Testlink的优势就是可以管理case,分配测试任务。感觉如果要是能将Jenkins+Testlink+Robot整合到一起就完美了。
OK,其实将Robot的测试结果传到Testlink上也比较简单,找对接口就行,但是关键的就是,接口找不对...
Testlink的api模板我是没试成功。还有TCID(testcase ID),TPID(testplan ID)网上也没说怎么取。这里就详细的说下。
1. 下载安装TestLink-API-Python-client-0.6.1.zip,这个是别人封装好的接口。这个可以work...2. 自己先写个测试程序看看能不能连通Testlink(具体的TCID,TPID的查看在代码的说明中):
# -*- coding:utf-8 -*- #! /usr/bin/python import testlink import os os.environ['TESTLINK_API_PYTHON_SERVER_URL'] = "http://yourtestlinkurl.com/lib/api/xmlrpc/v1/xmlrpc.php" os.environ['TESTLINK_API_PYTHON_DEVKEY'] = "7776ad82392bfb213c5985508694a688" class FillResult(): def FillResultToTestLink(self,testcaseid, testplanid, buildname, result, note, user, platformid='0' ): self.testcaseid = testcaseid self.testplanid = testplanid self.buildname = buildname self.result = result self.note = note self.user = user self.platformid = platformid tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient) print self.testcaseid, self.testplanid, self.buildname, self.result, self.note, self.user, self.platformid tls.reportTCResult(testcaseid=self.testcaseid, testplanid=self.testplanid, buildname=self.buildname, status=self.result, notes=self.note) """ 1. TestCaseID could check via the exported TestList XML file. e.p: <testcase internalid="43" name="通过get方式访问网页,参数中包含permit关键字"> The TestCaseID is 43. 2. TestPlanID need to find in TestLink Database. Step: [root@localhost ~]# mysql -uxxxxx -pxxxxxxxx mysql> use testlink mysql> select * from testplans; +-----+----------------+-------+--------+---------+-----------+------------------------------------------------------------------+ | id | testproject_id | notes | active | is_open | is_public | api_key | +-----+----------------+-------+--------+---------+-----------+------------------------------------------------------------------+ | 76 | 1 | | 1 | 1 | 1 | 07df3b4860ffbdc1577a669255541bc6578c90f581f0275ce5f3b27109521366 | | 176 | 1 | | 0 | 1 | 0 | a01dbdbabd22c51b453e3c2eef1cb5f884f80bbd0afe3dde745373a6920f8bfb | +-----+----------------+-------+--------+---------+-----------+------------------------------------------------------------------+ 2 rows in set (0.00 sec) The Test PlanID is 76. 3. PlatFormID may be set to 0. 4. BuildName is the name defined in TestLink. 5. Result 'p' means 'Passed'; 'f' means 'Failed'. 6. Note will set in TestLink result description. 7. User is who execute this case. """ if __name__ == "__main__": a = FillResult() a.FillResultToTestLink(testcaseid='43', testplanid='76', buildname='执行1.0', result='f', note='some notes',user='bonjov1', platformid='0')
3. 执行完后,在Testlink中查看相应的case结果,应该是pass或者是fail。
4. 找我写的来,应该没有问题,可以work的。
5. 然后在RobotFramework中写一下在执行完case后将结果上传到Testlink中:
a)首先需要设置下开关,在执行正式测试任务是才会把结果上传到Testlink中,平时调试脚本时不需要上传case测试结果。
我是在总的Project下设置个全局变量“${debug}”,在执行正式测试任务时更改这个变量就行了。
b) 创建Testlink的关键字:testplanid, buildname, tester, 因为这些个变量比较固定,写在外面感觉就可以。
c) 创建Teardown关键字:
比如我这个Teardown是在执行完case后,退出FTP session:
Logout FTP log nonononon Run Keyword If Test Passed Fill Pass Result in TestLink Run Keyword If Test Failed Fill Fail Result in TestLink Fill Pass Result in TestLink Run Keyword IF ${debug}==1 Pass Execution Case: ${caseid} Finished ... ELSE FillResultToTestLink testcaseid=${caseid} testplanid=${testplanid} buildname=${buildname} result=p ... note='' user=${tester} Fill Fail Result in TestLink Run Keyword IF ${debug}==1 Pass Execution Case: ${caseid} Finished ... ELSE FillResultToTestLink testcaseid=${caseid} testplanid=${testplanid} buildname=${buildname} result=f ... note='' user=${tester}
d)如果你写的参数都正确的话,应该就会自动的将测试结果传到Testlink上了。