Simple behave Script – Add Two Numbers



You have completed Python, selenium, behave installation steps described at the beginning of the tutorial. You have also downloaded the template project, imported in pycharm.



  1. Intent is to add two numbers a and b and output the sum (a+b)
  2. Write First behave feature file 
  3. Write first scenario in the feature file
  4. Execute the scenario as is (It will fail since we did not write step definitions)
  5. Complete the code-behind (aka. step definitions) each step for the scenario
  6. Execute the scenario again
  7. The scenario passes and all steps pass too (GREEN as in Cucumber)
  8. The entire video is posted at the end ofComplete First Automation Script


1. Open the template project in pycharm



2. Pycharm will suggest to install any pip libraries by default if they are not found in your system. The libraries we use at this point are in requirements.text.




3. If for some reason, your step 2 , pycharm doesn’t suggest to install (this typically is for first time installations), then you can explicitly install the libraries, by going to the root directory (in this case python_behave_template) and execte “pip install -r requirements.text)


4. Now right click on the folder “features” and select “New Gherkin feature” (If for some reason, you do not have that option, you can also select “New file” and create the .feature). In my case, I already have the first_behave.feature file, however this is to demonstrate that you can create .features files in this way. Note: You are NOT required to do this step, because “first_behave.feature” already comes with the template project.



5.  Double Click on the “first_behave.feature” file and you can see the below



6. Right click anywhere on the feature and click “Run….” as shown below



7. Since, we did not define any step definitions yet, you should see the below output. Observe the “Test undefined…..” output. Indeed , we haven’t written the code behind, so this is expected




In the next post, we will complete the scenario by writing the code behind (the step definitions)