- Behave - Discussion
- Behave - Useful Resources
- Behave - Quick Guide
- Behave - Debugging
- Behave - Hooks
- Behave - Reports
- Behave - Retry Mechanism
- Behave - Exclude Tests
- Behave - Runner Script
- Behave - Step Parameters
- Behave - Step Functions
- Behave - Multi-Methods
- Behave - Optional Part
- Behave - Regular Expressions
- Behave - Step Matchers
- Behave - Enumeration
- Behave - Tags
- Behave - Data Types
- Behave - Background
- Behave - Steps in a Step
- Behave - Setup Table
- Behave - Multiline Text
- Behave - Scenario Outlines
- Behave - Step Parameters
- Behave - Supported Languages
- Behave - First Steps
- Behave - Step Implementations
- Behave - Feature Files
- Behave - Gherkin Keywords
- Behave - Feature Testing Setup
- Behave - Configuration Files
- Behave - Command Line
- Behave - Installation
- Behave - Introduction
- Behave - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Behave - Runner Script
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 −
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:
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.
Advertisements