测试的时候经常需要使用一些方法都整理放在一起,方便调用

首先一些基本的配置引入

 localReadConfig = readConfig.ReadConfig()
proDir = readConfig.proDir
log = Log.get_log() caseNo = 0

根据xls_name和sheet_name来读取数据

 def get_xls(xls_name, sheet_name):
"""
get interface data from xls file
:param xls_name:
:param sheet_name:
:return:
"""
cls = []
# get xls file's path
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
# open xls file
file = xlrd.open_workbook(xls_path)
# get sheet by name
sheet = file.sheet_by_name(sheet_name)
# get one sheet's rows
nrows = sheet.nrows
for i in range(nrows):
if sheet.row_values(i)[0] != u'case_name':
cls.append(sheet.row_values(i))
return cls

将结果写入到excel中

 def write_result_into_xls(xls_path, sheet, wb, result, row, col):
sheet.write(row, col, result)
   wb.save(xls_path)
 def write_results_into_xls(xls_name, sheet_name, results, col):
xls_path = os.path.join(proDir, 'testFile', 'case', xls_name)
rb = xlrd.open_workbook(xls_path)
wb = copy.copy(rb)
sheet = wb.get_sheet(sheet_name)
for i in range(len(results)):
write_result_into_xls(xls_path, sheet, wb, results[i], i+1, col)

正则表达式匹配

 用import.re导入正则表达式模块
用re.complie()函数创建一个Regex对象(记得使用原始字符串)
向Regex对象的search()方法传入想查找的字符串。它返回一个Match对象
调用Macth对象的group()方法,返回实际匹配文本的字符串

python——一些常用的方法类的更多相关文章

  1. python字符串常用的方法解析

    这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> ...

  2. Python day8常用格式化format类2

    format常用格式化 tp1="i am {},age {},{}".format('LittlePage',18,'boy') tp2="i am {},age {} ...

  3. 解析python部分常用魔术方法

    def __add__(self, *args, **kwargs): # real signature unknown """ Return self+value. & ...

  4. python的常用魔法方法详细总结

    构造和初始化 __init__我们很熟悉了,它在对象初始化的时候调用,我们一般将它理解为"构造函数". 实际上, 当我们调用x = SomeClass()的时候调用,__init_ ...

  5. python 基础 ----- 常用的方法

    one.将英文字符设置大小写 upper()  :将英文字符设置大写 lower()   :将英文字符设置小写 two.去掉字符串的首尾空格    不能去除字符串中间的空格偶 strip() : 去掉 ...

  6. python selenium常用基本方法---H5和键盘鼠标操作

    一.模拟手机打开页面(H5测试) from selenium import webdriver mobile_emulation = {'deviceName':'iPhone X'} options ...

  7. Python字符串常用的方法——真心觉得比java,c好用

    # Strings have many methods wo can use rand_string=" life is a beautiful struggle " print( ...

  8. Python语言学习:列表常用的方法

    python 列表常用的方法 1.append( ):用于在列表末尾添加新的对象 list.appent(obj) #obj:添加到列表末尾的对象 #!/usr/bin/python aList = ...

  9. Python语言学习:字符串常用的方法

    python字符串常用的方法 1. find( ):在字符串中搜索指定的值并返回它被找到的位置,如果没有找到,则返回-1 string.find(value,start,end) #value:必需, ...

随机推荐

  1. JDBC(2)Statement

    Statement: 用于执行SQL语句的对象 通过Connection的createStatement()方法得到一个Statement对象 只有在获得了Statement对象之后才能执行SQL对象 ...

  2. sort论文和代码解读

    流程:1.detections和trackers用匈牙利算法进行匹配 2.把匹配中iou < 0.3的过滤成没匹配上的(1.2步共同返回匹配上的,没匹配上的trackers,没匹配上的detec ...

  3. Java之生成Pdf并对Pdf内容操作

    虽说网上有很多可以在线导出Pdf或者word或者转成png等格式的工具,但是我觉得还是得了解知道是怎么实现的.一来,在线免费转换工具,是有容量限制的,达到一定的容量时,是不能成功导出的;二来,业务需求 ...

  4. 学生会管理系统(SSM)vue+ssm+shiro

    数据库 drop database StudentUnionManagementSystem ; create database StudentUnionManagementSystem CHARAC ...

  5. [转]解決 IE10 瀏覽器無法使用 ASP.NET 表單驗證登入的問題

    今天凌晨在客戶端上線,當程式佈署到正式機後發現我們的網站唯獨只有 IE10 瀏覽器無法成功登入,任何其他瀏覽器版本或使用較低的 IE 版本都可以正常登入,使用 IE 相容性檢視也都可以正常登入,想說會 ...

  6. 每日笔记---使用@ConfigurationProperties读取yml配置

    每日笔记---使用@ConfigurationProperties读取yml配置 参考地址  https://www.cnblogs.com/mycs-home/p/8352140.html 1.添加 ...

  7. 【Linux资源管理】使用sar进行性能分析

    sar可用于监控Linux系统性能,帮助我们分析性能瓶颈.sar工具的使用方式为”sar [选项] intervar [count]”,其中interval为统计信息采样时间,count为采样次数. ...

  8. 【模板】BM算法(找线性规律万能模板)

    (1) n是指要找该数列的第n项. (2) 往vec中放入该数列前几项的值,越多越精确. #include<set> #include<cmath> #include<v ...

  9. mac Axure RP 8 授权码 以及汉化

    Koshy wTADPqxn3KChzJxLmUr5jTTitCgsfRkftQQ1yIG9HmK83MYSm7GPxLREGn+Ii6xY 汉化包 汉化包链接 密码: upri 汉化步骤 以Win7 ...

  10. springboot-redis缓存

    Redis缓存使用 1.  引入依赖(可能已经引入了):spring-boot-starter-cache 2.  在application.yml配置文件中配置spring:redis:host/p ...