20221106 web自动化测试实战二 (Python)

实战目标

  • PO设计模式

课堂ppt

PPT地址

源码地址(思维导图在源码内)

内容

PO核心思想

  • The public methods represent the services that the page offers
  • Try not to expose the internals of the page
  • Generally don’t make assertions
  • Methods return other PageObjects
  • Need not represent an entire page
  • Different results for the same action are modelled as different methods

课件作业

  • 构造PO模型
    • 通讯录页面
    • 首页
    • 添加成员页面
  • 构造测试用例
    • 从首页添加成员
    • 从通讯录页面添加成员
  • 注意:实现先设置为空

注意事项

  • 两个路径需要保持一致,这样执行的结果才能保持一致

  • 执行命令
# 选择文件::类::方法执行, 并指定报告生成的路径
 pytest test_add_member.py::TestAddMember::test_add_member_by_index --alluredir=./report

#main.py
from PageObjectPro.WeinxinWorkPro.page_object.add_member_page import AddMemberPage
from PageObjectPro.WeinxinWorkPro.page_object.contact_page import ContactPage

class MainPage:
    def goto_add_member(self):
        pass
        return AddMemberPage()

    def goto_contact_page(self):
        pass
        return ContactPage()

#contact_page.py
from PageObjectPro.WeinxinWorkPro.page_object.add_member_page import AddMemberPage

class ContactPage:
    def goto_add_member(self):
        pass
        return AddMemberPage()

    def get_member(self):
        pass
        return ContactPage()
# add_member_page.py
from PageObjectPro.WeinxinWorkPro.page_object.contact_page import ContactPage

class AddMemberPage:
    def add_member_success(self):
        pass
        return ContactPage()
# test_add_member.py
from PageObjectPro.WeinxinWorkPro.page_object.main_page import MainPage

class TestAddMember:
    def setup_class(self):
        self.home = MainPage()

    def teardown_class(self):
        pass

    # 从首页添加成员
    def test_main_addmember(self):
        self.home.goto_add_member().add_member_success().get_member()

    # 从通讯录页添加成员
    def test_contact_addmember(self):
        self.home.goto_contact_page().goto_add_member().add_member_success().get_member()

1 个赞