全流程实战练习(一)

课堂 ppt

霍格沃兹测试开发

用例设计

  1. 访问系统: login_page
    2.用户登录:def login()

  2. 点开菜单 home_page
    4.上架商品: product_launch_page

  3. 校验结果: product_list_page

  4. 访问系统:展示登录页

http://litemall.hogwarts.ceshiren.com/

  1. 用户登录:预期:成功后展示首页
  • 用户名
  • 密码
  • 登录按钮

  1. 点开菜单:展示商品上架页面

  1. 商品上架页
  • 商品编号
  • 商品名称
  • 方法:上架()
  1. 校验结果:预期:商品列表页面

  • base_page.py
class BasePage:

    # litemall商城地址
    _BASE_URL = "https://litemall.hogwarts.ceshiren.com/"

    def __init__(self, driver:WebDriver = None):
        if driver is None:
            # 初始化浏览器
            self.driver = webdriver.Chrome()
            self.driver.implicitly_wait(5)
            self.driver.maximize_window()

            # 打开litemall网站
            self.driver.get(self._BASE_URL)
        else:
            # 设置浏览器
            self.driver = driver

    def do_click(self, by: By, locator: str):
        # 点击操作
        self.driver.find_element(by, locator).click()

    def do_send_keys(self, value: str, by: By, locator: str):
        # 输入操作
        element = self.driver.find_element(by, locator)
        element.clear()
        element.send_keys(value)
  • login_page.py
class LoginPage(BasePage):
    _INPUT_USERNAME = (By.XPATH, "//input[@name='username']")
    _INPUT_PASSWORD = (By.XPATH, "//input[@name='password']")
    _BUTTON_LOGIN = (By.CSS_SELECTOR, "button.el-button")

    def login_in(self):
        # 输入用户名
        self.do_send_keys("admin123", *self._INPUT_USERNAME)
        # 输入密码
        self.do_send_keys("admin123", *self._INPUT_PASSWORD)
        # 点击登录按钮
        self.do_click(*self._BUTTON_LOGIN)
        from litemall.pages.home_page import HomePage
        return HomePage(self.driver)
  • home_page.py
class HomePage(BasePage):
    _MENU_PRODUCT_MANAGE = (By.XPATH, "//span[contains(text(), '商品管理')]")
    _MENU_PRODUCT_LAUNCH = (By.XPATH, "//span[contains(text(), '上架')]")

    def go_to_product_launch(self):
        # 点击“商品管理”菜单
        self.do_click(*self._MENU_PRODUCT_MANAGE)
        # 点击“商品上架”
        self.do_click(*self._MENU_PRODUCT_LAUNCH)
        # 进入商品上架页面
        from litemall.pages.product_launch_page import ProductLaunchPage
        return ProductLaunchPage(self.driver)
  • product_launch_page.py
class ProductLaunchPage(BasePage):
    _INPUT_PRODUCT_CODE = (By.XPATH, "//label[@for='goodsSn']/../div/div/input")
    _INPUT_PRODUCT_NAME = (By.XPATH, "//label[@for='name']/../div/div/input")
    _INPUT_PRODUCT_PRICE = (By.XPATH, "//label[@for='counterPrice']/../div/div/input")
    _RADIO_IS_HOT = (By.XPATH, "//span[contains(text(), '热卖')]")
    _BUTTON_LAUNCH = (By.XPATH, " //div[@class='op-container']//span[contains(text(), '上架')]")

    def product_launch(self, product_name):
        # 输入“商品编号”
        self.do_send_keys(product_name, *self._INPUT_PRODUCT_CODE)
        # 输入“商品名称”
        self.do_send_keys(product_name, *self._INPUT_PRODUCT_NAME)
        # 输入“商品售价”
        self.do_send_keys("888", *self._INPUT_PRODUCT_PRICE)
        # 选择“热卖”
        self.do_click(*self._RADIO_IS_HOT)
        # 滑动到底部
        self.driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
        # 点击“上架”
        self.do_click(*self._BUTTON_LAUNCH)
        # 跳转到商品列表界面
        return ProductListPage(self.driver)
  • product_list_page.py
class ProductListPage(BasePage):
    _TEXT_PRODUCT_NAME = (By.XPATH, "//tbody/tr[1]/td[3]/div")

    def get_product_name(self):
        # 获取第一个商品名称
        element = WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self._TEXT_PRODUCT_NAME))
        name = element.text
        # 返回第一个商品名称
        return name
  • test_product_launch.py
class TestProductLaunch:

    # 前置处理
    def setup_class(self):
        self.manager = LoginPage()

    # 测试商品上架
    @pytest.mark.parametrize("product_name", ["20221030_1441"])
    def test_product_launch(self, product_name):
        real_name = self.manager.login_in() \
            .go_to_product_launch() \
            .product_launch(product_name) \
            .get_product_name()
        assert real_name == product_name

作业

1.商品列表页面:查找、编辑功能
2.商品评论页面:回复、删除功能

课后调查表单

请同学们填写一下今天的课后调查表单:20221030-汤达人 - 全流程实战1 - 课后调查问卷

仅完成了商品列表页面,评论无法重复回复,也无法查看是否已经回复评论,所以就偷个懒 :wink:

gitee地址:https://gitee.com/tester-joker/test-jy4/tree/master/litemall_work

gitee地址:
https://gitee.com/cc688/litemal_ui/tree/master/litemall_ui

nice