@ddt.ddt
class FirstDdtCase(unittest.TestCase):
ex = ExcelUtil()
data = ex.get_data()
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.get(‘http://www.5itest.cn/register’)
self.login = RegisterBusiness(self.driver)
def tearDown(self):
time.sleep(2)
#if sys.exc_info()[0]:
for method_name,error in self._outcome.errors:
if error:
case_name = self._testMethodName
file_path = os.path.join(os.getcwd()+"/report/"+case_name+".png")
self.driver.save_screenshot(file_path)
#print("这个是case的后置调键1")
self.driver.close()
# @ddt.data(
# ['12','Mushishi01','111111','code.png','user_email_error','请输入有效的电子邮件地址'],
# ['@qq.com','Mushishi01','111111','code.png','user_email_error','请输入有效的电子邮件地址'],
# ['12@qq.com','Mushishi01','111111','code.png','user_email_error','请输入有效的电子邮件地址']
# )
# @ddt.unpack
# @ddt.data(*data)
@ddt.data(*data)
def test_register_case(self,data):
email,username,password,self.file_name,assertCode,assertText = data
email_error = self.login.register_function(email,username,password,self.file_name,assertCode,assertText)
self.assertFalse(email_error,"测试失败")
if name == ‘main’:
file_path = os.path.join(
os.path.abspath(os.path.dirname(os.path.dirname(file))) + “\report\” + “first_case1.html”)
print(file_path)
f = open(file_path,‘wb’)
suite = unittest.TestLoader().loadTestsFromTestCase(FirstDdtCase)
runner = HTMLTestRunner(stream=f,title=“This is first report1”,description=u"这个是我们第一次测试报告1",verbosity=2)
runner.run(suite)