class TestLogin(): def setup_class(self): # 实例化 登录页面类 self.login = PageLogin(get_driver()) # 点击我 self.login.page_click_me() # 点击已有账户 self.login.page_click_info() def teardown_class(self): # 退出driver驱动 self.login.driver.quit() @pytest.mark.parametrize("username,password,expect,toast_expect", get_data()) def test_login(self, username, password, expect, toast_expect): if expect: try: # 输入用户名 self.login.page_input_user(username) # 输入密码 self.login.page_input_pwd(password) # 点击登录 self.login.page_click_login_btn() # 断言 assert expect in self.login.page_get_nickname() allure.attach("描述:", "登录成功") # 退出操作 self.login.page_login_logout() # 点击我 self.login.page_click_me() # 点击已有账户 self.login.page_click_info() except: # 截图 self.login.base_getImage() with open("./Image/faild.png", "rb") as f: allure.attach("失败描述:", f.read(), allure.attach_type.PNG) # 抛异常 raise else: try: # 输入用户名 self.login.page_input_user(username) # 输入密码 self.login.page_input_pwd(password) # 点击登录 self.login.page_click_login_btn() # 断言 assert toast_expect in self.login.base_get_toast(toast_expect) allure.attach("断言描述", "逆向断言成功") except: # 截图 self.login.base_getImage() with open("./Image/faild.png", "rb") as f: allure.attach("断言失败描述:", f.read(), allure.attach_type.PNG) # 抛异常 raise
class TestLogin(): def setup_class(self): # 实例化 登录页面类 self.login = PageLogin(get_driver()) # 点击我的 self.login.page_click_me() # 点击已有账号登录 self.login.page_click_info() def teardown_class(self): # 退出driver驱动 self.login.driver.quit() # 参数化 @pytest.mark.parametrize("username,password,expect,toast_expect", get_data()) def test_login(self, username, password, expect, toast_expect): if expect: try: # 登录操作 # self.login.page_login(username,password) self.login.page_input_user(username) self.login.page_input_pwd(password) self.login.page_click_login_btn() assert expect in self.login.page_get_nickname() allure.attach("登录状态:", "登录成功") # 退出操作 self.login.page_login_logout() self.login.page_click_me() self.login.page_click_info() except: # 截图 self.login.base_getImage() with open("./Image/failed.png", "rb") as f: allure.attach("登录失败描述:", f.read(), allure.attach_type.PNG) # 抛异常 raise else: # 登录 不能使用登录的封装(因为逆向只有第一次需要点击我的和已有账户登录) # self.login.page_login(username,password) # 以下两个操作放到setup中(以至于正向的操作 也不能使用登录和退出的封装) # self.login.page_click_me() # self.login.page_click_info() self.login.page_input_user(username) self.login.page_input_pwd(password) self.login.page_click_login_btn() try: # 断言toast assert toast_expect in self.login.base_get_toast(toast_expect) allure.attach("登录状态:", "逆向断言成功") except: # 截图 self.login.base_getImage() with open('./Image/failed.png', 'rb') as f: allure.attach("断言失败描述:", f.read(), allure.attach_type.PNG) # 抛异常 raise
class TestLogin(): def setup_class(self): self.login = PageLogin(get_driver()) self.login.page_click_me() self.login.page_click_info() def teardown_class(self): self.login.driver.quit() @pytest.mark.parametrize("username,password,expect,toast_expect", get_data()) def test_login(self, username, password, expect, toast_expect): if expect: try: self.login.page_input_user(username) self.login.page_input_pwd(password) self.login.page_click_login_btn() assert expect in self.login.page_get_nickname() allure.attach("登录状态:","登陆成功") self.login.page_login_logout() self.login.page_click_me() self.login.page_click_info() except: # 截图 self.login.base_getImage() with open("./Image/faild.png", "rb") as f: allure.attach("失败描述", f.read(), allure.attach_type.PNG) raise else: try: self.login.page_input_user(username) self.login.page_input_pwd(password) self.login.page_click_login_btn() assert toast_expect in self.login.base_get_toast(toast_expect) allure.attach("登录状态:", "逆向断言成功") except: # 截图 self.login.base_getImage() with open("./Image/faild.png", "rb") as f: allure.attach("失败描述", f.read(), allure.attach_type.PNG) raise
class TestLogin(): def setup_class(self): self.login=PageLogin(get_driver()) self.login.page_click_me() self.login.page_click_info() def teardown_class(self): self.login.driver.quit() @pytest.mark.parametrize(("username,password,expect,toast_expect"),get_data()) def test_login(self,username,password,expect,toast_expect): # 默认为TRUE,如果expect为TRUE代表有值也就是正向用例,需要进行以下操作 # 通过模拟功能测试得出思路 if expect: # 进行异常捕获 try: # 输入用户名 self.login.page_input_username(username) # 输入密码 self.login.page_input_pwd(password) # 点击登录 self.login.page_click_dl_btn() # 断言登录后的名称 assert expect in self.login.page_get_nickname() allure.attach("登录状态: ","登录成功") # 退出登录 self.login.page_exit() # 点击我的 self.login.page_click_me() # 点击已有账户立即登录 self.login.page_click_info() # 如果出现异常就截图保存 except: # 调用截图方法 self.login.base_get_screenshot() # 打开截图 with open("./Image/filed.png","rb") as f: # 写入报告中,三个参数:描述,读取文件,写入报告格式声明 png allure.attach("登录失败描述",f.read(),allure.attach_type.PNG) raise # 相反也就是expect为空,对应的就是逆向,需要执行的操作 else: try: # 输入用户名 self.login.page_input_username(username) # 输入密码: self.login.page_input_pwd(password) # 点击登录 self.login.page_click_dl_btn() # 断言toast_expect消息 # 调用获取toast消息方法,动态判断登录后的是否相等 assert toast_expect in self.login.base_get_toast(toast_expect) allure.attach("登录状态","逆向断言成功") except: self.login.base_get_screenshot() with open("./Image/filed.png","rb") as f : allure.attach("登录失败描述",f.read(),allure.attach_type.PNG) raise