![](logo.png)
[![PyPI version](https://badge.fury.io/py/poium.svg)](https://badge.fury.io/py/poium) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/poium)
> Page Objects design pattern test library; support selenium、appium、playwright, etc
Page Objects 设计模式测试库;支持 selenium、appium、playwright 等。
## Features
* 极简的Page层的元素定义。
* 支持主流的 Web/App UI库。
* 对原生 API 无损。
__支持库:__
- [x] selenium ✔️
- [x] appium ✔️
- [x] playwright ✔️
- [x] uiautomator2 ✔️
- [x] facebook-wda ️ ✔️
## Installation
pip install:
```shell
> 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:
```shell
> pip install -U git+https://github.com/SeldomQA/poium.git@master
```
## Sample
### selenium/appium
`poium` 对 `selenium/appium` 提供了良好的支持。
👉 [详细文档](./tests/selenium_sample)
* selenium
```python
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
```python
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`的用法.
👉 [详细文档](./tests/playwright_sample)
```python
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`同样对它做了支持。
👉 [详细文档](./tests/u2_sample)
* uiautomator2
```python
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是一个全功能自动化测试框架。
👉 [详细文档](./tests/seldom_sample)
```python
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)
> 欢迎添加微信,交流和反馈问题。
<div style="display: flex;justify-content: space-between;width: 100%">
<p><img alt="微信" src="wechat.jpg" style="width: 200px;height: 100%" ></p>
</div>
## Star History
![Star History Chart](https://api.star-history.com/svg?repos=SeldomQA/poium&type=Date)
## Project History
* [page-objects](https://github.com/eeaston/page-objects)
poium 参考 page-objects,他项目已经不再维护,原项目代码虽然只有100多行,但设计非常精妙。本项目在此基础上进行开发。
* [selenium-page-objects](https://pypi.org/project/selenium-page-objects/)
selenium-page-objects是poium的前身,为了简化项目名称,改名为poium。__po__ 取自 Page Object 首字母, __ium__
取自selenium/appium 共同后缀。
Raw data
{
"_id": null,
"home_page": "https://seldomqa.github.io",
"name": "poium",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "selenium, appium, playwright",
"author": "fnngj",
"author_email": "fnngj@126.com",
"download_url": "https://files.pythonhosted.org/packages/ac/7b/422822b52565b377226a68c35c2a632fc15469f18c8bd8ae6c6afd500c46/poium-1.6.3.tar.gz",
"platform": null,
"description": "![](logo.png)\n\n[![PyPI version](https://badge.fury.io/py/poium.svg)](https://badge.fury.io/py/poium) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/poium)\n\n> Page Objects design pattern test library; support selenium\u3001appium\u3001playwright, etc\n\nPage Objects \u8bbe\u8ba1\u6a21\u5f0f\u6d4b\u8bd5\u5e93\uff1b\u652f\u6301 selenium\u3001appium\u3001playwright \u7b49\u3002\n\n## Features\n\n* \u6781\u7b80\u7684Page\u5c42\u7684\u5143\u7d20\u5b9a\u4e49\u3002\n* \u652f\u6301\u4e3b\u6d41\u7684 Web/App UI\u5e93\u3002\n* \u5bf9\u539f\u751f API \u65e0\u635f\u3002\n\n__\u652f\u6301\u5e93\uff1a__\n\n- [x] selenium \u2714\ufe0f\n- [x] appium \u2714\ufe0f\n- [x] playwright \u2714\ufe0f\n- [x] uiautomator2 \u2714\ufe0f\n- [x] facebook-wda \ufe0f \u2714\ufe0f\n\n## Installation\n\npip install:\n\n```shell\n> pip install poium\n> pip install playwright [optional]\n> pip install uiautomator2 [optional]\n> pip install facebook-wda [optional]\n```\n\nIf you want to keep up with the latest version, you can install with GitHub repository url:\n\n```shell\n> pip install -U git+https://github.com/SeldomQA/poium.git@master\n```\n\n## Sample\n\n### selenium/appium\n\n`poium` \u5bf9 `selenium/appium` \u63d0\u4f9b\u4e86\u826f\u597d\u7684\u652f\u6301\u3002\n\n\ud83d\udc49 [\u8be6\u7ec6\u6587\u6863](./tests/selenium_sample)\n\n* selenium\n\n```python\nfrom selenium import webdriver\nfrom poium import Page, Element, Elements\n\n\n# page\nclass BaiduPage(Page):\n input = Element(\"#kw\")\n button = Element(\"id=su\")\n result = Elements(\"//div/h3/a\", describe=\"\u641c\u7d22\u7ed3\u679c\", timeout=2)\n\n\n# selenium\ndriver = webdriver.Chrome()\n\npage = BaiduPage(driver)\npage.open(\"https://www.baidu.com\")\npage.input.send_keys(\"baidu\")\npage.button.click()\n\nfor r in page.result:\n print(r.text)\n\ndriver.close()\n```\n\n* appium\n\n```python\nfrom appium import webdriver\nfrom appium.options.android import UiAutomator2Options\nfrom poium import Page, Element\n\n\n# page\nclass CalculatorPage(Page):\n number_1 = Element(\"id=com.android.calculator2:id/digit_1\")\n number_2 = Element(\"id=com.android.calculator2:id/digit_2\")\n add = Element(\"id=com.android.calculator2:id/op_add\")\n eq = Element(\"id=com.android.calculator2:id/eq\")\n\n\n# appium\ncapabilities = {\n \"automationName\": \"UiAutomator2\",\n \"platformName\": \"Android\",\n 'appPackage': 'com.android.calculator2',\n 'appActivity': '.Calculator'\n}\noptions = UiAutomator2Options().load_capabilities(capabilities)\ndriver = webdriver.Remote('http://localhost:4723/wd/hub', options=options)\n\npage = CalculatorPage(driver)\npage.number_1.click()\npage.add.click()\npage.number_2.click()\npage.eq.click()\n\ndriver.quit()\n```\n\n### playwright\n\n`poium 1.2` \u7248\u672c\u652f\u6301playwright\u5e93, \u76ee\u524d\u4ec5\u652f\u6301`sync`\u7684\u7528\u6cd5.\n\n\ud83d\udc49 [\u8be6\u7ec6\u6587\u6863](./tests/playwright_sample)\n\n```python\nimport re\nfrom playwright.sync_api import sync_playwright\nfrom playwright.sync_api import expect\nfrom poium.playwright import Page, Locator\n\n\n# page\nclass BingPage(Page):\n search_input = Locator('id=sb_form_q', describe=\"bing\u641c\u7d22\u6846\")\n search_icon = Locator('id=search_icon', describe=\"bing\u641c\u7d22\u6309\u94ae\")\n\n\n# playwright\nwith sync_playwright() as p:\n # \u542f\u52a8\u6d4f\u6d4f\u89c8\u5668\n browser = p.chromium.launch(headless=False)\n # \u521b\u5efa\u65b0\u7684\u9875\u9762\n page = browser.new_page()\n # \u8fdb\u5165\u6307\u5b9aURL\n page.goto(\"https://cn.bing.com\")\n\n # \u83b7\u5f97\u5143\u7d20\n search_page = BingPage(page)\n search_page.search_input.highlight()\n search_page.search_input.fill(\"playwright\")\n search_page.search_icon.highlight()\n search_page.search_icon.screenshot(path=\"./docs/abc.png\")\n search_page.search_icon.click()\n\n # \u65ad\u8a00URL\n expect(page).to_have_title(re.compile(\"playwright\"))\n\n # \u5173\u95ed\u6d4f\u89c8\u5668\n browser.close()\n```\n\n### openatx\n\n`openatx` \u6709\u56fd\u5185\u662f\u975e\u5e38\u6d41\u884c\u7684\u79fb\u52a8App\u81ea\u52a8\u5316\u5de5\u5177\uff0c`poium`\u540c\u6837\u5bf9\u5b83\u505a\u4e86\u652f\u6301\u3002\n\n\ud83d\udc49 [\u8be6\u7ec6\u6587\u6863](./tests/u2_sample)\n\n* uiautomator2\n\n```python\nimport uiautomator2 as u2\n\nfrom poium.u2 import Page, XpathElement\n\n\nclass BingPage(Page):\n search = XpathElement('//*[@resource-id=\"com.microsoft.bing:id/sa_hp_header_search_box\"]')\n search_input = XpathElement('//*[@resource-id=\"com.microsoft.bing:id/sapphire_search_header_input\"]')\n search_count = XpathElement('//*[@resource-id=\"count\"]')\n\n\nd = u2.connect()\nd.app_start(\"com.microsoft.bing\")\npage = BingPage(d)\npage.search.click()\n\npage.search_input.click()\npage.search_input.set_text(\"uiautomator2\")\npage.press(\"enter\")\npage.sleep(2)\nresult = page.search_count.get_text()\nassert \"\u4e2a\u7ed3\u679c\" in result\n\nd.app_stop(\"com.microsoft.bing\")\n```\n\n### seldom\n\nseldom\u662f\u4e00\u4e2a\u5168\u529f\u80fd\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\u3002\n\n\ud83d\udc49 [\u8be6\u7ec6\u6587\u6863](./tests/seldom_sample)\n\n```python\nimport seldom\nfrom poium import Page, Element\n\n\nclass BaiduPage(Page):\n \"\"\"baidu page\"\"\"\n input = Element(\"id=kw\", describe=\"\u641c\u7d22\u8f93\u5165\u6846\")\n button = Element(\"id=su\", describe=\"\u641c\u7d22\u6309\u94ae\")\n\n\nclass BaiduTest(seldom.TestCase):\n \"\"\"Baidu search test case\"\"\"\n\n def test_case(self):\n \"\"\"A simple test\"\"\"\n page = BaiduPage()\n page.open(\"https://www.baidu.com\")\n page.input.send_keys(\"seldom\")\n page.button.click()\n self.assertTitle(\"seldom_\u767e\u5ea6\u641c\u7d22\")\n\n\nif __name__ == '__main__':\n seldom.main(browser='edge')\n```\n\n## \u5fae\u4fe1\uff08WeChat\uff09\n\n> \u6b22\u8fce\u6dfb\u52a0\u5fae\u4fe1\uff0c\u4ea4\u6d41\u548c\u53cd\u9988\u95ee\u9898\u3002\n\n<div style=\"display: flex;justify-content: space-between;width: 100%\">\n <p><img alt=\"\u5fae\u4fe1\" src=\"wechat.jpg\" style=\"width: 200px;height: 100%\" ></p>\n</div>\n\n## Star History\n\n![Star History Chart](https://api.star-history.com/svg?repos=SeldomQA/poium&type=Date)\n\n## Project History\n\n* [page-objects](https://github.com/eeaston/page-objects)\n\npoium \u53c2\u8003 page-objects\uff0c\u4ed6\u9879\u76ee\u5df2\u7ecf\u4e0d\u518d\u7ef4\u62a4\uff0c\u539f\u9879\u76ee\u4ee3\u7801\u867d\u7136\u53ea\u6709100\u591a\u884c\uff0c\u4f46\u8bbe\u8ba1\u975e\u5e38\u7cbe\u5999\u3002\u672c\u9879\u76ee\u5728\u6b64\u57fa\u7840\u4e0a\u8fdb\u884c\u5f00\u53d1\u3002\n\n* [selenium-page-objects](https://pypi.org/project/selenium-page-objects/)\n\nselenium-page-objects\u662fpoium\u7684\u524d\u8eab\uff0c\u4e3a\u4e86\u7b80\u5316\u9879\u76ee\u540d\u79f0\uff0c\u6539\u540d\u4e3apoium\u3002__po__ \u53d6\u81ea Page Object \u9996\u5b57\u6bcd, __ium__\n\u53d6\u81easelenium/appium \u5171\u540c\u540e\u7f00\u3002\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Page Objects design pattern test library.",
"version": "1.6.3",
"project_urls": {
"Homepage": "https://seldomqa.github.io",
"Repository": "https://github.com/SeldomQA/poium"
},
"split_keywords": [
"selenium",
" appium",
" playwright"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a336a45ae10b18d40fa9ec42ba00a0f106d81ab7ff21f64d6eb2c3f6be929213",
"md5": "cd1abcdd2895b268859a1781a9407097",
"sha256": "8efaa38dee44e0dab4bdaa18a5a4b794dcdbae7ed22138e8df23a770be0070ee"
},
"downloads": -1,
"filename": "poium-1.6.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "cd1abcdd2895b268859a1781a9407097",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 35632,
"upload_time": "2024-11-07T10:22:57",
"upload_time_iso_8601": "2024-11-07T10:22:57.671880Z",
"url": "https://files.pythonhosted.org/packages/a3/36/a45ae10b18d40fa9ec42ba00a0f106d81ab7ff21f64d6eb2c3f6be929213/poium-1.6.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ac7b422822b52565b377226a68c35c2a632fc15469f18c8bd8ae6c6afd500c46",
"md5": "91c0f429e519473adeff3a0d1d8b852b",
"sha256": "a2044733f7044bd6cd31834d91f0c8b8427af9e7cdb3581be010755b77a4ee1a"
},
"downloads": -1,
"filename": "poium-1.6.3.tar.gz",
"has_sig": false,
"md5_digest": "91c0f429e519473adeff3a0d1d8b852b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 30097,
"upload_time": "2024-11-07T10:22:59",
"upload_time_iso_8601": "2024-11-07T10:22:59.215131Z",
"url": "https://files.pythonhosted.org/packages/ac/7b/422822b52565b377226a68c35c2a632fc15469f18c8bd8ae6c6afd500c46/poium-1.6.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 10:22:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "SeldomQA",
"github_project": "poium",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "poium"
}