English 中文(简体)
Behave - Runner Script
  • 时间:2024-12-22

Behave - Runner Script


Previous Page Next Page  

We can run a Behave test, by running the command pne 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 apppcation 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 pne 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 pne 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 pne 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