from HTMLTestRunner import HTMLTestRunner
import os
import time
import unittest
from ddt import ddt, data, unpack
from selenium import webdriver
import openpyxl
def read():
workbook = openpyxl.load_workbook('工作簿1.xlsx')
table = workbook['Sheet1']
zz = table.max_row
xx = table.max_column
alis = []
for i in range(1, zz + 1):
lis = []
for j in range(1, xx + 1):
lis.append(table.cell(i, j).value)
alis.append(lis)
return alis
@ddt
class Application(unittest.TestCase):
@data(*read())
@unpack
def test01_app(self, id, name, passwd):
print(id, name, passwd)
self.id = id
self.name = name
self.passwd = passwd
a = webdriver.Firefox()
a.get('https://mail.qq.com/')
a.switch_to.frame('login_frame')
a.find_element_by_id('u').send_keys(name)
a.find_element_by_id('p').send_keys(passwd)
a.find_element_by_id('login_button').click()
time.sleep(1)
a.quit()
def test02_app(self):
print('abc')
if name == 'main':
b = unittest.TestSuite()
b.addTest(Application('test01_app'))
file = open(os.getcwd() + '/report.html', 'wb')
c = HTMLTestRunner(stream=file, verbosity=2, title='我的表格', description='报告如下:')
c.run(b)
1 admin 123456
2 admin 123456
3 123456 123456
上面这个是xlsx表格,名字叫:工作簿1.xlsx