Get more updates and further details about your project right in your mailbox.
The best time to establish protocols with your clients is when you onboard them.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.
The “Gherkin” programming language is used by the Cucumber framework to run automated tests.
Two main files are used in the Cucumber framework. “Feature File” and “Step-definitions” are two of them.
There are a lot of frameworks available for web automation, but Cucumber is the best option when compared to other alternatives.
Cucumber framework has 3 major parts.
Feature file — Here the tests are written by the plain text that the file is called feature files it saved with the extension of “.feature”. These file elaborate how the project behaves and works by using the special kind of language is called “Gherkin”. Gherkin is the structured language that used the keyword “Given, When, Then”.
For example,
Given : Its a pre-conditions or the starting stage.
When : Its refer to the triggering object(What we do next)
Then : Its have the Expected outcome.
Step-definitions- What are the tests written in the feature file is associated with the step-definitions. The test fails having the certain action of code that tells the system what to do for that scenarios. If the Scenarios says “Click on the login button”, then the tests having the flow of action regarding the same.\
Test Runner file — Runner file runs the feature file and association with the corresponding step definitions.
Before going to the framework, we need to know what requirements are needed to set up the framework.
Pre-requirements:
Below I’ve listed the packages required for the setup.
You can use the following command to add the below packages which is added in the requirements.txt file.
For example, “pip install package_name” → “pip install selenium==4.13.0”.
├── requirements.txt/
Now we move on to the framework structure for Python project with Cucumber set-up.
Note: Prior to that, it is necessary to create the Python project.
In below framework I used “LeetCode” website to automate the features.
Here we used the following hooks “before_all, before_feature, and after_scenario”.
before_all: This hook runs at a single time. Whatever we want to run at only one time (like initialization or set-up) we can provide below “before_all” hooks.
before_feature: This hook executes before each feature. This hook is best used for ‘logging in’ or preparing data for the Scenario.
after_scenario: This hook executes after each scenario. Let’s take that you have 13 Scenarios in your feature this after_scenario hook executes after each scenario is done.
├── environment.py/
I used the browsersetup.py class inside of the browser selection folder.
├── browserselection/│ ├── browsersetup.py/
Browser-setup class has the Browser selection like which browser we want to use to run the Web application.
├── steps/│ ├── before_signIn_step.py/
├── pages/│ ├── Before_signIn_page.py/
Below the .ini file, you can modify the “url & browser_type — configuration parameter” based on your requirements.
If you need any other configuration Parameter and value you can add it here as well.
├── default_config.ini/
I used the properties.py class inside of the config folder. This class contains the method to read the config file
Here we read the “url, browser_type” from the “.ini” file.
├── configs/│ ├── properties.py/
├── commons/│ ├── lib_global.py/
The below files contain the feature file which has “Simple English”. You can modify the below file based on your needs. The file saved by the file contains “.feature”.
feature/login_with_invalid_credentials.feature
├── features/│ ├── login_with_invalid_credentials.feature/
Here are the steps that are created for the above features.
Note: Ensure that the step definitions are the same as the Given, When, and Then scenarios specified in the feature.
steps/login_with_invalid_credentials_step.py
Here are the pages that are created for the steps that are created for the related feature file. In the pages file, we can give the functionality of related tests.
pages/login_with_invalid_credentials_page.py
├── pages/│ ├── login_with_invalid_credentials_page.py/
pages/login_with_invalid_credentials_page.py
Import the needed packages and folders for the Login page.
You have successfully configured the framework set-up.
Navigate your project folder and type the following command to run your feature file:
behave --format allure_behave.formatter:AllureFormatter --outfile allure-results
Note: The way to handle, incase you are facing following exception after successfully create the project with cucumber framework setup.
browser_type = config[“Browser”][“browser_type”]
After run the feature file type the following command to generate the allure report:
allure generate allure-results -o allure-report --clean
Type the following command to open the report:
allure open allure-report
Sample allure report will be.,
Attached herewith is my sample framework (GitHub repo) for your reference.
Allure is an open-source framework designed to generate detailed test reports for various testing frameworks such as Pytest, JUnit, TestNG, Cucumber, and more.
Here I listed some annotations which are available in Allure:
@Feature , @Story , @Step , @Attachment , @Description , @Severity , @Issue , @Link , @Owner , @Tag , @Epic .,
In our project, we used the following annotations: “@Step” and “@Attachment”.
These annotations are used for detailing the steps of our test scenarios and attaching additional information, such as screenshots or log files, to our test reports.
Here’s how you can implement ‘with allure.step’ effectively in your project.
Allure Report output:
You can used the mentioned annotations according to your specific requirements.