<h2><imgsrc="https://seleniumbase.io/img/logo6.png"title="SeleniumBase"width="32"/> 🐝 Behave test runner for SeleniumBase 🐝</h2>
🐝 (Utilizes the [Behave BDD Python library](https://github.com/behave/behave). For more info, see the [Behave tutorial](https://behave.readthedocs.io/en/stable/tutorial.html) and read about [Behave's Gherkin model](https://behave.readthedocs.io/en/stable/gherkin.html).)
🐝 Behave examples with SeleniumBase: [SeleniumBase/examples/behave_bdd](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/behave_bdd)
🐝 The ``*.feature`` files can use any step seen from:
```bash
behave --steps-catalog
```
🐝 SeleniumBase includes several pre-made Behave steps, which you can use by creating a Python file with the following line in your ``features/steps/`` directory:
```python
from seleniumbase.behave import steps # noqa
```
🐝 Inside your ``features/environment.py`` file, you should have the following:
```python
from seleniumbase import BaseCase
from seleniumbase.behave import behave_sb
behave_sb.set_base_class(BaseCase) # Accepts a BaseCase subclass
from seleniumbase.behave.behave_sb import before_all # noqa
from seleniumbase.behave.behave_sb import before_feature # noqa
from seleniumbase.behave.behave_sb import before_scenario # noqa
from seleniumbase.behave.behave_sb import before_step # noqa
from seleniumbase.behave.behave_sb import after_step # noqa
from seleniumbase.behave.behave_sb import after_scenario # noqa
from seleniumbase.behave.behave_sb import after_feature # noqa
from seleniumbase.behave.behave_sb import after_all # noqa
```
🐝 If you've already created a subclass of ``BaseCase`` with custom methods, you can swap ``BaseCase`` in with your own subclass, which will allow you to easily use your own custom methods in your Behave step definitions.
🐝 Here's an example Python file in the ``features/steps/`` folder:
```python
from behave import step
@step("Open the Swag Labs Login Page")
def go_to_swag_labs(context):
sb = context.sb
sb.open("https://www.saucedemo.com")
sb.clear_local_storage()
@step("Login to Swag Labs with {user}")
def login_to_swag_labs(context, user):
sb = context.sb
sb.type("#user-name", user)
sb.type("#password", "secret_sauce\n")
@step("Verify that the current user is logged in")
Feature: SeleniumBase scenarios for the Fail Page # features/fail_page.feature:1
Scenario: Fail test on purpose to see what happens # features/fail_page.feature:3
When Open the Fail Page # features/steps/fail_page.py:4
Then Fail test on purpose # features/steps/fail_page.py:9
Assertion Failed: This test fails on purpose!
Captured stdout:
>>> STEP FAILED: (#2) Fail test on purpose
Class / Feature: SeleniumBase scenarios for the Fail Page
Test / Scenario: Fail test on purpose to see what happens
❌ Scenario Failed!
```
🐝🎖️ For convenience, the [SeleniumBase Behave GUI](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/behave_gui.md) lets you run ``behave`` scripts from a Desktop app.
🐝🎖️ To launch it, call ``sbase behave-gui`` or ``sbase gui-behave``:
```bash
sbase behave-gui
* Starting the SeleniumBase Behave Commander GUI App...