SeleniumBase Browser Automation Framework
SeleniumBase is a Python-based framework that extends Selenium WebDriver, making it easier to write and run automated web tests.
SeleniumBase includes many built-in features such as visual testing, screenshot comparisons, and handling of dynamic web content.
One of the key highlights of SeleniumBase is its ability to integrate smoothly with popular Python testing frameworks like pytest.
This enables parallel test execution, better test organization and improved scalability for larger projects.
Setting up SeleniumBase
To install SeleniumBase, you can use pip to install the package:
pip install seleniumbase
Running your first test
Once you've installed SeleniumBase, you can create your first test that will connect to a remote TestingBot browser.
Python Example:
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class DemoSiteTests(BaseCase):
def test_demo_site(self):
# Open a web page in the active browser window
self.open("https://seleniumbase.io/demo_page")
# Assert the title of the current web page
self.assert_title("Web Testing Page")
# Assert that an element is visible on the page
self.assert_element("tbody#tbodyId")
# Assert that a text substring appears in an element
self.assert_text("Demo Page", "h1")
You can now run this script on a TestingBot remote browser:
pytest test_demo_site.py --server=API_KEY:API_SECRET@hub.testingbot.com --port=443 --protocol=https --cap_file=capabilities/cap_file_TB.py
The capabilities are passed as a file, in this case an example cap_file_TB.py could look like this:
capabilities = {
"browserName": "chrome",
"browserVersion": "latest",
"platformName": "WIN11",
"tb:options": {
"name": "SeleniumBase Test"
}
}
Specify Browsers & Devices
To let TestingBot know on which browser/platform you want to run your test on, you need to specify the browsername, version, OS and other optional options in a capabilities file.
Testing Internal Websites
We've built TestingBot Tunnel, to provide you with a secure way to run tests against your staged/internal webapps.
Please see our TestingBot Tunnel documentation for more information about this easy to use tunneling solution.
The example below shows how to easily run a SeleniumBase test with our Tunnel:
1. Download our tunnel and start the tunnel:
java -jar testingbot-tunnel.jar key secret
2. Adjust your test command to point to your tunnel's IP address:
pytest test_demo_site.py --server=localhost --port=4445 --protocol=http --cap_file=capabilities/cap_file_TB.py
Run tests in Parallel
Parallel Testing means running the same test, or multiple tests, simultaneously. This greatly reduces your total testing time.
SeleniumBase supports parallel test execution using pytest-xdist:
pip install pytest-xdist
pytest -n 4 --server=API_KEY:API_SECRET@hub.testingbot.com --port=443 --protocol=https
Queuing
Every plan we provide comes with a limit of parallel tests.
If you exceed the number of parallel tests assigned to your account, TestingBot will queue the additional tests (for up to 6 minutes) and run the tests as soon as slots become available.
Mark tests as passed/failed
As TestingBot has no way to determine whether your test passed or failed (it is determined by your business logic), we offer a way to send the test status back to TestingBot. This is useful if you want to see if a test succeeded or failed from the TestingBot member area.
You can use our Python API client to report back test results.
from testingbotclient import TestingBotClient
client = TestingBotClient('API_KEY', 'API_SECRET')
client.tests.update_test(
driver.session_id,
name='My Test',
passed=True,
build='build-123'
)
Other Python Framework examples
-
PyTest
PyTest makes it easy to run Selenium tests with Python.
-
Behave
Behave is behaviour-driven development, Python style.
-
Lettuce
Lettuce is a Python BDD plugin based on Ruby's Cucumber, offering Gherkin stories.
-
PyUnit
PyUnit is the standard unit testing framework module for Python, described as a Python version of JUnit.
-
Helium
Helium is a tool that makes it easy to test websites and automate browsers.
-
Pylenium
Pylenium brings the best of Selenium, Cypress and Python into one package.
-
SeleniumBase
SeleniumBase is a Python package that simplifies Selenium testing.
-
Robot Framework
Robot Framework is a generic automation framework for acceptance testing.
More Information
More information regarding SeleniumBase is available on the SeleniumBase documentation.