class Test_Log(object): def setup_class(self): """ 点击我的 :return: """ self.obj_page = Login_Page( get_driver('com.tpshop.malls', '.SPMainActivity')) self.obj_page.click_my_btn_page() def teardown_class(self): """ 关闭应用 :return: """ self.obj_page.driver.quit() @pytest.mark.parametrize('phone,pwd,toast_mess,expect_mess,tag', get_data()) def test_login(self, phone, pwd, toast_mess, expect_mess, tag): """ :param phone: 输入账号 :param pwd:输入密码 :param toast_mess:获取toast传参 :param expect_mess:登录后期望toast :param tag:标记执行成功测试用例 :return: """ #点击登录/注册按钮 self.obj_page.click_login_resi_page() #进入到输入手机号和密码的登录页面 #输入手机号,#输入密码 self.obj_page.input_user_pwd_page(phone, pwd) if tag: try: #获取登录成功toast消息 suc_mess = self.obj_page.get_toast(toast_mess) #获取登录成功我的订单状态 order_state = self.obj_page.if_order_page() #点击退出登录 self.obj_page.logout_page() assert suc_mess == expect_mess and order_state except Exception as e: #如果获取获取不到以上信息,就关闭登录信息输入页面 print(e) self.obj_page.person_input_close_page() else: try: #获取登录失败toast消息 fail_mess = self.obj_page.get_toast(toast_mess) if fail_mess: assert fail_mess == expect_mess else: return False finally: self.obj_page.person_input_close_page()
class Test_TP(): def setup_class(self): self.TP_driver = Login_Page(get_server_settings("com.tpshop.malls",".SPMainActivity")) #点击我的按钮 self.TP_driver.click_my_btn() def teardown_class(self): self.TP_driver.driver.quit() @pytest.mark.parametrize("num,phone,password,get_mess,xpect_message,tag",put_data()) def test_login(self,num,phone,password,get_mess,xpect_message,tag): #点击登录注册按钮 self.TP_driver.click_login_sign_btn() #登录操作 self.TP_driver.login_input_page(phone,password) if tag: try: #获取登录成功toast toast_mes = self.TP_driver.get_toast(get_mess) #获取登录后状态 status = self.TP_driver.if_my_order_status() #退出登录 self.TP_driver.logout_page() assert toast_mes == xpect_message and status except Exception as e: #退出登录信息输入页面 self.TP_driver.login_close_page() assert False else: try: #获取登录失败toast toast_fail_toast = self.TP_driver.get_toast(get_mess) if toast_fail_toast: assert toast_fail_toast == xpect_message else: assert False finally: self.TP_driver.login_close_page()
class Test_Login: def setup_class(self): # 实例化登陆对象 logger.info("调起同桌100") os.system( 'adb shell am broadcast -a com.baidu.duer.query -e q "打开同桌100"') # os.system('adb shell am broadcast -a com.baidu.duer.query -e q "退出"') os.system( 'adb shell am broadcast -a com.baidu.duer.query -e q "打开同桌100"') os.system( 'adb shell am broadcast -a com.baidu.duer.query -e q "打开同桌100"') self.LP_obj = Login_Page(get_driver()) # 点击个人中心 # sleep(5) # self.LP_obj.click_sy_login_btn() def teardown_class(self): self.LP_obj.driver.quit() @pytest.mark.parametrize( "case_num, username, passwd,get_mess,expect_message, tag", get_data()) def test_login_page(self, case_num, username, passwd, get_mess, expect_message, tag): """ :param username: 用户名 :param passwd: 密码 :param get_mess: toast传参 :param expect_message: 预期toast消息 :param tag: 1 标记登陆成功用例 2 标记账号不存在 3标记登录失败 :return: """ # 点击登陆注册 # logger.info("点击登录/注册") # self.LP_obj.click_sy_login_btn() # 登陆操作 logger.info("登录相关操作") self.LP_obj.click_sy_login_btn() self.LP_obj.login_input_page(username, passwd) if tag == 1: try: # 获取登陆成功toast logger.info("正向登录用例") suc_msg = self.LP_obj.get_toast(get_mess) logger.debug("获取登录成功toast:{}".format(suc_msg)) # 退出登录 self.LP_obj.logout_page() assert suc_msg == expect_message logger.success("断言成功{}=={}".format(suc_msg, expect_message)) except Exception as e: # 捕获异常信息+截图 self.LP_obj.error_dispose(e) # 关闭登录信息输入页面 self.LP_obj.login_back_page() assert False elif tag == 2: try: logger.debug("登录不存在的账号用例") # 获取登陆成功toast suc_msg = self.LP_obj.get_toast(get_mess) logger.debug("获取账号不存在toast:{}".format(suc_msg)) # 退出登录 self.LP_obj.login_close_page() assert suc_msg == expect_message logger.success("断言成功{}=={}".format(suc_msg, expect_message)) except Exception as e: # 捕获异常信息+截图 self.LP_obj.error_dispose(e) assert False elif tag == 3: logger.debug("账号或密码错误用例") try: # 获取登陆失败toast消息 fail_msg = self.LP_obj.get_toast(get_mess) logger.debug("登录失败toast:{}".format(fail_msg)) if fail_msg: assert fail_msg == expect_message logger.success("断言成功:{}=={}".format( fail_msg, expect_message)) else: assert False self.LP_obj.login_back_page() except Exception as e: # 捕获异常信息+截图 self.LP_obj.error_dispose(e) sleep(3) assert False