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?
What is the test case format in gherkin language?
2.4k views Asked by Satish Amaravati At
2
There are 2 answers
0
On
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:
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
GivenThenandWhen. Your feature file should have steps that should look like these:There are also other keywords like:
Please refer to this documentation for more details:
https://github.com/cucumber/cucumber/wiki/Given-When-Then