0

I have a mock up profile page of a gym and I'm to write test cases for editing that profile page in gherkin language. I don't the gherkin test case format. Can anyone please help me with this?

  • 1
    Without meaning to come across as "RTFM", have you read the [documentation's overview of the syntax](https://github.com/cucumber/cucumber/wiki/Gherkin)? If so, what specific questions do you have about it? – Richard Szalay Mar 11 '17 at 08:37
  • Thanks for your valuable time and answer @RichardSzalay. I really appreciate it. I had already read the documentation's overview of the syntax and I wanted to know real-time examples that users (in Stack Overflow) are working on. – Satish Amaravati Apr 25 '17 at 06:53

2 Answers2

0

There is no hard and fast rule to write the gherkin tests. But it is highly advisable that you write them by following recommended procedures, to make it understandable. The main purpose of gherkin is for someone apart from your team, understand the whole testing process.

There are three primary, conditions that you will have to satisfy writing gherkin.

Start your tests with the pre-defined statements i.e Given Then and When. Your feature file should have steps that should look like these:

Given I land on homepage
When I click on the signup button
Then I see the error

There are also other keywords like:

And - Connect more than two steps

Please refer to this documentation for more details:

https://github.com/cucumber/cucumber/wiki/Given-When-Then

Emjey
  • 2,038
  • 3
  • 18
  • 33
0

In my opinion, this question has no scope; however, I'll try to answer. Gherkin is a language with no technical barriers; it enforces an entire team to write unambiguous requirement-based test specifications based on creative collaboration rather technical specifics. The base components of Gherkin have been explained in the first answer. So, I'd rather try to give a working example as requested in the question to understand the use of Given, When, Then clearly.

The following test (called test specification) is written in Gherkin in the feature file:

Feature: Google Book Searching from https://www.googleapis.com/books/v1/volumes?q={ID}

  Scenario Outline: Verify that the response status code is 200 and content type is JSON.
    Given webService endpoint is up
    When user sends a get request to webService endpoint using following details
      | ID | <ID> |
    Then verify <statusCode> and <contentType> from webService endpoint response
    Examples:
      | ID   | statusCode | contentType                       |
      | 1    | 200        | "application/json; charset=UTF-8" |
      | 9546 | 200        | "application/json; charset=UTF-8" |
      | 9    | 200        | "application/json; charset=UTF-8" |

Now here is the step definition for the above test specification:

// for **Given** - as it has to ensure that the required webservice end-point is up:

   @Given("webService endpoint is up")
    public void webserviceEndpointIsUp() {
        requestSpecification = new RequestSpecBuilder().
                setBaseUri(prop.getProperty(BASE_URL)).
                build();
    }

// for **When** - as this is for the part when user sends the request to the webservice end-point and receives the response

@When("user sends a get request to webService endpoint using following details")
public void userSendsAGetRequestToWebServiceEndpointUsingID(Map<String, String> data) {
    String ID = data.get("ID");
    System.out.println("The current ID is: " + ID);
    String pathParameters = "?q" + "=" + ID;
    response = given().
            spec(requestSpecification).
            when().
            get(pathParameters);
}

// for **Then** - finally, here is the then part. When we're verifying the actual stuff mentioned in the Scenario

 @Then("verify {int} and {string} from webService endpoint response")
    public void verifyResponseStatusCodeAndContentTypeFromWebServiceEndpointResponse(int statusCode, String contentType) {
        Assert.assertEquals(statusCode, response.getStatusCode());
        Assert.assertEquals(contentType, response.getContentType());
    }

This is just one example that how tests are written in Gherkin, there is a lot more to learn to be able to write such scripts. So, I'll recommend to start off with the following links:

  1. Writing Good Gherkin

  2. Cucumeber-JVM Free Course

Iqra.
  • 685
  • 1
  • 7
  • 18