Page Objects design pattern test library; support selenium、appium、playwright, etc
Page Objects 设计模式测试库;支持 selenium、appium、playwright 等。
Features
- 极简的Page层的元素定义。
- 支持主流的 Web/App UI库。
- 对原生 API 无损。
支持库:
- selenium ✔️
- appium ✔️
- playwright ✔️
- uiautomator2 ✔️
- facebook-wda ️ ✔️
Installation
pip install:
> pip install poium
> pip install playwright [optional]
> pip install uiautomator2 [optional]
> pip install facebook-wda [optional]
If you want to keep up with the latest version, you can install with GitHub repository url:
> pip install -U git+https://github.com/SeldomQA/poium.git@master
Sample
selenium/appium
poium 对 selenium/appium 提供了良好的支持。
👉 详细文档
- selenium
from selenium import webdriver
from poium import Page, Element, Elements
# page
class BaiduPage(Page):
input = Element("#kw")
button = Element("id=su")
result = Elements("//div/h3/a", describe="搜索结果", timeout=2)
# selenium
driver = webdriver.Chrome()
page = BaiduPage(driver)
page.open("https://www.baidu.com")
page.input.send_keys("baidu")
page.button.click()
for r in page.result:
print(r.text)
driver.close()
- appium
from appium import webdriver
from appium.options.android import UiAutomator2Options
from poium import Page, Element
# page
class CalculatorPage(Page):
number_1 = Element("id=com.android.calculator2:id/digit_1")
number_2 = Element("id=com.android.calculator2:id/digit_2")
add = Element("id=com.android.calculator2:id/op_add")
eq = Element("id=com.android.calculator2:id/eq")
# appium
capabilities = {
"automationName": "UiAutomator2",
"platformName": "Android",
'appPackage': 'com.android.calculator2',
'appActivity': '.Calculator'
}
options = UiAutomator2Options().load_capabilities(capabilities)
driver = webdriver.Remote('http://localhost:4723/wd/hub', options=options)
page = CalculatorPage(driver)
page.number_1.click()
page.add.click()
page.number_2.click()
page.eq.click()
driver.quit()
playwright
poium 1.2 版本支持playwright库, 目前仅支持sync的用法.
👉 详细文档
import re
from playwright.sync_api import sync_playwright
from playwright.sync_api import expect
from poium.playwright import Page, Locator
# page
class BingPage(Page):
search_input = Locator('id=sb_form_q', describe="bing搜索框")
search_icon = Locator('id=search_icon', describe="bing搜索按钮")
# playwright
with sync_playwright() as p:
# 启动浏浏览器
browser = p.chromium.launch(headless=False)
# 创建新的页面
page = browser.new_page()
# 进入指定URL
page.goto("https://cn.bing.com")
# 获得元素
search_page = BingPage(page)
search_page.search_input.highlight()
search_page.search_input.fill("playwright")
search_page.search_icon.highlight()
search_page.search_icon.screenshot(path="./docs/abc.png")
search_page.search_icon.click()
# 断言URL
expect(page).to_have_title(re.compile("playwright"))
# 关闭浏览器
browser.close()
openatx
openatx 有国内是非常流行的移动App自动化工具,poium同样对它做了支持。
👉 详细文档
- uiautomator2
import uiautomator2 as u2
from poium.u2 import Page, XpathElement
class BingPage(Page):
search = XpathElement('//*[@resource-id="com.microsoft.bing:id/sa_hp_header_search_box"]')
search_input = XpathElement('//*[@resource-id="com.microsoft.bing:id/sapphire_search_header_input"]')
search_count = XpathElement('//*[@resource-id="count"]')
d = u2.connect()
d.app_start("com.microsoft.bing")
page = BingPage(d)
page.search.click()
page.search_input.click()
page.search_input.set_text("uiautomator2")
page.press("enter")
page.sleep(2)
result = page.search_count.get_text()
assert "个结果" in result
d.app_stop("com.microsoft.bing")
seldom
seldom是一个全功能自动化测试框架。
👉 详细文档
import seldom
from poium import Page, Element
class BaiduPage(Page):
"""baidu page"""
input = Element("id=kw", describe="搜索输入框")
button = Element("id=su", describe="搜索按钮")
class BaiduTest(seldom.TestCase):
"""Baidu search test case"""
def test_case(self):
"""A simple test"""
page = BaiduPage()
page.open("https://www.baidu.com")
page.input.send_keys("seldom")
page.button.click()
self.assertTitle("seldom_百度搜索")
if __name__ == '__main__':
seldom.main(browser='edge')
微信(WeChat)
欢迎添加微信,交流和反馈问题。
Star History
Project History
poium 参考 page-objects,他项目已经不再维护,原项目代码虽然只有100多行,但设计非常精妙。本项目在此基础上进行开发。
selenium-page-objects是poium的前身,为了简化项目名称,改名为poium。po 取自 Page Object 首字母, ium 取自selenium/appium 共同后缀。
Metadata
Release files for poium 1.6.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| poium-1.6.4.tar.gz | 30.1 kB | Without provenance | Details for poium-1.6.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| poium-1.6.4-py3-none-any.whl | Python 3 | none | any | Details for poium-1.6.4-py3-none-any.whl |
Total release size: 65.7 kB
Release files / poium-1.6.4.tar.gz
| Download URL | poium-1.6.4.tar.gz |
|---|---|
| Size | 30.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7c55626d833ee788b10aa202072219acb95f9eb32b5310e9f29a5f5122e5984
|
|
BLAKE2b-256 checksum How to use checksums |
5df0a7b48036b68ee2d274f53be3c45f6cab12d4558dcf7de966d6f440bf3b6c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Release files / poium-1.6.4-py3-none-any.whl
| Download URL | poium-1.6.4-py3-none-any.whl |
|---|---|
| Size | 35.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cee34a59911b11f6f7da7c10d2c3b7c9f02495272b869ed1a3d4ceecc23dc611
|
|
BLAKE2b-256 checksum How to use checksums |
98796ffed72bbde1c932b52594cb87d2ca66ef489be73e9a7e72981f1604ef03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.9
|
Security for poium 1.6.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.