Sunday, March 10, 2019

Hey Santosh, I want to Automate my services and I would like to obtain a nice detailed test result report which I could share with my Boss through an email with a link to the reports, Automatically.




Well , Why don't You use Cucumber framework. it does do everything which You asked for for, its pretty simple to use and incorporate in project with hardly any learning curve.




What is cucumber framework?
Well cucumber is an integration testing framework. there are various flavor of cucumber , like for java, c etc. we will focus on using cucumber with java.
cucumber works with feature files (xyz.feature, abc123.feature) and java classes.
feature file is nothing but simple text file with (.feature) extension, it consists of  description of a test scenario in the form of GIVEN WHEN AND THEN, and the java file will consist of simple methods with annotations of @given @when @and @then corresponding to the scenarios written in the feature file.

For Example:
myfirst.feature

Scenario: Christmas holiday Given today is "25-12-2019"
When I was asked is it a holiday
Then I should say "Yes"

The Above feature file is written in simple English (Gherkin script) along with some keywords like Given When Then, cucumber framework will read this feature file and it will look for java code with in your automation maven project with methods having matching annotation and execute that method.
For Eample:
myfirst.java

@Given("^today is \"([^\"]*)\"$") public void today_is(String date) {
// here Your Custom Logic, usually initialization of test case. this.date = date;
}
@When("^I was asked is it a holiday$")
public void i_ask_whether_is_s_Friday_yet() {
this.actualAnswer = MyUtilityClass.isItaHoliday(this.date);
}
@Then("^I should say \"([^\"]*)\"$")
public void i_should_say(String expectedAnswer) {
System.out.println("EXPECTED ANSWER is :"+expectedAnswer);
assertEquals(expectedAnswer, this.actualAnswer);
}

The ABOVE 2 Steps is the foundation of using Cucumber,

  • Define Feature File
  • Create Java Class with methods and link the feature file with the methods using annotations.

How do I use cucumber to automate my REST/SOAP services?
In order to do that below are few steps to follow.
Create a simple Maven project and add cucumber dependencies so we can use cucumber features.


Hey Santosh, I want to Automate my services and I would like to obtain a nice detailed test result report which I could share with my Bos...