In this Blog ,you will learn how we can run Behave Project using BDD Framework in PyCharm IDE.
For that you do have to follow the below instructions:-
To download the Python ,click on the link and download the Python based on the platform you are using. https://www.python.org/downloads/
After download , Set the Path for Command Prompt
PyCharm is a dedicated Python Integrated Development Environment (IDE) providing a wide range of essential tools for Python developers, tightly integrated to create a convenient environment for productive Python, web, and data science development. PyCharm is a cross-platform IDE that works on Windows, macOS, and Linux.
There is two versions available Community Version (free and Open sourced) and Professional Version(paid). Download Community version.
Install selenium directories.
Open command Prompt -->Type Pip install selenium
Then Install Behave using Command Prompt -->Type Pip install behave.
So all the plugins and directories are installed ..lets start with creating a project
Create A Project
Open pycharm-->Click New Project --> Give the Name -->click create
As you can see New project is created
Now we have to install two package in py charm for that particular project. These two packages are:
Install Selenium Package
Install Behave Package
Select your project --> File -->New project Setup --> Setting for new project--> Click + icon
***Make sure you selected your Python interpreter otherwise add the interpreter first.
Search for selenium -->select it -->click install Package.
Search for behave --> select it -->click install package.
Now you successfully installed all the package associated with that project.
***As Selenium is an automation tool so we do need a web driver.
Next thing we must do is to download the specific driver for browser.
For that go to selenium official website
I am using chrome browser, which is very popular, but you can choose any one. Before downloading please cross check your browser version.
Let’s start creating the BDD framework for our project.
In BDD framework we do need
Feature Directory -->to create the features file for all the scenarios.
Steps Directory --> which will be used to create the steps.
Go to project --> Right click -->New--> Directory-->give name Features -->press enter.
Under the feature folder -->right click --->Directory-->give name steps -->press enter.
Create a new feature file under the folder feature.
Go to feature folder -->right click-->new-->file-->(filename). feature
***Make sure file name should end with . feature
As the first time pycharm doesn’t recognize it’s a feature file ,it will show up with the required gherkin plugin then click on install gherkin plugin .
Start writing your first feature using gherkin keywords. As I am working on DS Algo, there is my feature which is to verify the DS Algo portal page
Next step is to create the steps for the feature . For that you have
Go to the terminal and type behave Features\(feature file name),then enter.
As you can see All steps are created.
Create a new Python File Under the Directory Steps
Go to Steps directory --> Right Click -->New -->Python File -->(file Name ).py
***Make sure File Name should end with . py
Paste all the steps here.
Import all the Gherkins from behave .
Import webdriver from selenium.
You can change the names of the functions because feature file will associate with the syntax you wrote in gherkins. Then Write the code for all the steps.
below is my code for all the steps.
To run the code
Go to the terminal --> type Features\(Feature file name) -->press Enter
It will execute all your codes.
As you can see all the steps passed and it executed successfully.
Thanks for reading it.