Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Behave reads behavior scenarios written in Gherkin and connects each step to Python code; Selenium WebDriver performs browser actions from that code. Together they let you test selected user journeys in a browser while keeping the scenario language focused on expected behavior—not a transcript of clicks.

This tutorial builds a small sign-in example, from installation through cleanup and troubleshooting. Behave’s stable tutorial is identified as version 1.3.3, while its “latest” documentation is labeled 1.4.0.dev0; Selenium’s Python API is labeled 4.50.0 and lists Python 3.10+ support. Those documentation labels are not a claim that every combination is a tested or certified version pair. See the Behave stable tutorial and Selenium Python API for current details.

What Behave and Selenium each do

Behavior-driven development (BDD) is a collaborative practice for describing and discussing how software should behave. Behave’s documentation describes BDD as encouraging collaboration among developers, QA, and business or non-technical participants. Behave executes feature files: it matches their Given, When, and Then steps to Python step implementations. Selenium is the browser-automation layer those implementations can call to locate elements, interact with pages, and observe results.

BDD is not another name for browser automation. A behavior scenario can be tested at a model or API layer instead of through a browser when that better verifies the behavior. Use Selenium for representative end-to-end browser journeys, not automatically for every scenario.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Install Behave and Selenium

Use an isolated Python environment. The commands below install the current packages; pin the versions you choose in your project dependency file if repeatable environments matter. The cited documentation does not establish a specific compatible Behave-and-Selenium version pair, so verify versions in your own environment rather than assuming one.

python -m venv .venv
# macOS or Linux:
source .venv/bin/activate
# Windows PowerShell:
# .venvScriptsActivate.ps1
python -m pip install --upgrade pip
python -m pip install behave selenium

Behave’s installation instructions use pip install behave; Selenium’s Python API recommends an isolated environment and pip install -U selenium. Selenium currently lists Python 3.10+ support. The browser itself must also be installed. For current Selenium, Selenium Manager generally handles obtaining a suitable browser driver when WebDriver starts; manual driver configuration is still available, and Manager does not remove every machine-, network-, or browser-specific setup issue. Documented browser and protocol targets include Chrome, Edge, Firefox, Safari, WebKitGTK, and WPEWebKit.

Create the feature and Python files

Behave’s conventional minimum is a features/ directory with feature files and a steps/ subdirectory containing Python implementations. This example adds an environment hook and a page-object module to separate browser mechanics from behavior steps.

project/
  features/
    login.feature
    environment.py
    steps/
      login_steps.py
    pages/
      login_page.py

Describe the outcome in Gherkin

Create features/login.feature:

Feature: Account sign in

  Scenario: A registered user reaches their account
    Given a registered user is ready to sign in
    When they submit valid credentials
    Then their account page is displayed

The steps state the behavior and outcome. They do not expose selectors, button labels, or a click-by-click script. The setup step below assumes the application has a known test account and is available at the configured base URL; change the example locators and URL to match your application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Start and close the browser deterministically

Create features/environment.py. This version creates a fresh browser for each scenario so one scenario’s cookies or page state do not silently affect another. A shared browser can reduce startup overhead, but increases the risk of state leaking between scenarios; choose intentionally.

import os

from selenium import webdriver


def before_scenario(context, scenario):
    context.base_url = os.environ.get("APP_BASE_URL", "http://localhost:8000")
    context.driver = webdriver.Chrome()


def after_scenario(context, scenario):
    driver = getattr(context, "driver", None)
    if driver is not None:
        driver.quit()

quit() closes the WebDriver session and its associated browser windows. Keeping cleanup in the teardown hook means it runs after a scenario even when a step fails. Selenium Manager may resolve the Chrome driver automatically when webdriver.Chrome() starts; if that fails in your environment, install or specify a suitable driver using Selenium’s documented options.

Put locators and waits in a page object

Create features/pages/login_page.py. Replace the example identifiers and selectors with those used by your sign-in page.

from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


class LoginPage:
    USERNAME = (By.ID, "username")
    PASSWORD = (By.ID, "password")
    SUBMIT = (By.CSS_SELECTOR, "button[type='submit']")
    ACCOUNT_HEADING = (By.CSS_SELECTOR, "[data-testid='account-heading']")

    def __init__(self, driver, base_url):
        self.driver = driver
        self.base_url = base_url
        self.wait = WebDriverWait(driver, 10)

    def open(self):
        self.driver.get(f"{self.base_url}/login")

    def sign_in(self, username, password):
        self.wait.until(EC.visibility_of_element_located(self.USERNAME)).send_keys(username)
        self.driver.find_element(*self.PASSWORD).send_keys(password)
        self.driver.find_element(*self.SUBMIT).click()

    def account_heading(self):
        return self.wait.until(
            EC.visibility_of_element_located(self.ACCOUNT_HEADING)
        ).text

