Splinter subplugin for Pytest BDD plugin
pip install pytest-splinter
The plugin provides many useful fixtures to be used if you’re using splinter for browser testing
- Get the splinter’s Browser. Fixture is underneath session scoped, so browser process is started once per test session.
- Implicit wait timeout to be passed to Selenium webdriver. Fixture gets the value from the command-line option splinter-implicit-wait (see below)
- Speed for Selenium, if not 0 then it will sleep between each selenium command. Useful for debugging/demonstration. Fixture gets the value from the command-line option splinter-speed (see below)
- Socket timeout for communication between the webdriver and the browser. Fixture gets the value from the command-line option splinter-socket-timeout (see below)
- Splinter’s webdriver name to use. Fixture gets the value from the command-line option splinter-webdriver (see below)
- pytest-splinter should use single browser instance per test session. Fixture gets the value from the command-line option splinter-session-scoped-browser (see below)
- Directory, to which browser will automatically download the files it will experience during browsing. For example when you click on some download link. By default it’s a temporary directory. Automatic downloading of files is only supported for firefox driver at the moment.
- Comma-separated list of content types to automatically download. By default it’s the all known system mime types (via mimetypes standard library).
- Browser load condition, python function which should return True. If function returns False, it will be run several times, until timeout below reached.
- Browser load condition timeout in seconds, after this timeout the exception WaitUntilTimeout will be raised.
- Firefox profile preferences, a dictionary which is passed to selenium webdriver’s profile_preferences
- Webdriver keyword arguments, a dictionary which is passed to selenium webdriver’s constructor (after applying firefox preferences)
- Size of the browser window on browser initialization. Tuple in form (<width>, <height>). Default is (1366, 768)
Selenium webdriver implicit wait. Seconds (default: 1).
selenium webdriver speed (from command to command). Seconds (default: 0).
Selenium webdriver socket timeout for for communication between the webdriver and the browser. Seconds (default: 120).
Webdriver name to use. (default: firefox). Options:
For more details, refer to splinter and selenium documentation.
pytest-splinter should use single browser instance per test session. (set by default).
As mentioned above, browser is a fixture made by creating splinter’s Browser object, but with some overrides.
- Added possibility to wait for condition on each browser visit by having a fixture.
- This functionality is removed, so not available. Splinter implements this using additional request from python side, which is in general performance-wise not a good idea. Also normally when you interact with the browser as a user, you don’t need the status code of the page.
Python3 is supported, check if you have recent version of splinter as it was added recently.
def test_some_browser_stuff(browser): """Test using real browser.""" url = "http://www.google.com" browser.visit(url) browser.fill('q', 'splinter - python acceptance testing for web applications') # Find and click the 'search' button button = browser.find_by_name('btnK') # Interact with elements button.click() assert browser.is_text_present('splinter.cobrateam.info'), 'splinter.cobrateam.info wasn't found... We need to' ' improve our SEO techniques'
If you have questions, bug reports, suggestions, etc. please create an issue on the GitHub project page.
- unicode fixes to setup.py (bubenkoff,valberg)
- wait_for_condition now receives pytest_bdd.plugin.Browser object, not selenium webdriver one (bubenkoff)
- Refactoring and cleanup (bubenkoff)
- Initial public release