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.
importinjectimportpaf.configfrompaf.locatorimportByfrompaf.pageimportFinderPage, PageFactory# Configure dependency injectioninject.configure(paf.config.inject)
# Instantiate the page factorypage_factory=inject.instance(PageFactory)
# Create a simple finder pagepage=page_factory.create_page(FinderPage)
# Visit URLpage.open("https://google.com")
# Find elementelement=page.find("#q")
# Perform actionselement.type("Search")
# Perform assertionselement.expect.text.be("Search")- You need at least a local WebDriver installed.
brew|choco|apt install chromedriver
- Rect assertions
- Drag & Drop over frames
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
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 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
PAF_TEST_HEADLESS=1 PAF_TEST_LOCAL_SELENIUM=0 pytest --cov=paf -n=4 testpodman 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:latestRun 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 testwget 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.1xpath="//dt[.//text()='Title:']/following-sibling::dd[1]"snapshot=document.evaluate(xpath,document.body,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE)snapshot.snapshotItem(0).textContent