class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() cls.driver = webdriver.Chrome() cls.driver.get('http://www.5itest.cn/register') def setUp(self): self.logger.info("this is chrome") self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(2) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path = os.path.join("E:/pythonProject/SeleniumPython" + "/report/" + case_name + ".png") self.driver.save_screenshot(file_path) @classmethod def tearDownClass(cls): cls.log.close_handle() cls.driver.close() #邮箱、用户名、密码、验证码、错误信息定位元素、错误提示信息 def test_login_email_error(self): email_error = self.login.login_email_error('32', 'user111', '111111', 'test1') return self.assertFalse(email_error, '测试失败') #通过assert判断是否为error def test_login_username_error(self): username_error = self.login.login_email_error('*****@*****.**', 'ss', '111111', 'test1') self.assertFalse(username_error) def test_login_code_error(self): code_error = self.login.login_email_error('*****@*****.**', 'ss', '111111', 'test1') self.assertFalse(code_error) def test_login_password_error(self): password_error = self.login.login_email_error('*****@*****.**', 'ss', '111111', 'test1') self.assertFalse(password_error) def test_login_success(self): success = self.login.user_base('*****@*****.**', 'ss', '111111', 'test1') self.assertFalse(success)
class FirstCase(unittest.TestCase): def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.get("http://www.5itest.cn/register") self.register_business = RegisterBusiness(self.driver) def tearDown(self) -> None: self.driver.quit() def test_login_email_error(self): email_error = self.register_business.login_email_error('34', 'U1212', '12Test12', 'der56') self.assertFalse(email_error) # if email_error == True: # print("注册成功了,此条 case 执行失败") # login('223', '1111') # 通过 assert 判断是否为 error def test_login_username_error(self): username = self.register_business.login_username_error("*****@*****.**", "2", "Test@123", 'sdsds') self.assertFalse(username) def test_login_password_error(self): password = self.register_business.login_password_error("*****@*****.**", "2gw", "2", 'sdsds') self.assertFalse(password) def test_login_code_error(self): code = self.register_business.login_code_error("*****@*****.**", "2gw", "Test@123", 's') self.assertFalse(code) def test_login_success(self): success = self.register_business.register_success() self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.file_name = "E:\\test001.png" cls.log = UserLog() cls.logger = cls.log.get_logger() @classmethod def tearDownClass(cls): cls.log.close_handle() def setUp(self): self.driver = webdriver.Firefox() self.driver.get("http://www.5itest.cn/register") self.logger.info("this is a firfox") time.sleep(2) self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(3) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path = os.path.join( os.path.dirname(os.getcwd()) + "\\report\\" + case_name + ".png") self.driver.save_screenshot(file_path) # if sys.exc_info()[0]: # self.driver.close() print("后置条件") def test_login_email_error(self): email_error = self.login.login_email_error("3664", "11111", "222", self.file_name) self.assertFalse(email_error, "email case") # if email_error==True: # print("注册成功了,此条case失败") def test_login_username_error(self): username_error = self.login.login_name_error("*****@*****.**", "1", "11111", self.file_name) self.assertFalse(username_error, "name case") # if username_error==True: # print("注册成功了,此条case失败") def test_login_password_error(self): password_error = self.login.login_password_error( "*****@*****.**", "1ii11", "11", self.file_name) self.assertFalse(password_error, "password case") # if password_error == True: # print("注册成功了,此条case失败") def test_login_code_error(self): code_error = self.login.login_code_error("*****@*****.**", "ss", "11111", self.file_name) self.assertFalse(code_error, "code case") # if code_error == True: # print("注册成功了,此条case失败") def test_login_success(self): success = self.login.user_base("*****@*****.**", 'ssss', '22222', self.file_name) self.assertFalse(success)
class FirstCase(object): def __init__(self): driver = webdriver.Firefox() driver.get('http://www.5itest.cn/register') self.login = RegisterBusiness(driver) def test_login_email_error(self): email_error = self.login.login_email_error('11', 'user111', '111111', 'qwe1') if email_error == True: print('注册成功了,此条case执行失败') #通过assert判断是否为error def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 'dd', '2222222', 'wed3') if username_error == True: print('注册成功了,此条case执行失败') def test_login_password_error(self): password_error = self.login.login_name_error('*****@*****.**', 'd444d', '2222222', 'wed3') if password_error == True: print('注册成功了,此条case执行失败') def test_login_code_error(self): code_error = self.login.login_name_error('*****@*****.**', 'dd', '2222222', 'wed3') if code_error == True: print('注册成功了,此条case执行失败') def test_login_success(self): self.login.user_base('*****@*****.**', 'dd', '2222222', 'wed3') if self.login.register_success() == True: print('注册成功了')
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") self.driver.maximize_window() self.login = RegisterBusiness(self.driver) self.logger.debug('open the chrome') # 每条用例结束时,如果有错误就截图保存到指定路径下 def tearDown(self): time.sleep(3) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path_father = os.path.abspath(os.path.dirname( os.getcwd())) file_path = os.path.join(file_path_father + "\\report\\" + case_name + ".png") self.driver.save_screenshot(file_path) self.driver.close() @classmethod def tearDownClass(cls): cls.log.close_handle() # 邮箱、用户名、密码、验证码、错误信息元素、错误信息 def test_login_email_error(self): email_e = self.login.login_email_error('@', 'u', '1111', 'code') self.assertFalse(email_e, '此条case成功') # if email_e == True: # print('注册成功了,此条case失败') def test_login_username_error(self): username_e = self.login.login_name_error('@', 'u', '1111', 'code') if username_e == True: print('注册成功了,此条case失败') @unittest.skip def test_login_password_error(self): password_e = self.login.login_password_error('@', 'u', '1111', 'code') if password_e == True: print('注册成功了,此条case失败') def test_login_code_error(self): code_e = self.login.login_code_error('*****@*****.**', 'uangchery', '12345678', 'code') if code_e == True: print('注册成功了,此条case失败') def test_login_sucess(self): sucess = self.login.user_base('email', 'username', '1111', 'code') if self.login.register_sucess() == True: print("注册成功") else: print("注册不成功,此条case失败")
class FirstCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") self.login = RegisterBusiness(self.driver) def tearDown(self): self.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error('35','123','123456','2365') if email_error == True: print('注册成功了,此条case执行失败') def test_login_name_error(self): code_error = self.login.login_code_error('*****@*****.**','asxder','1234567','888') if code_error == True: print('注册成功了,此条case执行失败') def test_login_password_error(self): password_error = self.login.login_password_error('*****@*****.**','asxder','1234567','888') if password_error == True: print('注册成功了,此条case执行失败') def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**','asxder','1234567','888') if code_error == True: print('注册成功了,此条case执行失败') def test_login_success(self): self.login.user_base('*****@*****.**','asxder','1234567','888') if self.login.register_success() == True: print("注册成功!")
class firstCase(unittest.TestCase): @classmethod def setUpClass(self): self.log = UserLog() self.logger = self.log.get_log() print("所有case执行之前的前置") @classmethod def tearDownClass(self): print("所有case执行之后的后置置") self.log.close() def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register?goto=/") self.logger.info("this is chrome") self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(2) for method_name, error in self._outcome.errors: if error: casename = self._testMethodName file_path = os.path.join(os.getcwd() + "\\report\\" + casename + ".png") self.driver.save_screenshot(file_path) self.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error("22", "user11", "1111", "2222") if email_error == True: print("邮箱验证成功,此条case成功") else: print("注册成功,此条case失败") self.assertTrue(email_error, "case执行成功") def test_login_username_error(self): username_error = self.login.login_name_error("22", "user11", "1111", "2222") '''if username_error == True: print("用户名验证成功,此条case成功") else: print("注册成功,此条case失败")''' self.assertTrue(username_error, "case执行成功") def test_login_code_error(self): pass def test_login_success(self): success = self.login.user_base("1111", "222", "22", "333") '''if self.login.register_success() == True: print("注册成功")''' self.assertTrue(self.login.register_success())
class FirstCase(unittest.TestCase): @classmethod #装饰器 def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() print("所有case 执行之前的前置") @classmethod # 装饰器 def tearDownClass(cls): cls.log.close_handle() print("所有case执行之后的后置") def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") #self.driver.maximize_window() self.logger.info("this is chrome") self.login = RegisterBusiness(self.driver) # def tearDown(self): # 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) # self.driver.close() # print("这是case 的后置条件") # 邮箱,用户名,密码,验证码,错误信息定位元素,错误提示信息 def test_login_email_error(self): email_error = self.login.login_email_error("*****@*****.**", "user12", "111111", "test1") # if email_error == True: # print("注册成功了,此条case失败") #通过assert 判断是否为error self.assertFalse(email_error, "测试失败") def test_username_error(self): user_name_error = self.login.login_username_error( "*****@*****.**", "ss", "111111", "test1") self.assertFalse(user_name_error, "测试失败") def test_password_error(self): password_error = self.login.login_password_error( "*****@*****.**", "user2222", "111111", "test1") self.assertFalse(password_error, "测试失败") def test_code_error(self): code_error = self.login.login_code_error("*****@*****.**", "user3333", "111111", "test1") self.assertFalse(code_error, "测试失败") def test_login_success(self): success = self.login.login_success("12", "user1111", "111111", "test1") self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.file_name = "C:/Users/cheng/PycharmProjects/muke-selenium/report/test_login_email_error.png" cls.log = UserLog() cls.logger = cls.log.get_log() @classmethod def tearDownClass(cls): cls.log.close_handle() def setUp(self): self.file_name = "C:/Users/cheng/PycharmProjects/muke-selenium/report/test_login_email_error.png" self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.logger.info('this is Chrome') self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(2) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path = os.path.join( os.path.dirname(os.getcwd()) + '/report/' + case_name + '.png') self.driver.save_screenshot(file_path) self.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error('34', 'user111', '111111', self.file_name) self.assertFalse(email_error, '此条case执行失败') # if email_error==True: # print('注册成功了,此条case执行失败') def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 'ss', '111111', self.file_name) if username_error == True: print('此条case执行失败') @unittest.skip('跳过') def test_login_code_error(self): password_error = self.login.login_code_error('*****@*****.**', 'user111', '111111', self.file_name) if password_error == True: print('此条case执行失败') @unittest.skip('跳过') def test_login_success(self): succes = self.login.user_base('*****@*****.**', 'user111', '111111', self.file_name) if self.login.register_succes() == True: print('注册成功')
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): warnings.simplefilter("ignore", ResourceWarning) self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.driver.maximize_window() self.logger.info("this is chrome") self.login = RegisterBusiness(self.driver) self.file_name = "E:/SELENIUMPYTHON/Image/test001.png" def tearDown(self): time.sleep(2) 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) self.driver.close() print("执行完一条case") @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error('34', 'user1111', '111111', self.file_name) self.assertFalse(email_error) #通过assert判断是否为error def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 's1s', '33434', self.file_name) self.assertFalse(username_error) def test_login_password_error(self): password_error = self.login.login_password_error( '*****@*****.**', 'ss', '3343', self.file_name) self.assertFalse(password_error) def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**', 'ss', '33434', self.file_name) self.assertFalse(code_error) def test_login_success(self): success = self.login.register_success('*****@*****.**', 'test16', '33434', self.file_name) #self.assertFalse(success) self.assertEqual(True, success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls) -> None: cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.logger.info("this is chrome") self.login = RegisterBusiness(self.driver) self.file_name = os.path.join(BATH_PATH, 'image', 'test001.png') def tearDown(self) -> None: time.sleep(2) # 捕获程序是否有异常,有则截图保存 for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path = os.path.join(BATH_PATH, 'report', case_name + '.png') self.driver.save_screenshot(file_path) self.driver.close() @classmethod def tearDownClass(cls) -> None: cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error('34', 'user111', '11111', self.file_name) return self.assertFalse(email_error, "测试失败") def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 't1', '111111', self.file_name) self.assertTrue(username_error) def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**', 'ss22212', '111111', self.file_name) self.assertFalse(code_error) def test_login_password_error(self): password_error = self.login.login_password_error( '*****@*****.**', 'ss23222', '111111', self.file_name) self.assertFalse(password_error) def test_login_success(self): # success = self.login.register_success('*****@*****.**', '23213', '111111', self.file_name) # 成功 success = self.login.register_success('12221', '2321', '111111', self.file_name) # 失败 # print(success) self.assertTrue(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() cls.file_name = "E:/Teacher/Imooc/SeleniumPython/Image/test001.png" cls.driver = webdriver.Chrome() cls.driver.get('http://www.5itest.cn/register') cls.driver.maximize_window() def setUp(self): self.driver.refresh() self.logger.info("this is chrome") 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") @classmethod def tearDownClass(cls): cls.log.close_handle() cls.driver.close() #邮箱、用户名、密码、验证码、错误信息定位元素、错误提示信息 def test_login_email_error(self): email_error = self.login.login_email_error('*****@*****.**','*****@*****.**','111111',self.file_name) return self.assertFalse(email_error,"测试失败") def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**','t1','111111',self.file_name) self.assertTrue(username_error) def test_login_code_error(self): code_error = self.login.login_name_error('*****@*****.**','ss22212','111111',self.file_name) self.assertFalse(code_error) def test_login_password_error(self): password_error = self.login.login_name_error('*****@*****.**','ss23222','111111',self.file_name) self.assertFalse(password_error) def test_login_success(self): success = self.login.user_base('*****@*****.**','2321','111111',self.file_name) self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.driver.maximize_window() self.logger.info("this is the chrome") self.rb = RegisterBusiness(self.driver) self.file_name = 'E:/PycharmProjects/seleniumPython/image/test001.png' def tearDown(self): print('这是后置条件') 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) self.driver.close() @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.rb.login_email_error('*****@*****.**', 'user111', '11111', self.file_name) self.assertFalse(email_error, '此条email的case执行了') def test_login_username_error(self): username_error = self.rb.login_name_error('*****@*****.**', 'sss', '11111', self.file_name) self.assertFalse(username_error) def test_login_password_error(self): password_error = self.rb.login_password_error('*****@*****.**', 'user11', '1111', self.file_name) self.assertTrue(password_error) def test_login_code_error(self): code_error = self.rb.login_code_error('*****@*****.**', 'user11', '11111', self.file_name) self.assertTrue(code_error) def test_login_success(self): success = self.rb.user_base('*****@*****.**', 'user111', '11111', self.file_name) self.assertFalse(success)
class FirstCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.login = RegisterBusiness(self.driver) def tearDown(self): self.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error("34", "user1111", "1111111", "test1") if email_error == True: print("注册成功,此条case执行失败") def test_login_username_error(self): username_error = self.login.login_name_error("*****@*****.**", 'ss', '1111111', 'text1') if username_error == True: print("注册成功,此条case执行失败") def test_login_code_error(self): code_error = self.login.login_code_error("*****@*****.**", 'ssssss', '1111111', 'text1') if code_error == True: print("注册成功,此条case执行失败") def test_login_password_error(self): password_error = self.login.login_password_error( "*****@*****.**", 'sssss', '111', 'text1') if password_error == True: print("注册成功,此条case执行失败") def test_login_success(self): success = self.login.user_base("*****@*****.**", 'ssssss', '1111111', 'text1') if self.login.register_success() == True: print("注册成功")
class FirstCase(unittest.TestCase): def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.driver.maximize_window() self.register_business = RegisterBusiness(self.driver) def tearDown(self) -> None: self.driver.close() def test_login_email_error(self): user_email_error = self.register_business.login_email_error('34', 'user111', '122333', '1233') self.assertTrue(user_email_error, "注册失败,此条case执行成功") # 通过assert判断是否为error def test_login_username_error(self): user_name_error = self.register_business.login_username_error('*****@*****.**', 'qw', '12333', '1231') # if user_name_error is True: # print("注册失败,此条case执行成功") self.assertTrue(user_name_error, "注册失败,此条case执行成功") # def test_login_password_error(self): # password_error = self.register_business.login_password_error('*****@*****.**', 'joseph2111', '123456', # '1234') # if password_error is True: # print("注册失败,此条case执行成功") # def test_login_code_error(self): # code_text_error = self.register_business.login_code_error('*****@*****.**', 'joseph_beer2', '123345', '1234') # if code_text_error is True: # print("注册失败,此条case执行成功") def test_login_success(self): success = self.register_business.user_base('*****@*****.**', 'joseph_beer', '111111', '1234') if self.register_business.register_success() is True: print("注册成功")
class FirstCase(unittest.TestCase): def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.get("http://my.cnki.net/Register/") logger.debug("this is chrome") user_log.close_handle() self.register = RegisterBusiness(self.driver) def tearDown(self) -> None: time.sleep(2) self.driver.close() def test_login_email_error(self): email_error = self.register.login_email_error("34", "user11", "123qwe", "1234") self.assertTrue(email_error, "无效邮箱,注册失败~") def test_login_username_error(self): username_error = self.register.login_username_error( "*****@*****.**", "12", "123qwe", "1234") self.assertTrue(username_error, "无效用户名,注册失败~") def test_login_password_error(self): password_error = self.register.login_password_error( "*****@*****.**", "user123qwe", "123", "1234") self.assertTrue(password_error, "无效密码,注册失败~") def test_code_error(self): code_error = self.register.login_code_text_error_error( "*****@*****.**", "user123qwe", "123qweasd", "1234") self.assertTrue(code_error, "无效验证码,注册失败~") def test_login_success(self): success = self.register.user_base("*****@*****.**", "user123qwe", "123qweasd", "1234") self.assertTrue(success, "注册成功~")
class FirstCase(unittest.TestCase): """测试用例""" # r_log = None count = 0 @classmethod def setUpClass(cls) -> None: # cls.driver = webdriver.Chrome() # cls.driver.maximize_window() warnings.simplefilter("ignore", ResourceWarning) cls.r_log = RegisterLog() cls.register_log = cls.r_log.get_log() @classmethod def tearDownClass(cls) -> None: cls.r_log.close_log() time.sleep(3) def setUp(self) -> None: self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") self.register_log.info("this is Chrome") self.r_log.output_log() self.driver.maximize_window() path = "../config/LocalElement.ini" i_vcode = IdentifyVCode(self.driver, self._testMethodName, path) # self.v_code = i_vcode.get_jj_varify_code("code_image") self.register_b = RegisterBusiness(self.driver, path) def tearDown(self) -> None: curr_time = datetime.datetime.now() str_time = str(curr_time.time()) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName file_path = os.path.join("../report/" + case_name + str_time + ".png") self.driver.save_screenshot(file_path) time.sleep(2) self.driver.close() def test_login_email_error(self): """测试登录错误的情况""" email_statue = self.register_b.login_email_error( "1111", "mingzhi", "123456", "1234") self.assertFalse(email_statue, "邮箱不合法,怎么会登录成功呢!测试失败!") # if email_statue is True: # print("很遗憾,邮箱不合法,注册失败了!") # elif email_statue is False: # print("邮箱不合法,怎么会登录成功呢!") def test_login_nickname_error(self): nickname_statue = self.register_b.login_nickname_error( "*****@*****.**", "我是名字", "111111", "1234") self.assertFalse(nickname_statue, "用户名不合法,怎么会注册成功呢!测试失败!") # if nickname_statue is True: # print("很遗憾,用户名不合法,注册失败了!") # elif nickname_statue is False: # print("用户名不合法,怎么会注册成功呢!") def test_login_password_error(self): password_statue = self.register_b.login_password_error( "*****@*****.**", "2322", "1", "1234") self.assertFalse(password_statue, "用户名不合法,怎么会注册成功呢!测试失败!") # if nickname_statue is True: # print("很遗憾,用户名不合法,注册失败了!") # elif nickname_statue is False: # print("用户名不合法,怎么会注册成功呢!") def test_login_vcode_error(self): vcode_statue = self.register_b.login_vcode_error( "*****@*****.**", "mingzhi", "123456", "1234") self.assertFalse(vcode_statue, "验证码不正确,怎么会注册成功呢!测试失败!") # if vcode_statue is True: # print("很遗憾,验证码不正确,注册失败了") # elif vcode_statue is False: # print("验证码不正确,怎么会注册成功呢!") def test_login_success(self): login_statue = self.register_b.login_success("*****@*****.**", "mingzhi", "123456", "v_code") self.assertFalse(login_statue, "注册失败") def test_login_success1(self): login_statue = self.register_b.login_success("*****@*****.**", "mingzhi", "123456", "v_code") self.assertFalse(login_statue, "注册失败")
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): '''在所有用例执行前执行一次,只执行一次''' cls.log = UserLog() cls.logger = cls.log.get_log() cls.file_name = "F:\\myfile\\python\\code\\seleniumpython\\Image\\test001.png" #在jenkins中构建项目,如果浏览器和jenkins安装在不同的目录,就会出现找不到浏览器,所以打开浏览器的时候需要指定浏览器的路径 cls.driver = webdriver.Chrome( "C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chromedriver.exe" ) cls.driver.get('http://www.5itest.cn/register') cls.driver.maximize_window() def setUp(self): '''每个用例执行的前都会执行一次''' self.driver.refresh() self.logger.info("this is chrome!!!") 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) if sys.exc_info()[1]: file_path = os.path.join( os.path.dirname(os.getcwd()) + "\\report\\" + "1" + ".png") #print(file_path) self.driver.save_screenshot(file_path) #print("这个是case的后置调键1") @classmethod def tearDownClass(cls): '''所有用例执行后执行一次''' cls.log.close_handle() cls.driver.close() #邮箱、用户名、密码、验证码、错误信息定位元素、错误提示信息 def test_login_email_error(self): email_error = self.login.login_email_error('19', 'user1111', '111111', self.file_name) return self.assertFalse(email_error, "测试失败") def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 't3', '111111', self.file_name) self.assertTrue(username_error) def test_login_code_error(self): code_error = self.login.login_name_error('*****@*****.**', 'ss22212', '111111', self.file_name) self.assertFalse(code_error) def test_login_password_error(self): password_error = self.login.login_name_error('*****@*****.**', 'ss23222', '111111', self.file_name) self.assertFalse(password_error) def test_login_success(self): success = self.login.user_base('*****@*****.**', '2321000', '111111', self.file_name) self.assertFalse(success)
class FirstCase(unittest.TestCase): # 某一条case的前置条件, 装饰漆 @classmethod def setUpClass(cls): cls.code_file = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/code.png" print("所有case执行之前的前置") @classmethod def tearDownClass(cls): print("所有case执行之后的后置") def setUp(self): print("每条case执行之前") self.file_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_code_%s.png" % (time.time()) self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register") self.driver.maximize_window() self.register = RegisterBusiness(self.driver) # self.register_function = RegisterFunction(self.driver, self.file_path) self.register_code = GetCode(self.driver, self.file_path) def tearDown(self): print("每条case执行之后") # py2看case有没有异常 # if sys.exc_info()[0]: # self.driver.save_screenshot() # py3中使用_outcome.errors, self._outcome.errors结果是一个list print(self._outcome.errors) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName error_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_%s_%s.png" % ( case_name, time.time()) self.driver.save_screenshot(error_path) self.driver.close() # def __init__(self, driver): # self.file_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_code_%s.png" % (time.time()) # self.driver = driver # self.register = RegisterBusiness(driver) # self.register_function = RegisterFunction(driver, self.file_path) # case名称尽量见名知意 def test_login_email_error(self): # 此方法应该封装在handle中 # if not self.register.login_email_error('email', 'user11188', '111111', 'test1'): # error_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_email_error_%s.png" % (time.time()) # self.driver.save_screenshot(error_path) # AssertionError 通过assert判断是否为error email_error = self.register.login_email_error('email', 'user11188', '111111', FirstCase.code_file) self.assertTrue(email_error, "邮箱用例") # @unittest.skip("不执行username用例") def test_login_username_error(self): name_error = self.register.login_name_error('*****@*****.**', '11', '111111', FirstCase.code_file) self.assertTrue(name_error, "名字用例") def test_login_code_error(self): code_error = self.register.login_password_error('*****@*****.**', 'user111d88', '1', FirstCase.code_file) # error_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_password_error_%s.png" % (time.time()) # # self.driver.save_screenshot(error_path) self.assertTrue(code_error, "验证码错误") def test_login_success(self): login_success = self.register.register_success('*****@*****.**', '388uu7', '123456', FirstCase.code_file) # error_path = "/Users/qing.li/PycharmProjects/hm/selenium_/imooc/image/imooc_error_%s.png" % (time.time()) # self.driver.save_screenshot(error_path) # else: # print("校验成功") self.assertTrue(login_success, "登录成功")
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): #cls.login = UserLog() #cls.logger = cls.login.get_log() cls.file_name = 'D:\pycharm\python3\demo\study\image1.png' #静态全局变量 cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): print('测试开始前执行') self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.logger.info('This is chrome') self.driver.maximize_window() self.login = RegisterBusiness(self.driver) def tearDown(self): print('测试完成后执行') #if sys.exc_info()[0]: for method_name, error in self._outcome.errors: #_outcome.errors能获取当前运行case名称和错误信息 if error: #如果有错误信息 case_name = self._testMethodName #获取当前运行错误case的名称 path = os.path.dirname( os.path.dirname( os.path.abspath(__file__))) #获取当前文件目录的上一级目录 file_path = path + '\\report\\' + case_name + '.png' #存储路径 self.driver.save_screenshot(file_path) #截图 time.sleep(3) self.driver.quit() @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error( '34', '111', '1111', self.file_name) #也就是cls.file_name return self.assertFalse(email_error, 'case执行') #判断结果是否为false,不为false时候 打印'case执行' #if email_error == True: # print('注册成功,此case执行失败') #通过Assert判断是否为error def test_login_username_error(self): name_error = self.login.login_name_error('344', '111', '1111', self.file_name) self.assertFalse(name_error, 'case执行') #判断结果是否为false def test_login_password_error(self): password_error = self.login.login_password_error( '344', '111', '1111', self.file_name) self.assertFalse(password_error, 'case执行') #判断结果是否为false def test_login_code_error(self): code_error = self.login.login_code_text_error('344', '111', '1111', self.file_name) self.assertFalse(code_error, 'case执行') #判断结果是否为false def test_login_success(self): success = self.login.user_business('344', '111', '1111', self.file_name) #print(self.file_name) self.assertFalse(success, 'case执行') #判断结果是否为false
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() cls.file_name = r'D:\selenium_image\test02.png' cls.driver = webdriver.Chrome() cls.driver.get("http://www.5itest.cn/register") cls.driver.maximize_window() def setUp(self): self.driver.refresh() self.logger.info("this is Chrome") self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(2) for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName #获取case的名字,用于后续的截图 screenshot_name = case_name + '.png' #截图图片的名字 dir_path = os.path.dirname(os.getcwd()) #获取上一级目录,即工程目录 file_path = os.path.join(dir_path, 'report', screenshot_name) #截图保存路径 self.driver.save_screenshot(file_path) @classmethod def tearDownClass(cls): cls.log.close_handle() cls.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error('*****@*****.**', 'user221', '111111', self.file_name) self.assertFalse(email_error, '测试失败') def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', '1112122222222224444', '111111', self.file_name) self.assertFalse(username_error) # if username_error == True: # print("注册成功了,此条case执行失败") def test_login_password_error(self): password_error = self.login.login_password_error( '*****@*****.**', 'user111', '11', self.file_name) self.assertFalse(password_error) # if password_error == True: # print("注册成功了,此条case执行失败") def test_login_code_error(self): code_error = self.login.login_code_error('34', 'user111', '111111', self.file_name) self.assertFalse(code_error) # if code_error == True: # print("注册成功了,此条case执行失败") def test_login_success(self): success = self.login.register_succes("*****@*****.**", "ss222", "111111", self.file_name) self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): get_element = ReadIni() cls.pwd = os.path.join(os.path.dirname(os.getcwd())) cls.file_name = cls.pwd + "\\image\\test001.png" # cls.file_name = get_element.get_value("code_image_url") cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.driver = webdriver.Chrome( "C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application" "\\chromedriver.exe") # self.driver = webdriver.Chrome() option = webdriver.ChromeOptions() option.binary_location = r'C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe' self.driver.get("http://www.5itest.cn/register?goto=/") self.logger.info("打开浏览器成功") self.login = RegisterBusiness(self.driver) def tearDown(self): time.sleep(2) for methon_name, error in self._outcome.errors: if error: case_name = self._testMethodName # filePath = os.path.join(os.path.dirname(os.getcwd()) + "\\report\\" + case_name + ".png") filePath1 = 'C:\\Users\\Administrator\\PycharmProjects\\moco\\report' filePath = filePath1 + '\\' + case_name + '.png' self.driver.save_screenshot(filePath) self.driver.close() @classmethod def tearDownClass(cls): cls.log.close_handle() # 邮箱错误 def test_login_email_error(self): email_error = self.login.login_email_error("*****@*****.**", "user1111", "123456", self.file_name) self.assertFalse(email_error, "case执行成功") # 用户名错误 def test_login_username_error(self): username_error = self.login.login_username_error( "*****@*****.**", "ur", "12345", self.file_name) self.assertFalse(username_error, "case执行成功") # 密码错误 def test_login_password_error(self): password_erroer = self.login.login_password_error( "*****@*****.**", "test123", "11", self.file_name) self.assertFalse(password_erroer, "case执行成功") # 验证码错误 def test_longin_code_error(self): code_error = self.login.login_code_error("*****@*****.**", "loawang12", "123456", self.file_name) self.assertFalse(code_error, "case执行成功") # 注册成功 def test_login_success(self): success = self.login.user_base("*****@*****.**", "wanglaosi12", "23456", self.file_name) self.assertFalse(success, "case执行了")
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.file_name = "E:/unittest/image/test01.png" self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register?goto=/course/explore") self.driver.maximize_window() self.logger.info("this is chrome") 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) self.driver.close() # @classmethod # def tearDownClass(cls): # cls.driver.close() #print("这个是后置条件") @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error('*****@*****.**', '111', '111111', self.file_name) return self.assertFalse(email_error, "测试失败") # if email_error == True: # print("注册成功了,此条case执行失败") #通过assert判断是否为error def test_login_username_error(self): user_name_error = self.login.login_name_error('*****@*****.**', 'ss', '111111', self.file_name) self.assertFalse(user_name_error) # if user_name_error == True: # print("注册成功了,此条case执行失败") def test_login_password_error(self): password_error = self.login.login_password_error( '*****@*****.**', 'ss', '111', self.file_name) self.assertFalse(password_error) # if password_error == True: # print("注册成功了,此条case执行失败") def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**', 'ss', '111111', self.file_name) self.assertFalse(code_error) # if code_error == True: # print("注册成功了,此条case执行失败") def test_login_success(self): success = self.login.register_success('*****@*****.**', 'ss', '111111', self.file_name) self.assertTrue(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.log = UserLog() cls.logger = cls.log.get_log() cls.file_name = "/Users/pmy/Downloads/selenium code/image/test001.png" cls.driver = webdriver.Chrome() cls.driver.get('http://www.5itest.cn/register') cls.driver.maximize_window() #unittest前置条件:打开网站 某一条case的前置条件 def setUp(self): self.driver = webdriver.Chrome() #加self使driver变成全局的 self.driver.get('http://www.5itest.cn/register') log.debug("this is debug") self.login = RegisterBusiness(self.driver) #unittest后置条件:关闭driver 某一条case的后置条件 def tearDown(self): time.sleep(2) #判断当前程序的运行是否有异常 python 3 #拿到当前运行的错误信息,返回的是list 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) self.driver.close() @classmethod def tearDownClass(cls): cls.log.close_handle() cls.driver.close() def test_login_email_error(self): email_error = self.login.login_email_error('34','user111','111111',self.file_name) #if email_error == True: #print("注册成功了,此条case执行失败") #通过assert判断是否为error,体现在报告中 self.assertFalse(email_error,'case执行了') #返回true 不等于 false ,输出'case执行了' def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 'ss', '111111', self.file_name) #if username_error == True: #print("注册成功了,此条case执行失败") self.assertFalse(username_error) def test_login_code_error(self): code_error = self.login.login_code_error('*****@*****.**', 'ss1111', '111111', self.file_name) #if code_error == True: #print("注册成功了,此条case执行失败") self.assertFalse(code_error) def test_login_password_error(self): password_error = self.login.login_password_error('*****@*****.**', 'ss1111', '111', self.file_name) #if password_error == True: #print("注册成功了,此条case执行失败") self.assertFalse(password_error) def test_login_success(self): success = self.login.user_base('*****@*****.**', 'ss1111', '111111', self.file_name) #if self.login.register_success() == True: #print("注册成功") self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): # cls.log = UserLog() # cls.logger = cls.log.get_log() cls.file_name = code_img_path # get_log cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.driver = webdriver.Chrome(executable_path=driver_path) self.driver.get('http://www.5itest.cn/register') self.logger.info("this is chrome") self.driver.maximize_window() self.login = RegisterBusiness(self.driver) def tearDown(self): # self.driver.save_screenshot() time.sleep(2) # sys.exc_info()[0]: for method_name, error in self._outcome.errors: if error: # caseの名前を取得 case_name = self._testMethodName # file_path = os.path.abspath(os.path.join(os.getcwd(), "..")) + r"\report\%s.png" % case_name file_path = r"report\%s.png" % case_name self.driver.save_screenshot(file_path) self.driver.close() self.driver.quit() @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error('*****@*****.**', '111', '111', 'tets') self.assertFalse(email_error, 'case実行') # if email_error is True: # print("ログイン成功,case失敗") # assertでエラーかどうかの判断をする def test_login_username_error(self): username_error = self.login.login_name_error('*****@*****.**', 'ss', '111111', self.file_name) self.assertFalse(username_error) # if username_error is True: # print("新規成功,case失敗") def test_login_code_error(self): code_error = self.login.login_name_error('*****@*****.**', 'ss22', '111111', 'xxxx') self.assertFalse(code_error) # if code_error is True: # print("新規成功,case失敗") def test_login_password_error(self): password_error = self.login.login_name_error('*****@*****.**', 'ss22', '1111', self.file_name) self.assertFalse(password_error) # if password_error is True: # print("新規成功,case失敗") def test_login_success(self): success = self.login.user_base('*****@*****.**', 'sss22', '111111', self.file_name) self.assertFalse(success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.file_name = r"E:\Users\dongf\PycharmProjects\BaiDeom\case\report\test001.png" cls.log = UserLog() cls.logger = cls.log.get_log() def setUp(self): self.driver = webdriver.Chrome() self.driver.get("http://www.5itest.cn/register?goto=/") self.logger.info("这个是日志") self.login = RegisterBusiness(self.driver) def tearDown(self): sleep(2) 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) self.driver.close() print("这个是case的后置条件") # 邮箱、用户名,密码,验证码、错误定位信息元素、错误定位信息 @classmethod def tearDownClass(cls): cls.log.close_handle() def test_login_email_error(self): email_error = self.login.login_email_error("456", "d123456", "df123456", self.file_name) self.assertFalse(email_error, "case失败") # if email_error == True: # print("注册成功,此条case失败") def test_login_username_error(self): name_error = self.login.login_name_error("*****@*****.**", "f12345", "123456", self.file_name) self.assertFalse(name_error) # if name_error == True: # print("注册成功,此条case失败") def test_login_password_error(self): password_error = self.login.login_password_error( "*****@*****.**", "d123456", "1234567", self.file_name) self.assertFalse(password_error) # if password_error == True: # print("注册成功,此条case失败") def test_login_code_error(self): code_error = self.login.login_code_error("*****@*****.**", "d12345678", "df1234567", self.file_name) self.assertFalse(code_error) # if code_error == True: # print("注册成功,此条case失败") def test_login_success(self): test_success = self.login.user_base("*****@*****.**", "de123456", "dgf123456", self.file_name) success = self.login.error_base() self.assertFalse(test_success)
class FirstCase(unittest.TestCase): @classmethod def setUpClass(cls): cls.user_log = UserLog() cls.log = cls.user_log.get_log() @classmethod def tearDownClass(cls): cls.user_log.close_handle() def setUp(self): warnings.simplefilter('ignore', ResourceWarning) self.driver = webdriver.Chrome() self.driver.get('http://www.5itest.cn/register') self.log.info("This is chrome") self.driver.maximize_window() time.sleep(3) self.re_business = RegisterBusiness(self.driver) self.file_code = base_path + '/Image/test001.png' def tearDown(self): time.sleep(3) # 失败截图 for method_name, error in self._outcome.errors: if error: case_name = self._testMethodName image_path = os.path.join(base_path + '/report/' + case_name + '.png') self.driver.save_screenshot(image_path) self.driver.close() # 邮箱,用户名,密码,验证码,错误信息定位元素,错误提示信息 def test_login_email_error(self): email_error = self.re_business.login_email_error( '*****@*****.**', '12', '66', self.file_code) self.assertFalse(email_error, '测试失败') ''' if email_error == True: print("email_error注册成功,此条case执行失败") else: print("email_error测试成功") ''' def test_login_username_error(self): name_error = self.re_business.login_name_error('55', '12222', '66', self.file_code) self.assertFalse(name_error) ''' if name_error == True: print("name_error注册成功,此条case执行失败") else: print("name_error测试成功") ''' def test_login_pwd_error(self): pwd_error = self.re_business.login_pwd_error('55', '12222', '666666', self.file_code) if pwd_error == True: print("pwd_error注册成功,此条case执行失败") else: print("pwd_error测试成功") def test_login_code_error(self): code_error = self.re_business.login_code_error('55', '12222', '66', self.file_code) if code_error == True: print("code_error注册成功,此条case执行失败") else: print("code_error测试成功") def test_login_success(self): self.re_business.user_base('3640', '12222', '66', '99') if self.re_business.register_success() == True: print("注册成功,此条case执行成功") else: print("注册失败")