top of page
Writer's pictureNiharika Varshney

Harnessing Cucumber’s power with AIO Tests

Accelerate your automation

In our last article, we talked about BDD philosophy and how Gherkin with its simple set of rules, facilitates the description of system behaviors and sets the foundation for automation. But how does a Gherkin test translate into an automated test? This is where tools like Cucumber and Specflow come in.


Cucumber is a tool which supports Behavior Driven Development (BDD).  The key feature of Cucumber is its support for Gherkin, the domain-specific language of BDD.

Cucumber interprets Gherkin syntax and executes the corresponding test steps, thereby promoting test automation practices within agile software development teams.

Cucumber implementation are available in multiple programming languages like Java, Node.js, Ruby, C++, Scala, Kotlin, Python, Perl, Go and many more.


AIO Tests + Gherkin + Cucumber


AIO Tests helps not only in writing BDD tests, but supports the end to end BDD ecosystem, from authoring to generating feature files for Cucumber and all the way till reporting results from Cucumber automation runs.


Gherkin Tests can either be created manually or by providing a story as input to AIO Tests AI Assistant! Let’s start off with manually writing a Gherkin test in AIO Tests for a simple user story. Or better still, let's do both - manual and AI assisted!

If you already have existing feature files, then AIO also has an "Import Feature files" ability to bring in existing automated tests in AIO.

User Story

Writing Tests

 Create a case and on the Steps screen, select the BDD/Gherkin steps type.

 

As steps are typed in, they get stored in a steps repository and then can be re-used.  While automation, a similar concept works with step definitions, wherein steps can be reused across multiple scenarios. Save and our first case is ready!


Writing Tests with AI

Head over to the AI assistant and select the story to generate BDD cases or simply add relevant text in the Text Based option.  In the below screenshot, the AI assistant has generated 15 cases. Cases can be edited and steps can be added right where the cases are being generated.


Heading over to automation

Gherkin documents are stored in .feature files.  Each feature file can contain multiple scenarios to test a particular feature. AIO Tests provides a simple export functionality to get the feature files ready, providing a quick base for automation of cases.


Note Jira Story filter has been applied to export the cases to a feature file.


A .feature file gets exported with all the selected cases becoming scenarios.  The feature file starts with the feature keyword which is the title text of Jira story.  All steps are exported as scenario steps.  The testcase key from AIO is added as tag to the Scenario, which forms the mapping between the automated code and the AIO case.

Cucumber executes each step in a scenario one at a time, in the sequence in the file. When Cucumber tries to execute a step, it looks for a matching step definition to execute. Step definitions can be written in any language.  The below shows the Cucumber Java library providing the conventions to write the step definitions. 


Once the code is written to test the application, the inbuilt json reporter of Cucumber can be used to generate a local json report.  In Java, with JUnit or TestNG bindings, the @CucumberOptions annotation provides a way to setup the Cucumber arguments.

@CucumberOptions(
        features = "src/test/resources/features",tags = "@JREQ-NVTES-11",
        glue = {"com.aiotests.samples.stepdefs"}
        plugin = { "pretty", "json:target/cucumber-reports/ProductListingResults.json"})

Once the JSON report is generated, it can simply be exported in AIO Tests using an AIO Tests' APIs or by using AIO's Jenkins or Azure Devops plugins


A sample report updated in AIO shows the step level results for each step in the Gherkin scenario. Time taken to execute the case and actual failures are captured at the step level giving a complete view of execution.

And that's it! We have written our first BDD case, exported it, automated it in the tool of our choice and reported the automation run results in AIO Tests.




50 views0 comments

Comments


bottom of page