{"id":13595672,"url":"https://github.com/pytest-dev/pytest-splinter","last_synced_at":"2025-04-09T13:33:08.454Z","repository":{"id":14183038,"uuid":"16889277","full_name":"pytest-dev/pytest-splinter","owner":"pytest-dev","description":"pytest splinter and selenium integration for anyone interested in browser interaction in tests","archived":false,"fork":false,"pushed_at":"2023-06-15T13:58:36.000Z","size":350,"stargazers_count":253,"open_issues_count":14,"forks_count":51,"subscribers_count":42,"default_branch":"master","last_synced_at":"2024-10-02T00:48:53.780Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pytest-dev.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst"}},"created_at":"2014-02-16T17:03:35.000Z","updated_at":"2024-07-11T18:26:20.000Z","dependencies_parsed_at":"2024-01-29T11:09:56.592Z","dependency_job_id":null,"html_url":"https://github.com/pytest-dev/pytest-splinter","commit_stats":{"total_commits":275,"total_committers":32,"mean_commits":8.59375,"dds":0.4945454545454545,"last_synced_commit":"1b0aa1efaec40919d79d424bb6d5c418925f2ad6"},"previous_names":[],"tags_count":74,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytest-dev%2Fpytest-splinter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytest-dev%2Fpytest-splinter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytest-dev%2Fpytest-splinter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pytest-dev%2Fpytest-splinter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pytest-dev","download_url":"https://codeload.github.com/pytest-dev/pytest-splinter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223394695,"owners_count":17138598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T16:01:55.288Z","updated_at":"2024-11-06T18:31:29.246Z","avatar_url":"https://github.com/pytest-dev.png","language":"Python","readme":"Splinter plugin for the pytest runner\n======================================\n\n.. image:: https://badges.gitter.im/pytest-dev/pytest-splinter.svg\n   :alt: Join the chat at https://gitter.im/pytest-dev/pytest-splinter\n   :target: https://gitter.im/pytest-dev/pytest-splinter?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n\n.. image:: https://img.shields.io/pypi/v/pytest-splinter.svg\n   :target: https://pypi.python.org/pypi/pytest-splinter\n.. image:: https://img.shields.io/pypi/pyversions/pytest-splinter.svg\n  :target: https://pypi.python.org/pypi/pytest-splinter\n.. image:: https://img.shields.io/coveralls/pytest-dev/pytest-splinter/master.svg\n   :target: https://coveralls.io/r/pytest-dev/pytest-splinter\n.. image:: https://github.com/pytest-dev/pytest-splinter/actions/workflows/tests.yml/badge.svg\n        :target: https://github.com/pytest-dev/pytest-splinter/actions\n.. image:: https://readthedocs.org/projects/pytest-splinter/badge/?version=latest\n    :target: https://readthedocs.org/projects/pytest-splinter/?badge=latest\n    :alt: Documentation Status\n\n\nInstall pytest-splinter\n-----------------------\n\n::\n\n    pip install pytest-splinter\n\n\nFeatures\n--------\n\nThe plugin provides a set of fixtures to use `splinter \u003chttps://splinter.readthedocs.io\u003e`_\nfor browser testing with `pytest \u003chttp://pytest.org\u003e`_\n\n\nFixtures\n--------\n\n* browser\n    Get the splinter's Browser. Fixture is underneath session scoped, so browser process is started\n    once per test session, but the state of the browser will be clean (current page is ``blank``, cookies clean).\n\n* session_browser\n    The same as ``browser`` except the lifetime. This fixture is session-scoped so will only be finalized at the\n    end of the whole test session. Useful if you want to speedup your test suite paying with reduced test isolation.\n\n* browser_instance_getter\n    Function to create an instance of the browser. This fixture is required only if you need to have\n    multiple instances of the Browser in a single test at the same time. Example of usage:\n\n.. code-block:: python\n\n    @pytest.fixture\n    def admin_browser(request, browser_instance_getter):\n        \"\"\"Admin browser fixture.\"\"\"\n        # browser_instance_getter function receives parent fixture -- our admin_browser\n        return browser_instance_getter(request, admin_browser)\n\n    def test_2_browsers(browser, admin_browser):\n        \"\"\"Test using 2 browsers at the same time.\"\"\"\n        browser.visit('http://google.com')\n        admin_browser.visit('http://admin.example.com')\n\n* splinter_selenium_implicit_wait\n    Implicit wait timeout to be passed to Selenium webdriver.\n    Fixture gets the value from the command-line option splinter-implicit-wait (see below)\n\n* splinter_wait_time\n    Explicit wait timeout (for waiting for explicit condition via `wait_for_condition`).\n    Fixture gets the value from the command-line option splinter-wait-time (see below)\n\n* splinter_selenium_speed\n    Speed for Selenium, if not 0 then it will sleep between each selenium command.\n    Useful for debugging/demonstration.\n    Fixture gets the value from the command-line option splinter-speed (see below)\n\n* splinter_selenium_socket_timeout\n    Socket timeout for communication between the webdriver and the browser.\n    Fixture gets the value from the command-line option splinter-socket-timeout (see below)\n\n* splinter_webdriver\n    Splinter's webdriver name to use. Fixture gets the value from the command-line option\n    splinter-webdriver (see below). To make pytest-splinter always use certain webdriver, override a fixture\n    in your `conftest.py` file:\n\n.. code-block:: python\n\n    import pytest\n\n    @pytest.fixture(scope='session')\n    def splinter_webdriver():\n        \"\"\"Override splinter webdriver name.\"\"\"\n        return 'chrome'\n\n* splinter_remote_url\n    Splinter's webdriver remote url to use (optional). Fixture gets the value from the command-line option\n    splinter-remote-url (see below). Will be used only if selected webdriver name is 'remote'.\n\n* splinter_session_scoped_browser\n    pytest-splinter should use single browser instance per test session.\n    Fixture gets the value from the command-line option splinter-session-scoped-browser (see below)\n\n* splinter_file_download_dir\n    Directory, to which browser will automatically download the files it\n    will experience during browsing. For example when you click on some download link.\n    By default it's a temporary directory. Automatic downloading of files is only supported for firefox driver\n    at the moment.\n\n* splinter_download_file_types\n    Comma-separated list of content types to automatically download.\n    By default it's the all known system mime types (via mimetypes standard library).\n\n* splinter_browser_load_condition\n    Browser load condition, python function which should return True.\n    If function returns False, it will be run several times, until timeout below reached.\n\n* splinter_browser_load_timeout\n    Browser load condition timeout in seconds, after this timeout the exception\n    WaitUntilTimeout will be raised.\n\n* splinter_wait_time\n    Browser explicit wait timeout in seconds, after this timeout the exception\n    WaitUntilTimeout will be raised.\n\n* splinter_firefox_profile_preferences\n    Firefox profile preferences, a dictionary which is passed to selenium\n    webdriver's profile_preferences\n\n* splinter_firefox_profile_directory\n    Firefox profile directory to use as template for firefox profile created by selenium.\n    By default, it's an empty directly inside pytest_splinter/profiles/firefox\n\n* splinter_driver_kwargs\n    Webdriver keyword arguments, a dictionary which is passed to selenium\n    webdriver's constructor (after applying firefox preferences)\n    \n.. code-block:: python\n\n    import pytest\n    from pathlib import Path\n    \n    @pytest.fixture\n    def splinter_driver_kwargs():\n        \"\"\"\n        Webdriver kwargs for Firefox.\n        https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver\n        \"\"\"\n        return {\"service_log_path\": Path(\"/log/directory/geckodriver.log\")}\n\nThe snippet below configures Chrome to ignore certificate errors and sets a specific window size\n\n.. code-block:: python\n\n    import pytest\n    from selenium import webdriver\n\n    @pytest.fixture(scope='session')\n    def splinter_driver_kwargs():\n        \"\"\"Override Chrome WebDriver options\"\"\"\n        chrome_options = webdriver.ChromeOptions()\n\n        # List of Chromium Command Line Switches\n        # https://peter.sh/experiments/chromium-command-line-switches/\n        chrome_options.add_argument(\"--window-size=1440,1200\")\n        chrome_options.add_argument(\"--ignore-ssl-errors=yes\")\n        chrome_options.add_argument(\"--ignore-certificate-errors\")\n\n        return {\"options\": chrome_options}\n\n* splinter_window_size\n    Size of the browser window on browser initialization. Tuple in form (\u003cwidth\u003e, \u003cheight\u003e). Default is (1366, 768)\n\n* splinter_screenshot_dir\n    pytest-splinter browser screenshot directory.\n    This fixture gets the value from the command-line option\n    `splinter-screenshot-dir` (see below).\n\n* splinter_make_screenshot_on_failure\n    Should pytest-splinter take browser screenshots on test failure?\n    This fixture gets the value from the command-line option\n    `splinter-make-screenshot-on-failure` (see below).\n\n* splinter_screenshot_encoding\n    Encoding of the `html` `screenshot` on test failure. UTF-8 by default.\n\n* splinter_screenshot_getter_html\n    Function to get browser html screenshot. By default, it saves `browser.html` with given path and\n    `splinter_screenshot_encoding` encoding.\n\n* splinter_screenshot_getter_png\n    Function to get browser image (png) screenshot. By default, it calls `browser.save_sceenshot`\n    with given path.\n\n* splinter_driver_executable\n    Filesystem path of the webdriver executable.\n    This fixture gets the value from the command-line option\n    `splinter-webdriver-executable` (see below).\n\n* splinter_browser_class\n    Class to use for browser instance.\n    Defaults to `pytest_splinter.plugin.Browser`.\n\n* splinter_clean_cookies_urls\n    List of additional urls to clean cookies on. By default, during the preparation of the browser for the test,\n    pytest-splinter only cleans cookies for the last visited url from previous test, as it's not possible to clean\n    all cookies from all domains at once via webdriver protocol, by design. This limitation can be worked around if\n    you know the list of urls, the domains for which you need to clean cookies (for example https://facebook.com).\n    If so, you can override this fixture and put those urls there, and pytest-splinter will visit each of them and will\n    clean the cookies for each domain.\n\n* splinter_headless\n    Run Chrome in headless mode. Defaults to false. http://splinter.readthedocs.io/en/latest/drivers/chrome.html#using-headless-option-for-chrome\n\nCommand-line options\n--------------------\n\n* `--splinter-implicit-wait`\n    Selenium webdriver implicit wait. Seconds (default: 5).\n\n* `--splinter-speed`\n    selenium webdriver speed (from command to command). Seconds (default: 0).\n\n* `--splinter-socket-timeout`\n    Selenium webdriver socket timeout for for communication between the webdriver and the browser.\n    Seconds (default: 120).\n\n* `--splinter-webdriver`\n    Webdriver name to use. (default: firefox). Options:\n\n    *  firefox\n    *  remote\n    *  chrome\n\n    For more details refer to the documentation for splinter and selenium.\n\n* `--splinter-remote-url`\n    Webdriver remote url to use. (default: None). Will be used only if selected webdriver name is 'remote'.\n\n    For more details refer to the documentation for splinter and selenium.\n\n* `--splinter-session-scoped-browser`\n    pytest-splinter should use a single browser instance per test session.\n    Choices are 'true' or 'false' (default: 'true').\n\n* `--splinter-make-screenshot-on-failure`\n    pytest-splinter should take browser screenshots on test failure.\n    Choices are 'true' or 'false' (default: 'true').\n\n* `--splinter-screenshot-dir`\n    pytest-splinter browser screenshot directory. Defaults to the current\n    directory.\n\n* `--splinter-webdriver-executable`\n    Filesystem path of the webdriver executable. Used by chrome driver.\n    Defaults to the None in which case the shell PATH variable setting determines the location of the executable.\n\n* `--splinter-headless`\n    Override `splinter_headless` fixture. Choices are 'true' or 'false', default: 'true'.\n    http://splinter.readthedocs.io/en/latest/drivers/chrome.html#using-headless-option-for-chrome\n    https://splinter.readthedocs.io/en/latest/drivers/firefox.html#using-headless-option-for-firefox\n\nBrowser fixture\n---------------\n\nAs mentioned above, browser is a fixture made by creating splinter's Browser object, but with some overrides.\n\n*  visit\n    Added possibility to wait for condition on each browser visit by having a fixture.\n\n*  wait_for_condition\n    Method copying selenium's wait_for_condition, with difference that condition is in python,\n    so there you can do whatever you want, and not only execute javascript via browser.evaluate_script.\n\n\nAutomatic screenshots on test failure\n-------------------------------------\n\nWhen your functional test fails, it's important to know the reason.\nThis becomes hard when tests are being run on the continuous integration server,\nwhere you cannot debug (using --pdb).\nTo simplify things, a special behaviour of the browser fixture is available,\nwhich takes a screenshot on test failure and puts it in a folder with the a\nnaming convention compatible to the\n`jenkins plugin \u003chttps://wiki.jenkins-ci.org/display/JENKINS/JUnit+Attachments+Plugin\u003e`_.\nThe html content of the browser page is also stored, this can be useful for debugging the html source.\n\nCreating screenshots is fully compatible with `pytest-xdist plugin\n\u003chttps://pypi.python.org/pypi/pytest-xdist\u003e`_ and will transfer the screenshots\nfrom the worker nodes through the communication channel automatically.\n\nIf a test (using the browser fixture) fails, you should get a screenshot files\nin the following path:\n\n::\n\n    \u003csplinter-screenshot-dir\u003e/my.dotted.name.test.package/test_name-browser.png\n    \u003csplinter-screenshot-dir\u003e/my.dotted.name.test.package/test_name-browser.html\n\nThe `splinter-screenshot-dir` for storing the screenshot is generated by a\nfixture and can be provided through a command line argument, as described above\nat the configuration options section.\n\nTaking screenshots on test failure is enabled by default. It can be controlled\nthrough the `splinter_make_screenshot_on_failure` fixture, where return `False`\nskips it. You can also disable it via a command line argument:\n\n::\n\n    pytest tests/functional --splinter-make-screenshot-on-failure=false\n\nIn case taking a screenshot fails, a pytest warning will be issued, which\ncan be viewed using the `-rw` argument for `pytest`.\n\n\nPython3 support\n---------------\n\nPython3 is supported, check if you have recent version of splinter as it was added recently.\n\n\nExample\n-------\n\ntest_your_test.py:\n\n.. code-block:: python\n\n    def test_some_browser_stuff(browser):\n        \"\"\"Test using real browser.\"\"\"\n        url = \"http://www.google.com\"\n        browser.visit(url)\n        browser.fill('q', 'splinter - python acceptance testing for web applications')\n        # Find and click the 'search' button\n        button = browser.find_by_name('btnK')\n        # Interact with elements\n        button.click()\n        assert browser.is_text_present('splinter.cobrateam.info'), \"splinter.cobrateam.info wasn't found... We need to\"\n        ' improve our SEO techniques'\n\n\nContact\n-------\n\nIf you have questions, bug reports, suggestions, etc. please create an issue on\nthe `GitHub project page \u003chttp://github.com/paylogic/pytest-splinter\u003e`_.\n\n\nLicense\n-------\n\nThis software is licensed under the `MIT license \u003chttp://en.wikipedia.org/wiki/MIT_License\u003e`_\n\nSee `License file \u003chttps://github.com/paylogic/pytest-splinter/blob/master/LICENSE.txt\u003e`_\n\n\n© 2014 Anatoly Bubenkov, Paylogic International and others.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytest-dev%2Fpytest-splinter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpytest-dev%2Fpytest-splinter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpytest-dev%2Fpytest-splinter/lists"}