def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.user_log.info('this is chrome') self.login = RedisterBusiness(self.driver) print('——————————————这是前置——————————————')
def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.login = RedisterBusiness(self.driver) time.sleep(2) print('——————————————这是前置——————————————')
class FrstDdtCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.login = RedisterBusiness(self.driver) time.sleep(2) print('——————————————这是前置——————————————') def tearDown(self): time.sleep(5) self.driver.close() print('****************************这是后置*****************************') # @ddt.data( # ['12 ', '123465', '1234554', 'code', 'email_error', '请输入有效的电子邮件地址'] # ) # @ddt.unpack @ddt.data(*ex_data) def test_register_case(self, ex_data): print(ex_data) email, name, password, file_name, assertCode, assertText = ex_data print(file_name) self.login.user_base(email, name, password, file_name) print(1) print(file_name)
class DttData(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.login = RedisterBusiness(self.driver) print('——————————————这是前置——————————————') def tearDown(self): self.driver.close() print('****************************这是后置*****************************') @ddt.data( [' ', '123465', '1234554', 'code', 'email_error', '请输入有效的电子邮件地址'], ['*****@*****.**', ' ', '1212342345', 'code', 'nickname_error', '字符长度必须大于等于4,一个中文字算2个字符'], ['*****@*****.**', '12121122222222222222222222222222', '1212342345', 'code', 'nickname_error', '字符长度必须小于等于18,一个中文字算2个字符'], ['*****@*****.**', '124322334', ' ', 'code', 'password_error', '最少需要输入 5 个字符'], ['*****@*****.**', '124322334', '2122121112212121212121212112 ', 'code', 'password_error', '最多只能输入 20 个字符'], ['*****@*****.**', '1223434', '12323445', '', '最少需要输入 5 个字符'], ) @ddt.unpack def test_login_email_error(self, email, username, password, code, assertCode, assertText): error_text = self.login.register_function(email, username, password, code, assertCode, assertText) self.assertFalse(error_text, '注册成功,输入错误')
class FirstCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.login = RedisterBusiness(self.driver) print('——————————————这是前置——————————————') def tearDown(self): self.driver.close() print('****************************这是后置*****************************') def test_login_email_error(self): email_error_text = self.login.login_email_error(' ', '123465', '1234554', 'code') # if email_error_text == True: # print('注册成功,---email输入错误') self.assertFalse(email_error_text,'注册成功,---email输入错误') def test_login_username_error(self): username_error_text = self.login.login_name_error('*****@*****.**', ' ', '12342345', 'code') if username_error_text == True: print('注册成功,---name输入错误') # self.assertFalse(username_error_text,'注册成功,---name输入错误') def test_login_password_error(self): password_error_text = self.login.login_password_error('*****@*****.**', '124322334', ' ', 'code') # if password_error_text == True: # print('注册成功,---password输入错误') self.assertFalse(password_error_text,'注册成功,---password输入错误') def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**', '1223434', '12323445', '') # if code_error == True: # print('注册成功,---code输入错误') self.assertFalse(code_error,'注册成功,---code输入错误') def test_login_succeed(self): self.login.user_base('*****@*****.**', '1233244', '12345324', 'p23p2342') # if self.login.register_succes() == True: # print('注册成功') self.assertFalse(self.login.register_succeed(),'注册成功')
class FirstCase(unittest.TestCase): # 若是放到函数外面,只能执行一遍log:因为第一次实例化了,创建了对象然后销毁了,第二次没有可用的了 # 放发函数setup里面也可以 @classmethod def setUpClass(cls): # 调用日志的地方 cls.log = UserLog() cls.user_log = cls.log.get_log() # 传给放的路径信息--code码保存路径 path_file = os.getcwd() file_name = os.path.abspath( os.path.dirname(path_file) + '/Image' + '/code.png') cls.file_name = file_name def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.user_log.info('this is chrome') self.login = RedisterBusiness(self.driver) print('——————————————这是前置——————————————') def tearDown(self): time.sleep(3) # outcome: 捕捉函数运作之后的结果 for method_name, error in self._outcome.errors: if error: cae_name = self._testMethodName path_cwd = os.getcwd() file_path = os.path.abspath( os.path.dirname(path_cwd) + '/report' + '/' + cae_name + '.png') self.driver.save_screenshot(file_path) self.driver.close() print('****************************这是后置*****************************') @classmethod def tearDownClass(cls): # 还是报错:TypeError: 'FileHandler' object is not callable # cls.log = UserLog() cls.log.file_handle() # 验证邮箱 def test_login_email_error(self): email_error_text = self.login.login_email_error( '0', '1234265', '12342554', self.file_name) # if email_error_text == True: # print('注册成功,---email输入错误') self.assertFalse(email_error_text, '注册成功,---email输入错误') # 验证用户名 def test_login_username_error(self): username_error_text = self.login.login_name_error( '*****@*****.**', '1', '123422345', self.file_name) # if username_error_text == True: # print('注册成功,---name输入错误') self.assertFalse(username_error_text, '注册成功,---name输入错误') # 验证密码 def test_login_password_error(self): password_error_text = self.login.login_password_error( '*****@*****.**', '1214322334', '2', self.file_name) # if password_error_text == True: # print('注册成功,---password输入错误') self.assertFalse(password_error_text, '注册成功,---password输入错误') # 验证成功 def test_login_succeed(self): self.login.user_base('*****@*****.**', '1122214', '11114', self.file_name) # if self.login.register_succes() == True: # print('注册成功') self.assertFalse(self.login.register_succeed(), '注册成功')