You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Overview

In this tutorial, we will perform some web/UI-based tests using Gwen interpreter along with gwen-web engine.

Gwen uses the Given, When, Then syntax from Gherkin (thus, its name) to implement an interpretation engine that allows users to easily write "automated tests" (i.e. automated scripts), whose steps will be executed implicitly by their corresponding code implementation. Thus, users can focus on writing (executable) specifications without having to do all the implementation hard-work.

Gwen also separates declarative from imperative style Gherkin specifications. Declarative is done in standard .feature files that may include steps defined in while imperative spefications

Gwen Web Automation (gwen-web) is an engine that extends Gwen and adds capabilities for easy web testing using Selenium under the hood, by providing a DSL that allows users to interact with the browser without having to write code.

From the many interesting features of Gwen is the ability of automatically taking screenshots, which will be available for analysis after tests are run.


Requirements

  • gwen
  • gwen-web
  • cucumber-json-merge
    • npm install -g cucumber-json-merge

Description

We will use the code from the Github repository "cucumber-java-skeleton", with slight changes in order to make the dummy Test pass.

The first step is to create a Cucumber Test, of Cucumber Type "Scenario", in Jira. The specification would be exactly the same as the one provided in the original repository.

After creating the Test in Jira and associating it with requirements, etc., you can export the specification of the test to a Cucumber .feature file via the REST API or the Export to Cucumber UI action from within the Test Execution issue.

The created file will be similar to the original, but will contain the references to the Test issue key and the covered requirement issue key.


new feature after export /cucumber-java-skeleton/src/test/resources/skeleton/belly.feature
 @ABC-100
 Feature: Belly

  @ABC-122
  Scenario: a few cukes
    Given I have 42 cukes in my belly
    When I wait 1 hour
    Then my belly should growl


You can change the implementation of the steps in order to make them pass quickly.


/cucumber-java-skeleton/src/test/java/skeleton/Stepdefs.java
package skeleton;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class Stepdefs {
    @Given("^I have (\\d+) cukes in my belly$")
    public void I_have_cukes_in_my_belly(int cukes) throws Throwable {
        Belly belly = new Belly();
        belly.eat(cukes);
    }
    
    
    @When("^I wait (\\d+) hour$")
    public void I_wait_hours(int hours) throws Throwable {
        Thread.sleep(hours*0);
    }
    
    @Then("^my belly should growl$")
    public boolean my_belly_should_growl() throws Throwable {
        return true;
    }
}



After running the tests and generating the Cucumber JSON  report (e.g., data.json), it can be imported to Xray via the REST API or the Import Execution Results action within the Test Execution.

./gwen -b -m meta -f json -r target/reports features
cucumber-json-merge -d target/reports/json/
curl -H "Content-Type: application/json" -X POST -u admin:admin --data @"merged-test-results.json" http://jiraserver.example.com/rest/raven/1.0/import/execution/cucumber



The execution screen details will provide information on the test run result that includes step-level information including duration.



As shown above, besides a detailed error message,  screenshots are also automatically available on failed steps.


Learn more

Please see Testing in BDD with Gherkin based frameworks (e.g. Cucumber) for an overview of the possible workflows.


Using Xray as master

...


References


  • No labels