import ddt
import unittest
from handle.register_business import RegisterBusiness
from selenium import webdriver
from time import sleep
import os
import HTMLTestRunner
from util.exlcel_util import ExcelUtil
ex = ExcelUtil()
data = ex.get_data()
@ddt.ddt
class FirstDdtCase(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = webdriver.Chrome()
cls.driver.get('http://www.5itest.cn/register')
cls.driver.maximize_window()
def setUp(self):
self.driver.refresh()
self.registerb = RegisterBusiness(self.driver)
def tearDown(self):
sleep(3)
for method_name, error in self._outcome.errors:
if error:
case_name = self._testMethodName
file_path = os.path.join(r'..\\report\\' + case_name + '.png')
self.driver.save_screenshot(file_path)
@classmethod
def tearDownClass(cls):
cls.driver.close()
'''
@ddt.data(
['982364','ddff343','111111','111111','user_email_error','请输入有效的电子邮件地址'],
['121998734@qq.com','l1','111111','111111','user_email_error','请输入有效的电子邮件地址'],
['@qq.com', 'l1', '111111', '111111', 'user_email_error', '请输入有效的电子邮件地址']
)
@ddt.unpack
'''
@ddt.data(*data)
def test_register_case(self,data):
email,username,password,code,codeerror,errortext = data
error_text = self.registerb.register_functiom(email,username,password,code,codeerror,errortext)
self.assertFalse(error_text,'执行失败')
if __name__ == '__main__':
file_path = os.path.join(r'..\\report\\' + "first_case.html")
f = open(file_path,'wb')
suite = unittest.TestLoader().loadTestsFromTestCase(FirstDdtCase)
runner = HTMLTestRunner.HTMLTestRunner(stream=f,title='测试报告1',description="这个是测试报告1",verbosity=2)
runner.run(suite)