python使用TestLink-API-Python-client库对testLink操作——excel导入

依赖库:TestLink-API-Python-client,xlrd
通过pip安装: python3 -m pip install TestLink-API-Python-client (笔者本地有多个版本python,只有一个版本直接python就可以)
url: 替换自己的testLink地址 http://xx.xx.xx.xx:xxxx/testlink/lib/api/xmlrpc/v1/xmlrpc.php
key: 登录testLink后点击上方个人账号进入个人中心,新页面点击 '生成新的秘钥’获取

一、确定excel模板

1.查看TestLink-API-Python-client提供的创建用例方法
    def createTestCase(self, *argsPositional, **argsOptional):
        """ createTestCase: Create a test case
        positional args: testcasename, testsuiteid, testprojectid, authorlogin,
                         summary
        optional args : steps, preconditions, importance, executiontype, order,
                        internalid, checkduplicatedname, actiononduplicatedname,
                        status, estimatedexecduration
                        
        argument 'steps' will be set with values from .stepsList, 
        - when argsOptional does not include a 'steps' item
        - .stepsList can be filled before call via .initStep() and .appendStep()
        
        otherwise, optional arg 'steps' must be defined as a list with 
        dictionaries , example
            [{'step_number' : 1, 'actions' : "action A" , 
                'expected_results' : "result A", 'execution_type' : 0},
                 {'step_number' : 2, 'actions' : "action B" , 
                'expected_results' : "result B", 'execution_type' : 1},
                 {'step_number' : 3, 'actions' : "action C" , 
                'expected_results' : "result C", 'execution_type' : 0}]

        """ 
        
        # store current stepsList as argument 'steps', when argsOptional defines
        # no own 'steps' item
        if self.stepsList:
            if 'steps' in argsOptional:
                raise TLArgError('confusing createTestCase arguments - ' +
                                 '.stepsList and method args define steps')
            argsOptional['steps'] = self.stepsList
            self.stepsList = []
        return super(TestlinkAPIClient, self).createTestCase(*argsPositional, 
                                                             **argsOptional)

分析该方法:
①positional args:testcasename, testsuiteid, testprojectid, authorlogin,summary这些参数必填
其中testprojectid可以根据项目名去获取,testsuiteid也可以获取稍后讲获取方法(其中一种我自己写了一个递归函数来获取一个项目下所有的目录),所以我是将几个必要的参数写在了excel(testcasename,authorlogin,summary)
②optional args中都是可选参数,可以根据自己的项目组习惯或规范来使用

2.excel模板示例

导入testLink excel模板示例

二、读取excel

我是根据列名来获取用例对应的参数,所以列名必须严格按照模板来,列的位置可以随意调整
excel的sheet是默认读取了第一页即index[0]

def read_excel(file_path):
    """
    读取用例数据
    :return:
    """
    case_list = []
    case_list_dic = []
    try:
        book = xlrd.open_workbook(file_path)  # 打开excel
    except Exception as error:
        logger.error('路径不在或者excel不正确 : ' + str(error))
        return error
    else:
        sheet = book
  • 4
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值