Exemplo n.º 1
0
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()
                #退出操作
                self.login.page_login_logout()
                #点击我
                self.login.page_click_me()
                #点击已有账户,去登录
                self.login.page_input_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)
                except:
                    #截屏
                    self.login.base_getImage()
                    with open("./Image/faild.png","rb")as f:
                        allure.attach("失败描述:",f.read(),allure.attach_type.PNG)
                        allure.attach("描述:","登陆失败")
                    #抛出异常
                    raise
Exemplo n.º 2
0
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