예제 #1
0
class TestAddress02():
    def setup_class(self):
        self.page = PageIn(get_driver())
        self.page.page_get_login().page_login("13805489414", "123456")
        #点击设置
        self.page.page_get_login().page_click_setting()
        #点击地址管理
        self.address = self.page.page_get_setting()
        self.address.page_address_manage()

    def teardown_class(self):
        self.page.driver.quit()

    """新增"""

    @pytest.mark.run(order=1)
    @pytest.mark.parametrize("name,phone,sheng,shi,qu,address,youbian",
                             get_data("add"))
    def test02_address(self, name, phone, sheng, shi, qu, address, youbian):
        addr = self.address
        #点击新增地址
        addr.page_new_address()
        #输入收件人
        addr.page_receipt_name(name)
        #输入手机号
        addr.page_add_phone(phone)
        #选择所在区域
        addr.page_address_area(sheng, shi, qu)
        #输入详细地址
        addr.page_detail_addr_info(address)
        #输入邮编
        addr.page_address_post_code(youbian)
        #设置默认地址
        addr.page_address_default()
        #点击保存
        addr.page_address_save()
        #断言,是否新增成功
        try:
            # print("获取新增地址联系人电话",addr.page_get_recipit_and_phone())
            # assert name in addr.page_get_recipit_and_phone()
            """第二种实现断言方法:所有收件和电话"""
            #组装字符串
            name_phone = name + "  " + phone
            assert name_phone in addr.page_get_elements_text()
        except:
            self.login.base_getImage()
            with open("./Image/faild.png", "rb") as f:
                allure.attach("失败描述", f.read(), allure.attach_type.PNG)
            raise

    """更新地址"""

    @pytest.mark.run(order=2)
    @pytest.mark.parametrize("name,phone,sheng,shi,qu,address,youbian,toast",
                             get_data("update"))
    def test_update_address(self, name, phone, sheng, shi, qu, address,
                            youbian, toast):
        addr = self.address
        #点击编辑
        self.address.page_click_edit_btn()
        #点击修改
        self.address.page_click_xiugai()
        #点击信息
        #输入收件人
        addr.page_receipt_name(name)
        #输入手机号
        addr.page_add_phone(phone)
        #选择所在区域
        addr.page_address_area(sheng, shi, qu)
        #输入详细地址
        addr.page_detail_addr_info(address)
        addr.page_address_post_code(youbian)
        #点击保存
        addr.page_click_baocun_btn()
        try:
            name_phone = name + "  " + phone
            assert name_phone in addr.page_get_elements_text()
            #第二种toast
            assert toast in self.address.base_get_toast(toast)
        except:
            self.login.base_getImage()
            with open("./Image/faild.png", "rb") as f:
                allure.attach("失败描述", f.read(), allure.attach_type.PNG)
            raise

    """"删除"""

    @pytest.mark.run(order=3)
    def test_delete_address(self):
        #删除操作
        self.address.page_delete_address()
        #断言
        try:
            assert self.address.page_is_delete_ok()
        except:
            self.login.base_getImage()
            with open("./Image/faild.png", "rb") as f:
                allure.attach("失败描述", f.read(), allure.attach_type.PNG)
            raise
