class Test_001: def setup_class(self): self.page_obj = Page(get_driver()) self.page_obj.get_login_page().if_login() def teardown_class(self): self.page_obj.driver.quit() @pytest.mark.run(order=1) def test_add_addr(self): # 点击收货地址,新增收货地址 self.page_obj.get_user_addr_page().click_addr_btn() # 添加用户名 self.page_obj.get_user_addr_page().addr_name() # 添加手机号 self.page_obj.get_user_addr_page().addr_phone() # 选择所在地区 self.page_obj.get_user_addr_page().addr_area() # 添加详细地址 self.page_obj.get_user_addr_page().addr_detail() # 勾选默认地址 self.page_obj.get_user_addr_page().addr_default() # 保存收货地址 self.page_obj.get_user_addr_page().addr_save_btn() assert self.page_obj.get_user_addr_page().get_recive_address() assert self.page_obj.get_user_addr_page().get_addr_default() @pytest.mark.run(order=3) def test_delete_addr(self): self.page_obj.get_user_addr_page().update_addr_btn() self.page_obj.get_user_addr_page().delete_addr() assert "删除成功" == self.page_obj.get_user_addr_page().find_toast("删除") assert not self.page_obj.get_user_addr_page().get_recive_address() @pytest.mark.run(order=2) def test_update_addr(self): # 修改收货地址 self.page_obj.get_user_addr_page().update_addr_btn() self.page_obj.get_user_addr_page().addr_name(name="1234") self.page_obj.get_user_addr_page().addr_default() self.page_obj.get_user_addr_page().addr_save_btn() assert self.page_obj.get_user_addr_page().get_recive_address() assert "编辑成功" == self.page_obj.get_user_addr_page().find_toast("编辑") assert not self.page_obj.get_user_addr_page().get_addr_default()
class Test_01: def setup_class(self): # 实例化统一入口类 self.page_obj = Page(get_driver()) def teardown_class(self): self.page_obj.driver.quit() def get_ph(self): img_name = './phtot/%d.png' % int(time.time()) self.page_obj.driver.get_sereenshot_as_file(img_name) with open(img_name, 'rb') as f: allure.attach("sd", f.read(), allure.attach_type.PNG) def test_01(self): self.page_obj.get_login_page().click_my_btn() assert 0, self.get_ph() def test_02(self): assert 0, self.get_ph()
class Test_Login: def setup_class(self): self.page_obj = Page(get_driver()) # 点击我的 self.page_obj.get_login_page().click_my_btn() def teardown_class(self): self.page_obj.driver.quit() @pytest.mark.parametrize("username,passwd,expectx,expect_toast,get_msg",get_login_data()) def test_login(self, username,passwd,expectx,expect_toast,get_msg): # 点击登陆/注册 self.page_obj.get_login_page().click_insert_login() # 登陆操作 self.page_obj.get_login_page().login(username, passwd) if expectx: try: # 登陆成功toast消息 suc_msg = self.page_obj.get_login_page().find_toast(get_msg) # 获取我的订单按钮是否存在 成功返回True 不成功返回False suc_status = self.page_obj.get_login_page().get_suc_login_status() # 断言成功/失败 assert suc_msg == expect_toast and suc_status # 退出操作 # 点击个人中心设置 self.page_obj.get_setting_page().click_setting_btn() # 点击退出登录按钮 self.page_obj.get_setting_page().click_logout_btn() except: # 点击登陆页面关闭按钮 self.page_obj.get_login_page().login_faile_x() assert False else: # 获取toast消息 reslut_msg = self.page_obj.get_login_page().find_toast(get_msg) # 点击登陆页面关闭按钮 self.page_obj.get_login_page().login_faile_x() assert expect_toast == reslut_msg
class Test_01: def setup_class(self): self.Page_obj = Page(get_driver("com.tpshop.malls", ".SPMainActivity")) self.Page_obj.get_login_page().click_my_btn() def teardown_class(self): self.Page_obj.driver.quit() @allure.step("执行测试用例") @pytest.mark.parametrize( "case_num, username, passwd,get_mess,expect_message, tag", get_data()) def test_01_1(self, case_num, username, passwd, get_mess, expect_message, tag): self.Page_obj.get_login_page().click_sign_btn() self.Page_obj.get_login_page().input_mess(username, passwd) self.Page_obj.get_login_page().click_login_btn() if tag: try: order_status = self.Page_obj.get_login_page( ).if_my_order_status() toast = self.Page_obj.get_login_page().get_toast(get_mess) self.Page_obj.get_login_page().click_setting_btn() self.Page_obj.get_setting_page().clcik_exit_btn() assert order_status and toast == expect_message except Exception as e: print(e) self.Page_obj.get_login_page().click_close() assert False else: try: toast = self.Page_obj.get_login_page().get_toast(get_mess) if toast: assert toast == expect_message else: assert False finally: self.Page_obj.get_login_page().click_close()
class Test_Add_Address(): def setup_class(self): self.pag_obj = Page(get_driver()) # 判断是否登陆 self.pag_obj.get_login_page().if_login() def teardown_class(self): self.pag_obj.driver.quit() @pytest.mark.run(order=3) @pytest.mark.parametrize("name, get_toast, expect_toast", data_list().get("del_data")) def test_delete_addr(self, name, get_toast, expect_toast): # 删除已添加地址 # 地址编辑按钮 self.pag_obj.get_add_addr_page().edit_address() # 点击删除 self.pag_obj.get_add_addr_page().delete_address() # 判断toast消息 assert expect_toast == self.pag_obj.get_add_addr_page().find_toast( get_toast) # 判断列表收货人不包含某个用户名 assert not self.pag_obj.get_add_addr_page().if_addr_name() @pytest.mark.run(order=2) @pytest.mark.parametrize("name, get_toast, expect_toast", data_list().get("edit_data")) def test_edit_address(self, name, get_toast, expect_toast): # 修改收货人 和 取消默认 self.pag_obj.get_add_addr_page().edit_address() # 修改收货人 self.pag_obj.get_add_addr_page().add_recv_name(name) # 关闭默认开关 self.pag_obj.get_add_addr_page().click_default_btn() # 点击保存按钮 self.pag_obj.get_add_addr_page().click_addr_save() # 判断toast消息 assert expect_toast == self.pag_obj.get_add_addr_page().find_toast( get_toast) # 判断收货人 assert name in self.pag_obj.get_add_addr_page().if_addr_name() # 判断默认消失 assert not self.pag_obj.get_add_addr_page().if_addr_default() @pytest.mark.run(order=1) @pytest.mark.parametrize( "name,phone,detail,get_toast,expect_toast,expect_default", data_list().get("add_data")) def test_add_address(self, name, phone, detail, get_toast, expect_toast, expect_default): # 点击收货地址 self.pag_obj.get_add_addr_page().click_recv_addr() # 点击新建地址 self.pag_obj.get_add_addr_page().new_address() # 输入收货人 self.pag_obj.get_add_addr_page().add_recv_name(name) # 输入手机号 self.pag_obj.get_add_addr_page().add_recv_phone(phone) # 选择所在地区 self.pag_obj.get_add_addr_page().add_recv_change_area() # 输入详细地址 self.pag_obj.get_add_addr_page().add_recv_detail(detail) # 点击保存新增地址 self.pag_obj.get_add_addr_page().click_addr_save() # 判断添加成功提示 assert expect_toast == self.pag_obj.get_add_addr_page().find_toast( get_toast) # 判断收货人姓名 assert name in self.pag_obj.get_add_addr_page().if_addr_name() # 判断默认 assert expect_default in self.pag_obj.get_add_addr_page( ).if_addr_default()
class Test_login: def setup_class(self): # self.obj = Login_Page(get_driver()) # # 点击我的 # self.obj.click_btn() self.page_obj = Page(get_driver()) #点击我的 self.page_obj.get_login_page().click_btn() def teardown_class(self): self.page_obj.driver.quit() @pytest.mark.parametrize( 'test_login_num,username,passwd,get_mess,expect_message,tag', get_data()) def test_login(self, test_login_num, username, passwd, get_mess, expect_message, tag): # 点击登录注册 self.page_obj.get_login_page().click_login_sign_btn() self.page_obj.get_login_page().input_phone(username, passwd) # 分两种去情况 我的订单 和登录失败 # 输入手机号 密码 点击登录 # 输入正确的手机号和密码 if tag: try: # 断言是否登录成功和是否有 我的订单内容 login_toast = self.page_obj.get_login_page().get_toast( get_mess) login_status = self.page_obj.get_login_page( ).if_my_order_status() #点击设置 self.page_obj.get_login_page().click_setting_btn() # 退出登录 点击安全退出 self.page_obj.setting_page().safe_logout() assert login_toast == expect_message and login_status except Exception as e: self.page_obj.get_login_page().get_screen_01() assert False finally: # 点击 登录页面的关闭按钮 self.page_obj.get_login_page().quit_login_page() else: try: mess = self.page_obj.get_login_page().get_toast(get_mess) if mess: assert mess == expect_message else: self.page_obj.get_login_page().get_screen_01() assert False finally: self.page_obj.get_login_page().quit_login_page()
class Test_Login: def setup_class(self): # 实例化统一入口类 self.page_obj = Page(get_driver()) self.page_obj.get_login_page().click_my_btn() def teardown_class(self): self.page_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 标记登陆成功用例 :return: """ # 点击登陆注册 self.page_obj.get_login_page().click_login_sign_btn() # 登陆操作 self.page_obj.get_login_page().login_input_page(username, passwd) if tag: try: # 获取登陆成功toast suc_msg = self.page_obj.get_login_page().get_toast(get_mess) # 获取我的订单状态 order_status = self.page_obj.get_login_page( ).if_my_order_status() # 退出登录 self.page_obj.get_setting_page().logout_page() assert suc_msg == expect_message and order_status except Exception as e: # 关闭登陆信息输入页面 self.page_obj.get_login_page().login_close_page() assert False else: try: # 获取登陆失败toast消息 fail_msg = self.page_obj.get_login_page().get_toast(get_mess) if fail_msg: assert fail_msg == expect_message else: assert False finally: self.page_obj.get_login_page().login_close_page()
class TestLLogin(object): def setup_class(self): """初始化对象""" self.driver = get_phone_driver( 'com.yunmall.lc', 'com.yunmall.ymctoc.ui.activity.MainActivity') self.page_obj = Page(self.driver) def teardown_class(self): self.driver.quit() @pytest.fixture(autouse=True) def into_login_page(self): """点击首页'我',跳转至注册页面""" self.page_obj.get_index_page().go_to_sign_page() """点击"已账号",跳转至登录页面""" self.page_obj.get_sign_page().go_to_login_page() @pytest.mark.parametrize("login_num,name,password,exp", get_login_data().get("success")) def test_success_login(self, login_num, name, password, exp): """打印测试数据顺序""" print("这是用例测试:", login_num) """点击首页'我',跳转至注册页面""" self.page_obj.get_index_page().go_to_sign_page() """点击"已账号",跳转至登录页面""" self.page_obj.get_sign_page().go_to_login_page() """输入信息,点击登录,跳转至个人页面""" self.page_obj.get_login_page().login(name, password) """进行断言,点击设置,跳转至设置页面""" try: """断言成功""" res = self.page_obj.get_person_page().get_login_success_result() try: assert res in exp except AssertionError: """在个人中心,但没有'exp'""" """截图""" self.page_obj.get_person_page().screen_shot() assert False finally: """点击设置""" self.page_obj.get_person_page().go_to_setting_page() """执行退出操作`""" self.page_obj.get_setting_page().scroll_screen_in_setting(1) self.page_obj.get_setting_page().click_login_out_btn(1) except TimeoutException: """断言失败""" """还停留在登录页面""" self.page_obj.get_person_page().screen_shot() # 截图 """需要执行退出登录页面,以便于进行下面的测试""" self.page_obj.get_login_page().close_login_page() @pytest.mark.parametrize("login_num,name,password,toast,exp", get_login_data().get("fail")) def test_fail_login(self, login_num, name, password, toast, exp): print("这是测试用例", login_num) """输入信息,点击登录,跳转至个人页面""" self.page_obj.get_login_page().login(name, password) """进行断言""" try: """能获取toast信息""" message = self.page_obj.get_login_page().get_toast(toast) try: assert message == exp except AssertionError: """截图""" self.page_obj.get_login_page().screen_shot() assert False finally: try: """判断登录按钮在不在""" assert self.page_obj.get_login_page().if_login_btn() """在,就关闭登录页面""" self.page_obj.get_login_page().close_login_page() except AssertionError: """不在,就可能在个人页面""" """截图""" self.page_obj.get_login_page().screen_shot() """点击设置""" self.page_obj.get_person_page().go_to_setting_page() """执行退出操作`""" self.page_obj.get_setting_page().click_login_out_btn(1) assert False except TimeoutException: """不能获取到toast消息""" try: """对登录按钮进行判断""" self.page_obj.get_login_page().if_login_btn() # 登录按钮在,表示在登录页面 self.page_obj.get_login_page().close_login_page() # 关闭登录页面 except TimeoutException: self.page_obj.get_person_page().go_to_setting_page() # 点击设置 self.page_obj.get_setting_page().click_login_out_btn( ) # 执行退出操作 assert False
class TestLogin: def setup_class(self): # 实例化统一入口类 self.page_obj = Page( get_android_driver("com.yunmall.lc", "com.yunmall.ymctoc.ui.activity.MainActivity")) def teardown_class(self): # 退出driver self.page_obj.driver.quit() @pytest.fixture(autouse=True) def goto_login(self): """进入登录页面""" # 点击我 self.page_obj.get_home_page().click_my_btn() # 点击已有账号去登录 self.page_obj.get_chocie_login_page().click_exits_account_btn() @pytest.mark.parametrize("case_num, username, passwd, expect_data", get_login_data().get("suc")) def test_login_suc(self, case_num, username, passwd, expect_data): """ 预期成功测试用例 :param case_num: 用例编号 :param username: 用户名 :param passwd: 密码 :param expect_data: 预期结果 :return: """ # 登录 self.page_obj.get_login_page().login(username, passwd) try: # 获取收藏 cart_text = self.page_obj.get_person_page().get_shop_cart_text() try: # 断言 assert cart_text == expect_data except AssertionError: # 断言失败异常 """个人中心""" # 截图 self.page_obj.get_person_page().screen_shot() assert False finally: # 点击设置 self.page_obj.get_person_page().click_setting_btn() # 退出操作 self.page_obj.get_setting_page().logout() except TimeoutException: """停留在登录页面""" # 截图 self.page_obj.get_setting_page().screen_shot() # 关闭页面 self.page_obj.get_login_page().close_login_page() assert False @pytest.mark.parametrize("case_num, username, passwd,toast,expect_data", get_login_data().get("fail")) def test_login_fail(self, case_num, username, passwd, toast, expect_data): """ 预期失败测试用例 :param case_num: 用例编号 :param username: 用户名 :param passwd: 密码 :param toast: xpath拼接语句 :param expect_data: 预期结果 :return: """ # 登录操作 self.page_obj.get_login_page().login(username, passwd) try: """找到toast""" # 获取toast 消息 message = self.page_obj.get_login_page().get_toast(toast) try: # 断言 assert message == expect_data except AssertionError: # 截图 self.page_obj.get_login_page().screen_shot() assert False except TimeoutException: """没找到toast 消息""" # 截图 self.page_obj.get_login_page().screen_shot() assert False finally: try: """登录按钮存在""" # 判断登录按钮 self.page_obj.get_login_page().if_login_btn() # 关闭登录页面 self.page_obj.get_login_page().close_login_page() except TimeoutException: """登录按钮不存在""" # 点击设置 self.page_obj.get_person_page().click_setting_btn() # 退出操作 self.page_obj.get_setting_page().logout() # 找不到登录按钮 全失败 assert False