测试学员,希望大家为我解惑,这代码困扰我一天了,谢!

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

from HTMLTestRunner import HTMLTestRunner
import os
import time
import unittest

import requests
from ddt import ddt, data, unpack
from selenium import webdriver
import openpyxl



def read(): # 读取 Excel 里的数据 通过对行 列进行遍历 得到所有数据
    workbook = openpyxl.load_workbook('swork.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):  # 继承自 unittest.TestCase
    @data(*read()) # ddt 的装饰器固定写法, 将 read方法里面返回的内容作为测试数据来执行 
    @unpack  # ddt 的装饰器固定写法,将 @data 里面返回的测试数据 进行分解,此处则是分解成id,name,passwd
    def test01_app(self, id, name, passwd):  # 测试用例
        print(id, name, passwd)
        self.id = id
        self.name = name
        self.passwd = passwd
        a = webdriver.Chrome()
        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()  # 多个测试用例放在一起 构成集合,就是TestSuite
    b.addTest(Application('test01_app'))  # 向测试集合内添加测试用例
    file = open(os.getcwd() + '/report.html', 'wb') # 打开一个用来保存报告的html文件
    # 实例 报告对象
    c = HTMLTestRunner.HTMLTestRunner(stream=file, verbosity=2, title='报告名称', description='报告如下:')
    # 运行测试用例
    c.run(b)