This project implements automation tests for the Selenium Web Form page using Behave (a BDD testing framework for Python), Selenium WebDriver and Allure Reports to create detailed performance reports.
The goal of this project is to demonstrate how to use Behave and Selenium WebDriver to create and execute automated tests based on scenarios described in the Gherkin language.
- Python - Programming language
- Behave - Framework for Behavior-Driven Development (BDD)
- Selenium WebDriver - Browser automation
- Gherkin - Language for describing test scenarios
The main code resides in the Behave step definition file, which connects the scenarios described in Gherkin files to Python code.
Here's the information organized in a table format:
Feature File | Description of Scenarios | Step File | Step Definitions Purpose |
---|---|---|---|
webform_actions_part_1.feature | Scenarios for text, password, and textarea inputs. | webform_actions_part_1.py | Contains step definitions for handling input scenarios. |
webform_actions_part_2.feature | Scenarios for dropdown boxes. | webform_actions_part_2.py | Contains step definitions for handling dropdown scenarios. |
webform_actions_part_3.feature | Scenarios for file input, checkbox and radio buttons. | webform_actions_part_3.py | Contains step definitions for handling file input and buttons scenarios. |
webform_actions_part_4.feature | Scenarios for color, date picker and range bar. | webform_actions_part_4.py | Contains step definitions for handling color, date picker and range bar scenarios. |
It includes three main steps:
- Given: Opens the web form page.
- When: Enters text into the input field.
- Then: Clicks the submit button.
@given(u'the browser open Webform page')
@when(u'insert a information in the text input field')
@then(u'the submit button will be clicked')
An example of how a scenario can be described in Gherkin in the features/form_test.feature file:
Feature: Test the Selenium Web Form
Scenario: Fill and submit the form
Given the browser open Webform page
When insert a information in the text input field
Then the submit button will be clicked
webform_selenium_behave_python/
├── allure-reports/ # Directory for Allure reports
├── features/ # Tests and automation logic
│ ├── pages/ # Page Objects (Page Object Pattern)
│ ├── steps/ # Step definitions (separated by part)
│ ├── *.feature # Gherkin test scenarios
├── behave.ini # Behave configuration
├── requirements.txt # Project dependencies
├── README.md # Project documentation
Follow these steps to set up and run the project:
- Clone this repository:
git clone https://github.com/your-username/selenium-behave-webform.git
cd selenium-behave-webform
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # Linux/Mac
venv\Scripts\activate # Windows
- Install the dependencies:
pip install -r requirements.txt
Make sure the requirements.txt file includes the following dependencies:
behave
selenium
- Install the WebDriver for your browser (e.g., ChromeDriver for Google Chrome). Ensure the driver is added to your system PATH.
To run the tests, use the following command:
behave
This will execute all scenarios described in the .feature files within the features directory.
- Install AlLure: Allure can be installed in various ways. Choose the method that best fits your environment:
Via Homebrew (macOS/Linux):
brew install allure
Via Chocolatey (Windows): First, install Chocolatey. Then:
choco install allure
Via Binary (manual): Download the zip file from Allure Releases. Extract the contents and add the binary directory to your PATH.
- Install Allure plugin for Python: Install the allure-behave package, which integrates Allure with Behave.
pip install allure-behave
- Set up project for Allure Make sure Behave test results are generated in a format compatible with Allure:
- Run Behave with the Allure Plugin: When running your Behave tests, include the -f allure_behave.formatter:AllureFormatter option to use the Allure format and -o allure-results to specify the output directory for the results.
Example:
behave -f allure_behave.formatter:AllureFormatter -o allure-results
-f: Specifies the report format.
-o: Specifies the output directory.
- Final Structure: After running the tests, Allure results will be saved in a directory called allure-results.
- Generate HTML Report Once the results are generated, use the Allure Commandline to create the report:
- Run the command to generate and view the report:
allure serve allure-results
This will open the report in your default browser. The report is served from a temporary local server.
- To create a static report:
allure generate allure-results -o allure-report
-
allure-results: Directory containing the raw test results.
-
allure-report: Directory where the HTML report will be saved.
-
To view the static report:
allure open allure-report
- Selenium Documentation
- Behave Documentation
- Guide to Writing Gherkin Scenarios
Contributions are welcome! Follow these steps to contribute:
- Fork this repository.
- Create a branch for your changes (git checkout -b feature/new-feature).
- Commit your changes (git commit -m 'Add new feature').
- Push to your branch (git push origin feature/new-feature).
- Open a Pull Request.
Made with ❤️ by Alisson (https://github.com/alisson-t-bucchi) Let me know if you need any additional modifications! 🚀