예제 #2
0
class TestAddress():
    @allure.step("初始化操作")
    def setup_class(self):
        print("获取数据驱动的添加地址格式:", get_data("add"))
        print("获取数据驱动的编辑址格式:", get_data("edit"))
        # 获取driver
        self.driver = get_driver()
        # 获取统一入口类
        self.page = PageIn(self.driver)
        # 获取设置页面对象
        self.setting = self.page.page_get_setting()
        allure.attach("描述", "地址管理前登陆")
        # 登录 +点击设置
        self.page.page_get_login().page_login_address()
        allure.attach("描述", "点击地址管理")
        # 点击地址管理
        self.setting.page_click_address_manage()

    def teardown_class(self):
        # 关闭driver
        self.driver.quit()

    @pytest.mark.run(order=1)
    @pytest.mark.parametrize("receipt_name,phone,address_info,post",
                             get_data("add"))
    def test_add_address(self, receipt_name, phone, address_info, post):
        allure.attach("描述", "点击新增地址")
        # 点击新增地址
        self.setting.page_click_new_address()
        allure.attach("描述", "输入收件人")
        # 输入收件人
        self.setting.page_input_receipt_name(receipt_name)
        allure.attach("描述", "输入手机号")
        # 输入手机号
        self.setting.page_input_phone(phone)
        allure.attach("描述", "选择所在区域")
        # 所在区域
        # self.setting.page_select_Area()
        self.setting.page_select_Area_xpath()
        allure.attach("描述", "输入详细地址")
        # 详细地址
        self.setting.page_input_address_info(address_info)
        allure.attach("描述", "输入邮编")
        # 邮编
        self.setting.page_input_post_code(post)
        allure.attach("描述", "设为默认地址")
        # 默认地址
        self.setting.page_click_default_address()
        allure.attach("描述", "点击保存按钮")
        # 点击保存按钮
        self.setting.page_click_save_btn()
        try:
            allure.attach("描述", "开始判断地址是否添加成功")
            # 断言地址是否添加成功
            receipt_name_phone = receipt_name + '  ' + phone
            assert receipt_name_phone in self.setting.page_get_receipt_name_phone(
            )
            allure.attach("描述", "地址添加成功")
            allure.attach("描述", "判断是否有默认按钮")
            # 判断是否有默认按钮
            assert self.setting.page_if_default()
        except:
            allure.attach("描述", "添加地址或默认地址失败")
            allure.attach("描述", "开始截图")
            # 截图
            self.setting.base_get_screenshot()
            img_path = os.getcwd(
            ) + os.sep + "Image" + os.sep + "faild_img.png"
            with open(img_path, "rb") as f:
                allure.attach("截图完成,写入报告", f.read(), allure.attach_type.PNG)
            allure.attach("描述", "截图成功,并导入报告")
            raise

    # 修改地址
    @pytest.mark.run(order=2)
    @allure.step("修改地址")
    @pytest.mark.parametrize(
        "text,receipt_name,phone,sheng,shi,qu,address_info,post",
        get_data("edit"))
    def test_edit_address(self, text, receipt_name, phone, sheng, shi, qu,
                          address_info, post):
        # 点击编辑
        self.setting.page_click_edit_btn()
        # 点击修改按钮
        self.setting.page_click_elements(text)
        # 修改地址
        self.setting.page_edit_address(receipt_name, phone, sheng, shi, qu,
                                       address_info, post)
        try:
            # 断言
            receipt_name_phone = receipt_name + "  " + phone
            assert receipt_name_phone in self.setting.page_get_receipt_name_phone(
            )
            allure.attach("描述:", "修改地址成功!")
        except:
            allure.attach("描述:", "修改地址失败!")
            # 截图
            self.setting.base_get_screenshot()
            img_path = os.getcwd(
            ) + os.sep + "Image" + os.sep + "faild_img.png"
            with open(img_path, "rb") as f:
                allure.attach("截图完成,写入报告", f.read(), allure.attach_type.PNG)
            allure.attach("描述", "截图成功,并导入报告")
            raise

    # 删除地址
    @pytest.mark.run(order=3)
    def test_delete_address(self):
        # 点击 编辑按钮
        self.setting.page_click_edit_btn()
        # 删除
        self.setting.page_delete_address()
        try:
            # 断言
            assert self.setting.if_delete_none()
            allure.attach("描述:", "删除地址地址!")
        except:
            allure.attach("描述:", "删除地址失败!")
            # 截图
            self.setting.base_get_screenshot()
            img_path = os.getcwd(
            ) + os.sep + "Image" + os.sep + "faild_img.png"
            with open(img_path, "rb") as f:
                allure.attach("截图完成,写入报告", f.read(), allure.attach_type.PNG)
            allure.attach("描述", "截图成功,并导入报告")
            raise
예제 #3
0
class TestLogin():
    def setup_class(self):
        # 获取driver
        self.driver = get_driver()
        # 实例化统一入口类
        self.page = PageIn(self.driver)
        # 实例化登录页面对象
        self.login = self.page.page_get_login()
        # 实例化设置页面对象
        self.setting = self.page.page_get_setting()
        # 点击我的
        self.login.page_click_me()
        # 点击已有账号去登录
        self.login.page_click_login_link()

    def teardown_class(self):
        self.driver.quit()

    @pytest.mark.parametrize("username,password,expect_nickname,expect_toast",
                             get_data())
    @allure.step("开始登录操作")
    def test_login(self, username, password, expect_nickname, expect_toast):
        # 把登录页面对象赋值给login 便于调用
        login = self.login
        setting = self.setting
        # 如果expect_nickname不为空,说明为正向数据,执行以下步骤
        if expect_nickname:
            try:
                allure.attach("开始登录",
                              "username:%s,password%s" % (username, password))
                # 输入用户名和密码 进行登录
                login.page_login(username, password)
                # 断言是否登录成功
                assert expect_nickname in login.page_get_nickname()
                allure.attach("登录成功",
                              "username:%s,password%s" % (username, password))
                # 点击设置
                login.page_click_setting()
                allure.attach("退出操作", "开始退出")
                # 点击退出
                setting.page_drag_and_drop()
                # 断言 退出是否成功
                assert setting.page_if_logout()
                allure.attach("退出状态", "退出成功!")
                # 点击我的
                login.page_click_me()
                # 点击已有账号
                login.page_click_login_link()
            except:
                # 截图
                login.base_get_screenshot()
        # 逆向数据(登录失败数据)执行流程
        else:
            allure.attach("开始校验类数据验证",
                          "usrename:'%s',password:'******'" % (username, password))
            # 调用登录方法
            login.page_login(username, password)
            try:
                allure.attach("开始验证", "预期toast消息为:%s" % expect_toast)
                # 断言
                assert expect_toast in login.base_get_toast(expect_toast)
                allure.attach("验证成功",
                              "预期toast:%s和捕获toast提示信息相符合" % expect_toast)
            except:
                allure.attach("开始截图", "捕获toast消息与预期toast消息不符合")
                # 截图
                login.base_get_screenshot()
                img_path = os.getcwd(
                ) + os.sep + "Image" + os.sep + "faild_img.png"
                with open(img_path, "rb") as f:
                    allure.attach("截图完成,写入报告", f.read(),
                                  allure.attach_type.PNG)
                raise