Pytest UI自动化测试实战实例_ui自动化 账号密码验证码的测试用例

9 “”"
10 from openpyxl import load_workbook
11 from config.conf import excelPath
12
13
14 class ParseExcel(object):
15
16 def init(self):
17 self.wk = load_workbook(excelPath)
18 self.excelFile = excelPath
19
20 def getSheetByName(self, sheetName):
21 “”“获取sheet对象”“”
22 sheet = self.wk[sheetName]
23 return sheet
24
25 def getRowNum(self, sheet):
26 “”“获取有效数据的最大行号”“”
27 return sheet.max_row
28
29 def getColsNum(self, sheet):
30 “”“获取有效数据的最大列号”“”
31 return sheet.max_column
32
33 def getRowValues(self, sheet, rowNum):
34 “”“获取某一行的数据”“”
35 maxColsNum = self.getColsNum(sheet)
36 rowValues = []
37 for colsNum in range(1, maxColsNum + 1):
38 value = sheet.cell(rowNum, colsNum).value
39 if value is None:
40 value = ‘’
41 rowValues.append(value)
42 return tuple(rowValues)
43
44 def getColumnValues(self, sheet, columnNum):
45 “”“获取某一列的数据”“”
46 maxRowNum = self.getRowNum(sheet)
47 columnValues = []
48 for rowNum in range(2, maxRowNum + 1):
49 value = sheet.cell(rowNum, columnNum).value
50 if value is None:
51 value = ‘’
52 columnValues.append(value)
53 return tuple(columnValues)
54
55 def getValueOfCell(self, sheet, rowNum, columnNum):
56 “”“获取某一个单元格的数据”“”
57 value = sheet.cell(rowNum, columnNum).value
58 if value is None:
59 value = ‘’
60 return value
61
62 def getAllValuesOfSheet(self, sheet):
63 “”“获取某一个sheet页的所有测试数据,返回一个元祖组成的列表”“”
64 maxRowNum = self.getRowNum(sheet)
65 columnNum = self.getColsNum(sheet)
66 allValues = []
67 for row in range(2, maxRowNum + 1):
68 rowValues = []
69 for column in range(1, columnNum + 1):
70 value = sheet.cell(row, column).value
71 if value is None:
72 value = ‘’
73 rowValues.append(value)
74 allValues.append(tuple(rowValues))
75 return allValues
76
77
78 if name == ‘main’:
79 # excel = ParseExcel()
80 # sheet = excel.getSheetByName(‘login’)
81 # print(‘行号:’, excel.getRowNum(sheet))
82 # print(‘列号:’, excel.getColsNum(sheet))
83 #
84 # rowvalues = excel.getRowValues(sheet, 1)
85 # columnvalues = excel.getColumnValues(sheet, 2)
86 # valueofcell = excel.getValueOfCell(sheet, 1, 2)
87 # allvalues = excel.getAllValuesOfSheet(sheet)
88 #
89 # print(‘第{}行数据{}’.format(1, rowvalues))
90 # print(‘第{}列数据{}’.format(2, columnvalues))
91 # print(‘{}{}单元格的内容{}’.format(1, 2, valueofcell))
92 # print(‘login{}’.format(allvalues))
93
94 excel = ParseExcel()
95 sheet = excel.getSheetByName(‘mail’)
96 print(‘行号:’, excel.getRowNum(sheet))
97 print(‘列号:’, excel.getColsNum(sheet))
98
99 allvalues = excel.getAllValuesOfSheet(sheet)
100
101 print(‘sendmail{}’.format(allvalues))



