class TestLogin(): def setup_class(self): # 实例化 登录页面类 self.login = PageIn(get_driver()).page_get_login() # 点击我 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) allure.attach("描述:", "登录失败!") # 抛异常 raise else: try: # 输入用户名 self.login.page_input_user(username) # 输入密码 self.login.page_input_pwd(password) # 点击登录 self.login.page_click_login_btn() # 断言toast消息 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): # ------ 实例化 PageLogin # self.login = PageLogin(get_driver()) # self.toast = PageToast(get_driver()) self.login = PageIn().page_get_login() self.toast = PageIn().page_get_toast() # self.login.page_click_skip() self.login.page_click_me() self.login.page_click_go_login() # 结束方法 def teardown_class(self): # 关闭驱动对象 # self.driver.quit() self.login.driver.quit() # @pytest.mark.parametrize("username,pwd",[("*****@*****.**", "123456"),("*****@*****.**","222222")]) # @allure.step("登录测试") # @allure.severity(allure.severity_level.CRITICAL) # @pytest.mark.parametrize("username, pwd, nickname", [("18339052997", "Zz0103", "lq_0223094916_yxe"), (" 1833", "22222", "此用户不存在")]) # --- 以yaml读取 @pytest.mark.parametrize("username, pwd, expect_resoult, expect_toast", get_yaml_data()) # 以txt读取 # @pytest.mark.parametrize("username, pwd, expect_resoult, expect_toast", get_txt_data()) def test_login(self, username, pwd, expect_resoult, expect_toast): if expect_resoult: try: self.login.page_input_username(username) self.login.page_input_password(pwd) self.login.page_click_login_btn() assert expect_resoult in self.login.page_get_self_name() self.login.page_click_setting() self.login.page_drag_and_drop() self.login.page_click_loginout() self.login.page_click_loginout_ok() self.login.page_click_me() self.login.page_click_go_login() except: self.login.base_get_iamge() raise else: try: self.login.page_input_username(username) self.login.page_input_password(pwd) self.login.page_click_login_btn() assert expect_toast in self.login.base_get_toast(expect_toast) except: self.login.base_get_iamge() raise
class TestLogin(): def setup_class(self): # 实例化 统一入口类 self.login = PageIn().page_get_pagelogin() # 点击 我 self.login.page_click_me() # 点击 已有账号,去登录 self.login.page_click_user_link() def teardown_class(self): # 退出 driver self.login.driver.quit() # @pytest.mark.parametrize("username,password,expect_result,expect_toast",get_data()) # 以txt形式去读取 @pytest.mark.parametrize("username,password,expect_result,expect_toast", get_data_txt()) @allure.step('我是test_login') def test_login(self, username, password, expect_result, expect_toast): if expect_result: try: # 输入 用户名 self.login.page_input_username(username) # 输入 密码 self.login.page_input_password(password) # 点击 登录 self.login.page_click_login_btn() # 获取 昵称 进行断言 assert expect_result in self.login.page_get_nickname() # 点击 设置 self.login.page_click_setting() # 拖拽 消息推送--》修改密码 self.login.page_drag_and_drop() # 点击退出 self.login.page_click_logout() # 确认退出 self.login.page_click_logout_ok() # 点击 我 self.login.page_click_me() # 点击 已有账号,去登录 self.login.page_click_user_link() except: # 截图 self.login.base_getImage() raise else: try: # 输入 用户名 self.login.page_input_username(username) # 输入 密码 self.login.page_input_password(password) # 点击 登录 self.login.page_click_login_btn() # 断言 assert expect_toast == self.login.base_get_toast(expect_toast) except: # 截图 self.login.base_getImage() # 打开图片写入报告 with open("./Image/faild.png", "rb") as f: allure.attach("失败原因请附图:", f.read(), allure.attach_type.PNG) # 抛出异常 raise