A Python Selenium library inspired by the Testing Library
Project description
Selenium Testing Library
Slenium Testing Library (STL) is a Python library for Selenium inspired by the Testing Library.
from selenium import webdriver
from selenium_testing_library import Screen
screen = Screen(webdriver.Chrome())
screen.driver.get("http://www.google.com/ncr")
screen.get_by_text("Accept").click()
screen.get_by_role("combobox").send_keys("Dogs" + Keys.RETURN)
# Find waits until the results become available
screen.find_by_text("Dog - Wikipedia", timeout=5, poll_frequency=0.5)
assert screen.query_by_text("Cats") is None
API Parity with Testing Library
Queries
Testing Library | STL | Status |
---|---|---|
getBy |
get_by |
🟢 Done |
queryBy |
query_by |
🟢 Done |
findBy |
find_by |
🟢 Done |
getAllBy |
get_all_by |
🟢 Done |
queryAllBy |
query_all_by |
🟢 Done |
findAllBy |
find_all_by |
🟢 Done |
Examples:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium_testing_library import Screen, locators
screen = Screen(webdriver.Chrome())
screen.get_by(locators.Css(".my_class")) # locator classes are a shorthand for (By.CSS_SELECTOR, ".my_class"). All Selenium By.* options are supported
screen.query_by((By.ID, "my_id")) # you can use regular tuples/lists if you want to
screen.find_by(locators.Text("My text"), timeout=5, poll_frequency=0.5) # locators for searching through text also work
Testing Library | STL | Status |
---|---|---|
ByRole |
by_role |
⚠️ Partial |
ByLabelText |
by_label_text |
⚠️ Partial |
ByPlaceholderText |
by_placeholder_text |
⚠️ Partial |
ByText |
by_text |
⚠️ Partial |
ByDisplayValue |
by_display_value |
❌ Missing |
ByAltText |
by_alt_text |
⚠️ Partial |
ByTitle |
by_title |
❌ Missing |
ByTestId |
by_test_id |
❌ Missing |
Examples:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium_testing_library import Screen, locators
screen = Screen(webdriver.Chrome())
screen.query_by_role("role_name")
screen.get_by_label_text("label text")
screen.find_all_by_text("my text", timeout=5, poll_frequency=0.5)
screen.get_all_by_alt_text("alt text")
User Actions
Testing Library | STL | Status |
---|---|---|
fireEvent |
N/A |
❌ Not Planned |
fireEvent[eventName] |
N/A |
❌ Not Planned |
createEvent[eventName] |
N/A |
❌ Not Planned |
There is currently no plan to support the event API of Testing Library. Use the methods on WebElement
instead.
Testing Library | STL | Status |
---|---|---|
waitFor |
wait_for |
🟢 Done |
waitForElementToBeRemoved |
wait_for_stale |
🟢 Done |
from selenium import webdriver
from selenium_testing_library import Screen, locators
screen = Screen(webdriver.Chrome())
# Wait for the element to be clickable:
element = screen.get_by_text("Submit")
screen.wait_for(lambda _: element.is_enabled(), timeout=5, poll_frequency=0.5)
# Wait for the element to be removed from the page:
screen.wait_for_stale(element)
Local development
poetry install && poetry shell
# Make sure `chromedriver` is in your PATH, download from https://chromedriver.chromium.org/downloads
# run tests:
pytest --selenium-headless
# run tests and display coverage info:
pytest --selenium-headless --cov=selenium_testing_library --cov-report html
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
Close
Hashes for selenium-testing-library-2021.6.6a2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 35164ed6a9a8a82afb5c6377d7821fc59ff68648bbc6bc3b7dd98e0943eae776 |
|
MD5 | 875778206eafc2cd10a82468ddd6f6f2 |
|
BLAKE2b-256 | 689279f09059f598b8aaa5a387eb1f060983b89d49be7271e5368c82b21686d2 |
Close
Hashes for selenium_testing_library-2021.6.6a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8a9dc57dcf2d860070e1a3a4f7df87125c7fc7b111387eda793aa96b5537471 |
|
MD5 | d4c1469ee18f6a4d9952575080747d9a |
|
BLAKE2b-256 | 906ffb05a31de35bda20b7b15796ba9a57c1e457f0c190918e087d0880659530 |