Skip to content

Gherkin syntax And and But #29

@corrado4eyes

Description

@corrado4eyes

And or But keywords is kind of syntactic sugar for the Gherkin syntax. They are used to avoid to be repetitive when describing some scenarios.

Docs

Instead of writing

feature("Some feature") {
    scenario("Some scenario") {
        given("The user is logged in") {
            // initialise user to be logged off
        }
        given("The user is not premium") {
            // initialise non premium user
        }
        then("The user should see the Home view") {
            // assert that the user sees the Home view and not another
        }
        then("The user should see the Upgrade button") {
            // assert toolbar is visible
        }
    }
}

One could simplify it

feature("Some feature") {
    scenario("Some scenario") {
        given("The user is logged in") {
            // initialise user to be logged off
        }.but("The user is not premium") {
            // initialise non premium user
        }
        
        then("The user should see the Home view") {
            // assert that the user sees the Home view and not another
        }.and("The user should see the Upgrade button") {
            // assert toolbar is visible
        }
        
    }
}

To note that but and and are basically an extension of then, when and given builder methods

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions