Simple behave Script – Add Two Numbers

 

Pre-Requisites:

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.

 

Agenda:

  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

 

pycharm_template_imported

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.

behave_first_project_pip_reqs

 

 

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)

behave_pip_install

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.

behave_new_feature_file

 

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

behave_first_feature

 

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

behave_first_feature_run

 

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

behave_first_feature_run_results

 

 

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