Search code examples
seleniumautomated-testsbddgherkinkatalon-studio

How to structure BDD scenarios for situations with a lot of variables


Our team is new to BDD development/specification, and from a testautomation perspective we would like to get some advice on setting up BDD scenarios (and the Steps) in a situation where there are a lot of variables, like with forms.

Here is the situation: A form to create employees, which consists of multiple subjects like personal information, job details, salary, etc.

A possible scenario outline the team has come up with:

Given I want to add a new employee
And the job title is "jobtitle"
When I submit the form
Then a notification is sent to "manager"

Examples:
|jobtitle|manager|
|Developer|John Doe|

The steps above describe only the deciding factors for the outcome of the scenario. So what name a person might have or what salary he/she will earn won't affect the scenario. However, in another scenario a different field might be the deciding factor, like someones department. In this case, how would be bundle the scenarios or the underlying steps, so we can re-use as much as possible? Because even though in this exaple the jobtitle is the deciding factor, we still need to fill in all other mandatory fields to be able to submit the form. Any advice is welcome!


Solution

  • I would define some types of employee and get the right details in the code.

    for example: junior admin, senior admin, manager assistant Each description tells something about job details, salary and role.

    Based on these you generate the salary and job description in a method.

    In your bdd scenario:
    Given I have an junior admin employee
    where junior admin is a parameter that you can use to get what data type you need and create the user.

        /**
         * @When /^I have an (junior admin|senior hr) employee$/
         */
        public function iHaveAnEmployee($employeeType)
        {
            // generate data for employee
            $employee = someMethodThatGeneratesEmployeeDetails($employeeType);
    
           // create the employee
           someMethodThatCreatesTheEmployee($employee);
        }

    If you want to see those details in the report then find a way to print them there after the step runs.