Behave – Runner Script


Behave – Runner Script



”;


We can run a Behave test, by running the command line arguments, or we can create a runner script. This script gives the provision of running the test and generating the corresponding report.

We can do a re-try and execute the failed test. Also, before executing the entire suite, the runner script is capable of making an application programming interface (API) call and ensuring that there are no issues with the API.

Steps for Runner Script

Follow the steps given below to create and execute a runner script successfully in Behave.

Step 1 − Create a runner script (runner.py) within the features folder.

The following screen will appear on your computer −


Steps for Runner Script

Step 2 − Runner Script Implementation to run tests

The runner script can be implemented to run the tests by using the below mentioned code −


import subprocess
if __name__ == ''__main__'':
#command line args along with error capture on failure with check true
      s = subprocess.run(''behave --no-capture'',shell=True, check=True)

Step 3 − Execute the runner script

Execute runner.py file with command python3 runner.py (if Python version is 3). The following screen will appear on your computer:


Execute the Runner Script

Step 4 − Parametrise runner script by passing command line arguments.

The runner script implementation to run tests can be done as follows −


import argparse
import subprocess
if __name__ == ''__main__'':
   p = argparse.ArgumentParser()
  #--testdir command line argument added
   p.add_argument(''--testdir'', required=False, help="File path")
   a = p.parse_args()
   testdir = a.testdir
   #complete command
   c= f''behave --no-capture {testdir}''
   s = subprocess.run(c, shell=True, check=True)

Step 5 − Execute the runner script

Execute runner.py file with command python3 runner.py –testdir=features.


Python3 Runner

Advertisements

”;

Leave a Reply

Your email address will not be published. Required fields are marked *