class TestSearch: def setup_class(self): # 声明driver self.driver = get_android_driver('com.android.settings', '.Settings') # 实例化统一入口页面类 self.page_obj = Page(self.driver) def teardown_class(self): """退出driver""" self.driver.quit() @pytest.fixture(scope="class", autouse=True) def click_search(self): """点击搜索按钮 依赖一次""" self.page_obj.get_setting().click_search_btn() @pytest.mark.parametrize("search, expdata", search_data()) def test_search(self, search, expdata): """ 搜索测试 :param search: 搜索内容 :param expdata: 搜索预期结果 :return: """ # # 定位搜索输入框 self.page_obj.get_search().search_text(search) # 断言 assert expdata in self.page_obj.get_search().get_search_result()
def test_login(self, name, pwd, toast, exp): """ 测试方法 :param name: 账号 :param pwd: 密码 :param toast: toast拼接文本 :param exp: 预期结果 :return: """ # 登录 Page.get_login().login(name, pwd) # 判断 if toast: """预期失败用例""" # 获取toast消息 message = Page.get_login().get_toast(toast) try: # 断言toast消息 assert message == exp except AssertionError: # AssertionError断言失败异常 # 截图 Page.get_setting().screen_image() # 抛出异常 raise finally: # 点击返回按钮 Page.get_login().login_return_btn() else: """预期通过数据""" # 登录确认按钮 Page.get_login().login_acc_btn() # 获取用户名 user_name = Page.get_person().get_user_name() try: # 断言 assert user_name == exp except AssertionError: # 截图 Page.get_setting().screen_image() # 抛出异常 raise finally: # 点击设置 Page.get_person().click_setting_btn() # 点击退出 Page.get_setting().logout()
def test_login(self, desc, account, password, toast, exp): """ 登录测试方法 :param desc: 用例描述 :param account: 账号 :param password: 密码 :param toast: 获取toast拼接关键文本 :param exp: 预期结果 :return: """ logging.info("用例类型:{}".format(desc)) # 登录 Page.get_login().login(account, password) if toast: # 逆向数据 # 获取toast消息 message = Page.get_login().get_app_toast(toast) try: # 断言 assert message == exp except AssertionError as e: # 断言失败异常AssertionError # 截图 Page.get_setting().screenshot() # 抛出异常 raise e finally: # 关闭登陆页面 Page.get_login().close_login_page() else: # 正向数据 # 获取用户名 user_name = Page.get_person().get_user_name() try: # 断言 assert user_name == exp except AssertionError as e: # 捕获断言失败异常 # 截图 Page.get_setting().screenshot() # 抛出异常 raise e finally: # 点击设置 Page.get_person().click_setting_btn() # 退出 Page.get_setting().logout()
def test_login(self, phone, passwd, toast, exp): """ 测试方法 :param phone: 手机号 :param passwd: 密码 :param toast: toast拼接xpath :param exp: 预期结果 :return: """ # 登录 Page.get_login().login(phone, passwd) if toast: """预期失败用例""" # 获取toast提示消息 message = Page.get_login().get_toast(toast) try: # 断言 assert message == exp except AssertionError as e: # 断言失败异常 # 截图 Page.get_setting().screen_png() # 抛出断言失败异常 raise e finally: # 点击返回按钮 Page.get_login().login_return() else: """预期成功用例""" # 点击登录确认 Page.get_login().login_acc() # 获取用户名 username = Page.get_person().get_user_name() try: # 断言 assert username == exp except AssertionError as e: # 截图 Page.get_setting().screen_png() # 抛出断言失败异常 raise e finally: # 点击设置 Page.get_person().click_setting_btn() # 退出操作 Page.get_setting().logout()
def setup_class(self): """点击搜索按钮""" Page.get_setting().click_search_btn()