Automation framework for the WebDriver API
Project description
PAF - Python Automation Framework
Python implementation of Testerra API.
It is basically a wrapper for Selenium WebDriver and WebElement which brings some more comfort features. This is not a test framework, but it implements assertion features anyway.
The basic concept is, to identify WebElements on every action or property accessor to prevent StaleElementExceptions.
Quick start
import inject
import paf.config
from paf.locator import By
from paf.page import FinderPage, PageFactory
# Configure dependency injection
inject.configure(paf.config.inject)
# Instantiate the page factory
page_factory = inject.instance(PageFactory)
# Create a simple finder page
page = page_factory.create_page(FinderPage)
# Visit URL
page.open("https://google.com")
# Find element
element = page.find("#q")
# Perform actions
element.type("Search")
# Perform assertions
element.expect.text.be("Search")
Prerequisites
- You need at least a local WebDriver installed.
brew|choco|apt install chromedriver
Feature list
- UiElements
- Locators
- Page objects
- Components
- Managing WebDrivers
- Execution controlling
- Inject listeners
Missing features (tdb)
- Rect assertions
- Drag & Drop over frames
Environment variables
PAF_BROWSER_SETTING=chrome:90: Sets the requested browser name and it's version.PAF_WINDOW_SIZE=1920x1080: Sets the browsers initial window size.PAF_WINDOW_POSITION=0x0: Place the initial window to a different location/screen.PAF_WINDOW_MAXIMIZE=False: Maximize the initial window.PAF_SCREENSHOTS_DIR=screenshots: Sets the screenshots' directory.PAF_SEQUENCE_WAIT_AFTER_FAIL=0.3: Wait in seconds whenever a sequence action fails.PAF_SEQUENCE_RETRY_COUNT=3: Retry count for every sequence action.PAF_DEMO_MODE=0: Enables the demo mode by highlighting actions and assertions.PAF_SELENIUM_SERVER_URL=http://127.0.0.1:4444: Uses Selenium server if set.PAF_DRIVER_PATH: Path to Webdriver binaryPAF_BINARY_PATH: Path to User agent's binary
Examples
Some real world examples.
- test_google.py: is a regular Google search, implemented with Page Objects and Components.
- test_todo_mvc.py: are re-implemented test cases from the Robot Framework TodoMVC example. It's IMHO developer friendly, better readable and less code.
- test_asyncio.py: Parallel execution via
asyncio. - test_monkeytype.py: Typing test on https://monkeytype.com
Comparison
Comparison of the syntax with other frameworks.
Pylenium
py.get("a[href='/about']").should().have_text("About")
find("a[href='/about']").expect.text.be("About")
SeleniumBase
self.assert_text_not_visible("Thanks for your purchase.", "#app .success")
find("#app .success").expect.text.not_be("Thanks for your purchase.")
Selene
browser.all('#rso>div').should(have.size_greater_than(5)) \
.first.should(have.text('Selenium automates browsers'))
div = find("#rso>div")
div.expect.count.greater_than(5).be(True)
div.first.expect.text.be("Selenium automates browsers")
References: https://www.nextgenerationautomation.com/post/python-test-automation-frameworks
Developer area
Testing
Run the tests on your local machine
PAF_TEST_HEADLESS=1 PAF_TEST_LOCAL_SELENIUM=0 pytest --cov=paf -n=4 test
Build test base container (for use in GitHub Actions)
podman build -f ubuntu-base.Dockerfile --arch=amd64 -t paf-test-base:latest
source build.env
echo $DOCKER_CONTAINER_REGISTRY_TOKEN | podman login -u mreiche --password-stdin ghcr.io
podman push paf-test-base:latest docker://ghcr.io/mreiche/paf-test-base:latest
Build test runner container (for testing)
Run tests within container
podman run -e PAF_TEST_HEADLESS=1 -e PAF_TEST_CONTAINER=1 -e PAF_TEST_LOCAL_SELENIUM=0 paf-test-base:latest pytest --cov=paf -n=4 test
Run local selenium server
wget https://github.com/SeleniumHQ/selenium/releases/download/selenium-4.9.0/selenium-server-4.9.0.jar -O selenium-server.jar
java -jar selenium-server.jar standalone --host 127.0.0.1
Debug XPaths in Browser's Developer Console
xpath = "//dt[.//text()='Title:']/following-sibling::dd[1]"
snapshot = document.evaluate(xpath, document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)
snapshot.snapshotItem(0).textContent
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_automation_framework-0.2.4.tar.gz.
File metadata
- Download URL: python_automation_framework-0.2.4.tar.gz
- Upload date:
- Size: 29.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a83bac8da273bada22db7f6e98f1590ed8350693de5238cc08153df57628d65f
|
|
| MD5 |
442d46248336365e44f3155b8f7ea173
|
|
| BLAKE2b-256 |
a219bcf5d1cc0282c7dbfe595fea0e57ae8e540d0cafe3d734ec2b6926d9f018
|
File details
Details for the file python_automation_framework-0.2.4-py3-none-any.whl.
File metadata
- Download URL: python_automation_framework-0.2.4-py3-none-any.whl
- Upload date:
- Size: 23.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c6e926cf158afeba2f6e9e9c66e11d974d716e2ee47bdc629fec9a1f7e5dbfd
|
|
| MD5 |
0dda92eee8ce2e97b0086af110bf744e
|
|
| BLAKE2b-256 |
2561f300101ce36286fd0f2c1698b0ac9fca37ddda18b8ff1b1ac7b1fcb2e877
|