Web Module¶
The Web module provides steps for testing web applications with Selenium.
It covers navigation, interactions, waits, assertions, cookies, frame
handling, store/extract operations and browser configuration — 34 steps
in total, all with es and pt translations.
Installation¶
pip install "behave-steplib[web]"
Backends¶
Backend |
Package |
Notes |
|---|---|---|
|
|
Chrome and Firefox with headless support. Requires the |
Steps¶
Configuration¶
Pattern |
Description |
|---|---|
|
Set the base URL for subsequent navigations. |
|
Set the implicit wait time for element lookups. |
|
Set the page load timeout. |
|
Set the browser window size. |
Interactions¶
Pattern |
Description |
|---|---|
|
Click an element on the page. |
|
Type text into an input element, clearing it first. |
|
Clear an input element. |
|
Select an option from a dropdown by visible text. |
|
Take a screenshot and save it to a file. |
Waits¶
Pattern |
Description |
|---|---|
|
Wait until an element is present on the page. |
|
Wait until an element is visible on the page. |
|
Wait until the page contains specific text. |
Assertions¶
Pattern |
Description |
|---|---|
|
Assert the page title equals a value. |
|
Assert the current URL contains a fragment. |
|
Assert an element is present on the page. |
|
Assert an element is NOT present on the page. |
|
Assert an element is visible on the page. |
|
Assert an element is enabled. |
|
Assert an element’s text content equals a value. |
|
Assert an element’s attribute equals a value. |
|
Assert the page source contains text. |
|
Assert the page source does NOT contain text. |
The {by} placeholder uses Selenium’s By strategy names (id,
name, xpath, css_selector, class_name, tag_name,
link_text, partial_link_text).
Store and extract¶
Pattern |
Description |
|---|---|
|
Store an element’s text content as a variable. |
|
Store an element’s attribute value as a variable. |
|
Store the current browser URL as a variable. |
|
Store a cookie value as a variable. |
Example¶
Feature: Web navigation
Scenario: User visits the login page
Given the web base url is "https://example.com"
When I navigate to "/login"
Then the page title is "Login"
And the element id "username" is present
And the page contains "Sign In"
Driver lifecycle¶
The WebContext holds the browser
driver. It is created lazily and closed by cleanup():
from steplib.modules.web.client import get_driver
def before_all(context):
context.steplib = autoload(context)
context.steplib.web.driver = get_driver("selenium", browser="chrome", headless=True)
def after_scenario(context, scenario):
context.steplib.cleanup() # quits the browser
API reference¶
See Modules API Reference for the full autodoc reference of the Web module.