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): # 实例化 统一入口类 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
class TestAddress(): def setup_class(self): # 实例化统一入口类,调用登陆方法 PageIn().page_get_pagelogin().page_login_and_setting() # 获取页面地址对象 self.address = PageIn().page_get_pageaddress() def teardown_class(self): # 关闭driver self.address.driver.quit() # 新增地址方法 @allure.step("开始新增地址操作") @pytest.mark.run(order=1) @pytest.mark.parametrize("name, phone, sheng, shi, qu, info_address, code", get_data("add")) def test_address(self, name, phone, sheng, shi, qu, info_address, code): # 地址管理 self.address.page_click_address() # 点击新增地址 self.address.page_click_new_address() # 收件人 self.address.page_input_receipt_name(name) # 电话 self.address.page_input_phone(phone) # 点击地址封装 self.address.page_click_Area_sheng_shi_qu(sheng, shi, qu) # 输入详细地址 self.address.page_input_info(info_address) # 输入邮编 self.address.page_input_post_code(code) # 设为默认按钮 self.address.page_click_default_btn() # 点击保存 self.address.page_click_save() try: expect_result = name + " " + phone assert expect_result in self.address.page_get_list_name_and_phone() except: # 截图 self.address.base_getImage() # 打开图片写入报告 with open("./Image/faild.png", "rb") as f: allure.attach("失败原因请附图:", f.read(), allure.attach_type.PNG) # 抛出异常 raise # 修改地址方法 @allure.step("开始修改地址操作") @pytest.mark.run(order=2) @pytest.mark.parametrize("name,phone,sheng,shi,qu,info_address,code", get_data("updata")) def test_updata_address(self, name, phone, sheng, shi, qu, info_address, code): self.address.page_click_edit_btn() # 点击修改 self.address.page_click_list_elements("修改") # 输入收件人 self.address.page_input_receipt_name(name) # 收入手机号 self.address.page_input_phone(phone) # 所在地区 self.address.page_click_Area_sheng_shi_qu(sheng, shi, qu) # 详细地址 self.address.page_input_info(info_address) # 邮编 self.address.page_input_post_code(code) # 保存 self.address.page_click_save() # 断言 try: # 拼接 收件+电话 格式:"xxx 18600001111" expect_result = name + " " + phone assert expect_result in self.address.page_get_list_name_and_phone() except: # 截图 self.address.base_getImage() # 打开图片 并写入报告 with open("./Image/faild.png", "rb") as f: allure.attach("失败原因请附件图:", f.read(), allure.attach_type.PNG) # 将捕获的异常 抛出 raise # 删除地址的方法 @allure.step("开始删除地址操作") @pytest.mark.run(order=3) def test_delete_address(self): if self.address.page_address_manage_is_exist(): # 点击地址管理 self.address.page_click_address_manage() # # 点击编辑 # self.address.page_click_edit_btn() # # 点击删除 # self.address.page_click_list_elements("删除") # # 确认删除 # self.address.page_delete_ok() # 删除所有地址 self.address.page_delete_all_address() try: # 断言地列表是否还存在地址 assert self.address.page_get_address_list_is_exist() except: # 截图 self.address.base_getImage() # 打开图片 并写入报告 with open("./Image/faild.png", "rb") as f: allure.attach("失败原因请附件图:", f.read(), allure.attach_type.PNG) # 将捕获的异常 抛出 raise