class TestCheckReceivingAddress(unittest.TestCase):
    def setUp(self) -> None:
        # 打开浏览器到添加收货地址界面
        # 创建对象
        driver = open_browser()
        self.login = AddressPage(driver)
        # 准备数据,进入到添加收货地址界面
        url = "http://172.16.1.224/ecshop/"
        self.login.open_url(url)
        self.login.login_address("grj123456", "grj123456")

    def tearDown(self) -> None:
        # 关闭浏览器
        self.login.close()

    @ddt.data(*test_data)
    def test_check_receiving_address(self, data):
        """测试用例,查询操作"""
        # 1.获取输入的id,然后根据id来进行定位要修改的地址
        b = self.login.a_number()
        a = data["id"] - 1
        if a < b:
            self.login.performance(a)
            self.login.driver.get_screenshot_as_file("./report/chrome.png")
        else:
            print("需要修改的地址编号不存在")
            return False
        # 断言,查看的姓名是否和原本的value值一样
        result = self.login.is_ckeck_success(data["consignee"])
        self.assertEqual(result, data["expect"])
Esempio n. 2
0
class TestAddReceivingAddress(unittest.TestCase):
    def setUp(self) -> None:
        # 打开浏览器到添加收货地址界面
        # 创建对象
        driver = open_browser()
        self.login = AddressPage(driver)
        # 准备数据,进入到添加收货地址界面
        url = "http://172.16.1.224/ecshop/"
        self.login.open_url(url)
        self.login.login_address("grj123456", "grj123456")
        # 得到最后一个数据的索引,就可以进行添加操作了
        self.a = self.login.a_number()
        self.login.performance(self.a)

    def tearDown(self) -> None:
        # 关闭浏览器
        self.login.close()

    @ddt.data(*test_data)
    def test_add_receiving_address(self, data):
        """测试用例,添加收货地址"""
        # 1.选择国家
        self.login.select_country(data["country"])
        # 2.选择省份
        self.login.select_province(data["province"])
        # 3.选择城市
        self.login.select_city(data["city"])
        # 4.选择区域
        if data["district"] != "None":
            self.login.select_district(data["district"])
        # 5.输入收货人姓名
        self.login.input_consignee(data["consignee"])
        # 6.输入邮箱
        if data["email"] != "None":
            self.login.input_email(data["email"])
        # 7.输入详细地址
        self.login.input_address(data["address"])
        # 8.输入邮政编码
        if data["zipcode"] != "None":
            self.login.input_zipcode(str(data["zipcode"]))
        # 9.输入电话
        if data["tel"] != "None":
            self.login.input_tel(str(data["tel"]))
        # 10.输入手机
        if data["mobile"] != "None":
            self.login.input_mobile(str(data["mobile"]))
        # 11.点击添加
        self.login.click_submit()
        # 12.隐式等待,找到对应的数据
        self.login.driver.implicitly_wait(5)
        # 13.断言,判断用例是否执行成功
        result = self.login.is_add_success(self.a)
        self.assertEqual(result, data["expect"])
class TestDeleteReceivingAddress(unittest.TestCase) :
    i = 1
    def setUp(self) -> None:
        # 打开浏览器到添加收货地址界面
        # 创建对象
        driver = open_browser()
        self.login = AddressPage(driver)
        # 准备数据,进入到添加收货地址界面
        url = "http://172.16.1.224/ecshop/"
        self.login.open_url(url)
        self.login.login_address("grj123456","grj123456")
    def tearDown(self) -> None:
        # 关闭浏览器
        self.login.close()
    @ddt.data(*test_data)
    def test_delete_receiving_address(self,data):
        """测试用例,删除地址"""
        # 1.获取输入的id,然后根据id来进行定位要修改的地址
        b = self.login.a_number()
        a = data["id"]-self.i
        self.i += 1
        if a < b :
            self.login.performance(a)
        else :
            print("需要修改的地址编号不存在")
            return False
        # 1.根据得到的a值,可以定位到删除按钮,点击删除
        self.login.click_delete()
        # 2.跳出弹框,获取弹窗
        alert = self.login.driver.switch_to.alert
        # 3.点击弹框确认按钮
        alert.accept()
        # 刷新窗口
        self.login.driver.refresh()
        # 2.隐式等待,找到对应的数据
        self.login.driver.implicitly_wait(5)
        # 3.断言,判断用例是否执行成功
        result = self.login.is_delete_success(b)
        self.assertEqual(result,data["expect"])
class TestModifyReceivingAddress(unittest.TestCase):
    def setUp(self) -> None:
        # 打开浏览器到添加收货地址界面
        # 创建对象
        driver = open_browser()
        self.login = AddressPage(driver)
        # 准备数据,进入到添加收货地址界面
        url = "http://172.16.1.224/ecshop/"
        self.login.open_url(url)
        self.login.login_address("grj123456", "grj123456")

    def tearDown(self) -> None:
        # 关闭浏览器
        self.login.close()

    @ddt.data(*test_data)
    def test_modify_receiving_address(self, data):
        """测试用例,修改地址"""
        # 1.获取输入的id,然后根据id来进行定位要修改的地址
        b = self.login.a_number()
        a = data["id"] - 1
        if a < b:
            self.login.performance(a)
        else:
            print("需要修改的地址编号不存在")
            return False
        # 2.修改国家
        if data["country"] != "None":
            self.login.select_country(data["country"])
        # 3.修改省份
        if data["province"] != "None":
            self.login.select_province(data["province"])
        # 4.修改城市
        if data["city"] != "None":
            self.login.select_city(data["city"])
        # 5.修改区域
        if data["district"] != "None":
            self.login.select_district(data["district"])
        # 6.输入新收货人姓名
        if data["consignee"] != "None":
            self.login.input_consignee(data["consignee"])
        # 7.输入新邮箱
        if data["email"] != "None":
            self.login.input_email(data["email"])
        # 8.输入新详细地址
        if data["address"] != "None":
            self.login.input_address(data["address"])
        # 9.输入新邮政编码
        if data["zipcode"] != "None":
            self.login.input_zipcode(str(data["zipcode"]))
        # 10.输入新电话
        if data["tel"] != "None":
            self.login.input_tel(str(data["tel"]))
        # 11.输入新手机
        if data["mobile"] != "None":
            self.login.input_mobile(str(data["mobile"]))
        # 12.点击修改按钮
        self.login.click_modify()
        # 13.断言
        # 隐式等待
        self.login.driver.implicitly_wait(5)
        # 开始判断value值是否一致,一致就断言成功
        result = self.login.is_modify_success(data)
        self.assertEqual(result, data["expect"])