{ "info": { "author": "Spencer Young", "author_email": "spencer.young@spyoung.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Internet :: WWW/HTTP :: Browsers", "Topic :: Software Development :: Quality Assurance", "Topic :: Software Development :: Testing", "Topic :: Software Development :: Testing :: BDD" ], "description": "behave-webdriver\n================\n\nbehave-webdriver is a step library intended to allow users to easily write `selenium`_ webdriver tests with the\nbehave BDD testing framework.\nInspired by the `webdriverio/cucumber-boilerplate`_ project.\n\n|docs| |status| |version| |pyversions| |coverage|\n\nFor more details, see the `behave-webdriver documentation`_\n\n.. image:: https://raw.githubusercontent.com/spyoungtech/behave-webdriver/master/docs/_static/behave-webdriver.gif\n\n\n\n\nInstallation\n============\n\nInstallation is easy via pip. The install will require ``behave`` and ``selenium``.::\n\n pip install behave-webdriver\n\nUsing webdrivers\n----------------\n\nSelenium requires that you provide executables for the webdriver you want to use. Further, unless you specify the path to\nthe binary explicitly, selenium expects that this executable is in PATH. See these\n`driver installation notes`_ for more details.\n\n\nUsage\n=====\n\nBasic usage of this library with behave requires the following steps:\n\n1. import the step implementations\n2. set the ``behave_driver`` attribute on the behave ``context`` in your ``environment.py`` file.\n3. write your feature file\n4. run ``behave``\n\nImporting the step implementations\n----------------------------------\n\nIn order for your feature file steps to match our step implementations, behave needs to find them in your project.\nThis is as simple as importing our step definitions into your own step implementation file.\n\n.. code-block:: python\n\n # features/steps/webdriver_example.py\n from behave_webdriver.steps import *\n\n\nFor more information about `step implementations`_, see the behave tutorial.\n\n\nSet behave_driver in the environment\n------------------------------------\n\nOur step implementations specifically look at the behave context for a ``behave_driver`` attribute to use to run your tests.\nIn order for that to work, you'll have to provide this attribute in your ``environment.py`` file.\n\n.. code-block:: python\n\n # features/environment.py\n import behave_webdriver\n\n def before_all(context):\n context.behave_driver = behave_webdriver.Chrome()\n\n def after_all(context):\n # cleanup after tests run\n context.behave_driver.quit()\n\n\nThe webdriver classes provided by behave-webdriver inherit from selenium's webdriver classes, so they will accept all\nsame positional and keyword arguments that selenium accepts.\n\nSome webdrivers, such as Chrome, provide special classmethods like ``Chrome.headless`` which instantiates ``Chrome`` with\noptions to run headless. This is useful, for example in headless testing environments.\n\n.. code-block:: python\n\n def before_all(context):\n context.behave_driver = behave_webdriver.Chrome.headless()\n\n\nUsing a fixture\n^^^^^^^^^^^^^^^\n\n*New in 0.1.1*\n\nYou may also find it convenient to use a fixture to setup your driver as well. For example, to use our fixture with Firefox\n\n.. code-block:: python\n\n from behave_webdriver.fixtures import fixture_browser\n def before_all(context):\n use_fixture(fixture_browser, context, webdriver='Firefox')\n\nThis will also ensure that the browser is torn down at the corresponding `cleanup point`_.\n\n.. _cleanup point: http://behave.readthedocs.io/en/stable/fixtures.html#fixture-cleanup-points\n\nWriting the feature file\n------------------------\n\n.. code-block:: gherkin\n\n # my-minimal-project/features/myFeature.feature\n Feature: Sample Snippets test\n As a developer\n I should be able to use given text snippets\n\n Scenario: open URL\n Given the page url is not \"http://webdriverjs.christian-bromann.com/\"\n And I open the url \"http://webdriverjs.christian-bromann.com/\"\n Then I expect that the url is \"http://webdriverjs.christian-bromann.com/\"\n And I expect that the url is not \"http://google.com\"\n\n\n Scenario: click on link\n Given the title is not \"two\"\n And I open the url \"http://webdriverjs.christian-bromann.com/\"\n When I click on the link \"two\"\n Then I expect that the title is \"two\"\n\nRun behave\n----------\n\nThen run the tests, just like any other behave test\n\n.. code-block:: bash\n\n behave\n\nYou should then see an output as follows::\n\n Feature: Sample Snippets test # features/myFeature.feature:2\n As a developer\n I should be able to use given text snippets\n Scenario: open URL # features/myFeature.feature:6\n Given the page url is not \"http://webdriverjs.christian-bromann.com/\" # ../../behave_webdriver/steps/given.py:136 0.012s\n And I open the url \"http://webdriverjs.christian-bromann.com/\" # ../../behave_webdriver/steps/given.py:10 1.414s\n Then I expect that the url is \"http://webdriverjs.christian-bromann.com/\" # ../../behave_webdriver/steps/then.py:102 0.007s\n And I expect that the url is not \"http://google.com\" # ../../behave_webdriver/steps/then.py:102 0.007s\n\n Scenario: click on link # features/myFeature.feature:13\n Given the title is not \"two\" # ../../behave_webdriver/steps/given.py:81 0.006s\n And I open the url \"http://webdriverjs.christian-bromann.com/\" # ../../behave_webdriver/steps/given.py:10 0.224s\n When I click on the link \"two\" # ../../behave_webdriver/steps/when.py:21 0.622s\n Then I expect that the title is \"two\" # ../../behave_webdriver/steps/then.py:10 0.006s\n\n 1 feature passed, 0 failed, 0 skipped\n 2 scenarios passed, 0 failed, 0 skipped\n 8 steps passed, 0 failed, 0 skipped, 0 undefined\n Took 0m2.298s\n\nAdvanced usage; extending behave-webdriver\n==========================================\n\nbehave-webdriver is designed with **you** in-mind. You are free to extend the behavior of our webdriver classes to suit your\nunique needs. You can subclass our webdriver classes, use a custom selenium webdriver, write your own mixin, or use\na mixin somebody else provides for selenium.\n\n\nExample: selenium-requests\n--------------------------\n\n`selenium-requests`_ is a preexisting project that adds functionality of the popular ``requests`` library to selenium.\nIt is simple to use ``selenium-requests`` with behave-webdriver.\nThe following, and other examples, are available in the repo ``examples`` directory and in the full documentation.\n\n.. code-block:: python\n\n # examples/selenium-requests/features/environment.py\n from selenium import webdriver # or any custom webdriver\n from behave_webdriver.driver import BehaveDriverMixin\n from seleniumrequests import RequestMixin # or your own mixin\n\n class BehaveRequestDriver(BehaveDriverMixin, RequestMixin, webdriver.Chrome):\n pass\n\n def before_all(context):\n context.behave_driver = BehaveRequestDriver()\n.. code-block:: python\n\n # examples/selenium-requests/features/steps/selenium_steps.py\n from behave import *\n from behave_webdriver.steps import *\n from urllib.parse import urljoin\n\n @given('I send a {method} request to the page \"{page}\"')\n def send_request_page(context, method, page):\n url = urljoin(context.base_url, page)\n context.response = context.behave_driver.request(method, url)\n\n @then('I expect the response text contains \"{text}\"')\n def check_response_text_contains(context, text):\n assert text in context.response.text\n.. code-block:: gherkin\n\n # examples/selenium-requests/features/selenium-requests.feature\n Feature: Using selenium-requests\n As a developer\n I should be able to extend behave-webdriver with selenium-requests\n\n Scenario: use selenium-requests with behave-webdriver\n # use a behave-webdriver step\n Given the base url is \"http://127.0.0.1:8000\"\n # use your own steps using selenium-requests features\n Given I send a GET request to the page \"/\"\n Then I expect the response text contains \"