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, name, pwd, code, is_suc): Page.get_login().login(name, pwd, code) time.sleep(3) if is_suc: assert Page.get_login().page_exits_text("系统后台") # 点击退出 Page.get_login().close_tp() time.sleep(10) else: assert Page.get_login().page_exits_text("账号密码不正确")
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, 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()
from Base.page import Page Page.get_login().login("admin", "123456", 8888) assert Page.get_login().page_exits_text("系统后台")
from selenium.webdriver.common.by import By from Base.page import Page # 首页关闭更新 Page.get_home().close_update() # 首页 -我的 Page.get_home().click_my_btn() # 个人中心 -登录注册 Page.get_person().click_login_sigin() # 登录操作 Page.get_login().login("13488834010", "159357") # # 定位提示消息 # mess_xpath = (By.XPATH, "//*[contains(@text,'错误')]") # # 任意页面类都继承了Base类 所以可以调用Base类方法 # message = Page.get_setting().search_ele(mess_xpath, timeout=3, poll_frequency=0.3).text print("提示消息:", Page.get_login().get_toast("错误")) # 点击返回按钮 Page.get_login().login_return() # # 登录确认按钮 # Page.get_login().login_acc() # # 个人中心 -打印用户名 # print("用户名:", Page.get_person().get_user_name()) # # 个人中心 -设置 # Page.get_person().click_setting_btn() # # 设置页面 -退出 # Page.get_setting().logout()
from selenium.webdriver.common.by import By from Base.page import Page # 首页关闭更新 Page.get_home().close_update_btn() # 首页 点击 我 Page.get_home().click_my_btn() # 注册 点击 已有账号去登陆 Page.get_sign().click_exits_account() # 登陆 Page.get_login().login("sadsad222", "159357li") # 打印提示toast消息 print("toast消息:{}".format(Page.get_login().get_app_toast("不存在"))) # 关闭登录页面 Page.get_login().close_login_page() # # 个人中心- 打印用户名 # print("用户名:{}".format(Page.get_person().get_user_name())) # # # 个人中心 -点击设置 # Page.get_person().click_setting_btn() # # # 设置页面 - 点击退出 # Page.get_setting().logout()