1 “”"
2 ------------------------------------
3 @Time : 2019/4/18 10:54
4 @Auth : linux超
5 @File : parseConFile.py
6 @IDE : PyCharm
7 @Motto: Real warriors,dare to face the bleak warning,dare to face the incisive error!
8 ------------------------------------
9 “”"
10 import configparser
11 from config.conf import configDir
12
13
14 class ParseConFile(object):
15
16 def init(self):
17 self.file = configDir
18 self.conf = configparser.ConfigParser()
19 self.conf.read(self.file, encoding=‘utf-8’)
20
21 def getAllSections(self):
22 “”“获取所有的section,返回一个列表”“”
23 return self.conf.sections()
24
25 def getAllOptions(self, section):
26 “”“获取指定section下所有的option, 返回列表”“”
27 return self.conf.options(section)
28
29 def getLocatorsOrAccount(self, section, option):
30 “”“获取指定section, 指定option对应的数据, 返回元祖和字符串”“”
31 try:
32 locator = self.conf.get(section, option)
33 if (‘->’ in locator):
34 locator = tuple(locator.split(‘->’))
35 return locator
36 except configparser.NoOptionError as e:
37 print(‘error:’, e)
38 return ‘error: No option “{}” in section: “{}”’.format(option, section)
39
40 def getOptionValue(self, section):
41 “”“获取指定section下所有的option和对应的数据,返回字典”“”
42 value = dict(self.conf.items(section))
43 return value
44
45
46 if name == ‘main’:
47 cf = ParseConFile()
48 print(cf.getAllSections())
49 print(cf.getAllOptions(‘126LoginAccount’))
50 print(cf.getLocatorsOrAccount(‘126LoginAccount’, ‘username’))
51 print(cf.getOptionValue(‘126LoginAccount’))



1 [126LoginAccount];126邮箱正确的登录账号和密码;运行用例时请更换正确的用户名和密码
2 username=linuxxiaochao
3 password=xiaochao11520
4 [HomePageElements];126邮箱首页菜单栏元素
5 homePage=id->_mail_tabitem_0_3text
6 mailList=id->_mail_tabitem_1_4text
7 applicationCenter=id->_mail_tabitem_2_5text
8 inBox=id->_mail_tabitem_3_6text
9 [LoginPageElements];126邮箱登录页面的元素
10 frame=xpath->//div[@id=“loginDiv”]/iframe
11 username=xpath->//input[@name=“email”]
12 password=xpath->//input[@name=“password”]
13 loginBtn=xpath->//a[@id=“dologin”]
14 ferrorHead=xpath->//div[@class=“ferrorhead”]
15 [ContactPageElements];126邮箱添加联系人页面元素
16 new_contact=xpath->//span[text()=“新建联系人”]
17 name=id->input_N
18 mail=xpath->//div[@id=“iaddress_MAIL_wrap”]//input[@class=“nui-ipt-input”]
19 star=xpath->//span[@class=“nui-chk-text”]/preceding-sibling::span/b
20 phone=xpath->//div[@id=‘iaddress_TEL_wrap’]//input[@class=‘nui-ipt-input’]
21 comment=id->input_DETAIL
22 commit=xpath->//span[text()=‘确 定’]
23 tooltip=xpath->//span[text()=‘请正确填写邮件地址。’]
24 [SendMailPageElements];126邮箱发送邮件页面元素
25 writeMail=xpath->//div[@id=‘dvNavContainer’]//span[text()=‘写 信’]
26 addressee=xpath->//input[@aria-label=‘收件人地址输入框,请输入邮件地址,多人时地址请以分号隔开’]
27 subject=xpath->//input[contains(@id, ‘_subjectInput’)]
28 iframe=xpath->//iframe[@class=“APP-editor-iframe”]
29 text=xpath->/html/body
30 sendBtn=xpath->//header//span[text()=‘发送’]
31 expect=xpath->//h1[contains(@id,‘_succInfo’)]
32 uploadAttachment=xpath->//div[@title=“点击添加附件”]
33 delete=xpath->//a[text()=‘删除’]



新建excel文件,分3个sheet,分别为:login,contact,mail #每个sheet中数据可自行填写,驱动测试用例执行不同的数据进行测试

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值