The page object owns browser details and returns an observed value; the step owns the behavior assertion. This keeps locator changes out of the feature language and lets more than one scenario reuse page operations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Connect feature steps to Python

Create features/steps/login_steps.py:

import os

from behave import given, when, then

from features.pages.login_page import LoginPage


@given("a registered user is ready to sign in")
def registered_user_ready(context):
    context.username = os.environ.get("TEST_USERNAME", "test-user")
    context.password = os.environ.get("TEST_PASSWORD", "test-password")
    context.login_page = LoginPage(context.driver, context.base_url)
    context.login_page.open()


@when("they submit valid credentials")
def submit_valid_credentials(context):
    context.login_page.sign_in(context.username, context.password)


@then("their account page is displayed")
def account_page_is_displayed(context):
    assert context.login_page.account_heading() == "Your account"

Store real test credentials in environment variables or another appropriate secrets mechanism rather than committing them to source control. Run the scenario from the project directory with:

behave

Behave discovers feature files under features/, loads Python files under features/steps/, and matches decorated functions such as @given, @when, and @then to the feature text.

Use waits for observable conditions

Browser pages do not necessarily reach the needed state as soon as navigation or a click returns. The example uses WebDriverWait with expected conditions to wait for visible elements. Prefer a condition tied to the next action or assertion over a fixed sleep: sleeps wait the same amount regardless of whether the page is ready sooner or later.

Use one synchronization strategy consistently. Behave’s page-object guide warns that implicit waits configured with driver.implicitly_wait() can stack with explicit waits and produce unpredictable timeout durations. This example uses explicit waits and does not set an implicit wait. Adjust the timeout to the application and environment, and wait for the actual state the scenario needs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Keep scenarios behavior-focused

Gherkin is most useful when it communicates intent in language a product, QA, and engineering team can discuss. A scenario such as “When they submit valid credentials” expresses an action at the behavior level. A scenario that spells out every selector, click, and wait describes the current interface implementation and tends to change when that interface changes. Behave’s practical testing guidance recommends describing what an application should do rather than how it does it.

For a behavior that is better verified through business logic or a REST API, test at that layer where practical. Model/API tests can avoid browser-specific setup and isolate the behavior from the UI; browser scenarios can verify that important user-facing paths work end to end. This is a design trade-off, not a published speed or maintenance benchmark. Behave’s guidance discusses both layer choice and avoiding UI-detail-heavy scenarios.

Extend the example without turning features into scripts

Behave supports parameterized steps, data tables, text blocks, and Scenario Outlines with example rows. Use them when they make a meaningful behavior clearer—for example, checking the same sign-in outcome for a small set of credential cases. Keep setup data understandable, and avoid a single generic step language that hides what each scenario verifies. The stable tutorial documents these Gherkin and step-definition features.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

  • Behave reports an undefined step: The feature wording does not match a step decorator, or the implementation is not under features/steps/. Make the text match, check spelling and punctuation, and confirm Behave is being run from the project directory.
  • WebDriver cannot start or find a browser: Confirm the browser is installed and supported, and that the active Python environment has Selenium installed. Selenium Manager usually manages the driver, but network restrictions, browser availability, or machine configuration can still interfere. Check Selenium’s API documentation for manual driver setup options if needed.
  • A step times out waiting for an element: Verify the page URL, selector, and expected state in the actual application. Ensure the page has reached the state the wait targets, and choose a condition appropriate to that state, such as visibility rather than mere presence.
  • Timeouts take longer than expected: Avoid mixing implicit waits and explicit waits. Use one strategy, and inspect every wait’s condition and timeout.
  • Scenarios pass individually but fail in a suite: Check for shared browser, cookie, account, or server-side state. Use a fresh browser per scenario where isolation matters, reset test data, and retain teardown that calls quit().
  • Credentials are rejected: Confirm the test account exists in the target environment and that the environment variables are set. Avoid substituting production credentials into an automated test.

Or skip the browser setup

If you need a screenshot of a page rather than a Behave-driven interaction and assertion, ScreenshotNeo can return a screenshot or PDF with one API request. For example, save the response as a WebP image:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Does Behave control the browser?

No. Behave matches Gherkin steps to Python functions; those functions use Selenium WebDriver for browser interaction.

Can Behave scenarios test an API instead of a browser?

Yes. Behave can describe behavior while its Python step implementations exercise a model or API layer; use Selenium when the browser journey itself needs verification.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.