Random Step Selection from Behave

  • Share this:

Code introduction


This function randomly selects a step type (Given, When, Then) from the Behave library and returns an instance of that step type. This can be used to dynamically generate test steps.


Technology Stack : Behave

Code Type : The type of code

Code Difficulty : Intermediate


                
                    
import random
from behave import Given, When, Then, Scenario, GivenStep, WhenStep, ThenStep

def random_feature():
    steps = {
        "Given": GivenStep,
        "When": WhenStep,
        "Then": ThenStep
    }
    
    step = random.choice(list(steps.values()))
    return step

def xxx(arg1, arg2):
    # This function randomly selects a step from Behave and returns it
    step = random_feature()
    return step                
              
Tags: