Skip to main content

为 UI 自动化测试包提供通用功能的包

项目描述

UiTestCore

这个包通过提供对 Selenium 和其他有用功能的包装器来帮助编写 UI 测试。UiTestCore 在设计时考虑了页面对象模型,无需编写任何 Selenium 代码即可轻松创建验收测试包。

该项目的存储库可以在 GitHub 上找到:https ://github.com/nhsuk/ui-test-core

例子

下面的示例展示了如何创建一个代表网页的类,在本例中为登录页面。

from uitestcore.page import BasePage
from uitestcore.page_element import PageElement
from selenium.webdriver.common.by import By


class MyLoginPage(BasePage):

    # Define elements to interact with
    header_logo = PageElement(By.ID, "company-logo")
    username_field = PageElement(By.ID, "input-user")
    password_field = PageElement(By.CLASS_NAME, "field-password")
    login_button = PageElement(By.XPATH, "//button[text()='Login']")

    def open_login_page(self):
        self.interact.open_url("https://mysite.com/login")
        self.wait.for_page_to_load()

    def logo_visible(self):
        return self.interrogate.is_element_visible(self.header_logo)

    def enter_username(self, username):
        self.interact.enter_text(self.username_field, username)

    def enter_password(self, password):
        self.interact.enter_text(self.password_field, password)

    def click_login_button(self):
        self.interact.click_element(self.login_button)

提供了“BasePage”类,以便测试包中的任何页面类都可以从它继承,从而可以访问许多有用的功能,这些功能分为“find”、“interrogate”、“interact”和“wait”。“PageElement”类用于定义您的测试需要与之交互的任何元素,因此可以重用它们而无需记住您是否正在寻找类、ID 等(支持所有 Selenium 选择器类型)。

然后可以在测试步骤中使用上述页面类来执行任何所需的操作和断言。实例化页面时必须提供selenium.webdriver驱动程序对象

    login_page = MyLoginPage(driver)
    login_page.open_login_page()

安装

这个包位于 PyPI:https ://pypi.org/project/uitestcore/ - 它可以以通常的方式安装,即pip install uitestcore

将此包包含在您的项目中的最简单方法是将其添加到您的 requirements.txt 中。这是应添加到此文件的行的示例,我们建议使用特定版本,但这是您的决定:

uitestcore==10.0.0

部署到 PyPI

PyPI 部署在 NHS.UK Azure Devops 项目的发布管道中配置。合并到 master 中的任何更改都将自动部署到 PyPI,并且推送到以“test/”开头的分支的任何更改都将自动部署到 TestPyPI。

执照

该项目在 MIT 许可下获得许可 - 请参阅 LICENSE.md 文件了解详细信息

依赖项

软件包依赖项及其许可证链接如下:

证书 - http://mozilla.org/MPL/2.0/
chardet - https://github.com/chardet/chardet/blob/master/LICENSE
idna - https://github.com/kjd/idna/blob/master /LICENSE.rst
pyhamcrest - https://github.com/hamcrest/PyHamcrest/blob/master/LICENSE.txt
python-dateutil - https://github.com/pganssle/dateutil/blob/master/LICENSE
请求 - https: //github.com/psf/requests/blob/master/LICENSE
selenium - https://github.com/SeleniumHQ/selenium/blob/master/LICENSE
六 - https://github.com/benjaminp/six/blob/主/许可证
urllib3 - https://github.com/urllib3/urllib3/blob/master/LICENSE.txt

贡献

阅读我们的贡献指南,为 UiTestCore 做出贡献。

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

uitestcore-10.0.1.tar.gz (19.9 kB 查看哈希

已上传 source

内置分布

uitestcore-10.0.1-py3-none-any.whl (23.2 kB 查看哈希

已上传 py3