2018-11-24

serenity cucumber selenium automation

BDD fundamentals

Behaviour-Driven Development (BDD) is a collaborative approach to software development that bridges the communication gap between business and IT. BDD helps teams communicate requirements with more precision, discover defects early and produce software that remains maintainable over time.

Writing acceptance criteria with Cucumber-JVM

In Cucumber, you express acceptance criteria in a natural, human-readable form.
For example, you want to write acceptance criteria for sending a mail
you could write like this:

Given I want to send a mail
When I login to to mail box. clicked compose button, entered the details and clicked send
Then I should see mail sent to the receiver.

Sometimes tables can be used to summarize several different examples of the same scenario.

Scenario Outline: sending a mail
    Given I have login to the mail box
    When I can enter the details '<Email>' and '<Subject>'
    Then I should see mail sent successfully
  Examples:
    | Email    | Subject  |
    | x@x.com  | test     |
    | x@y.com  | test     |
    | x@z.com  | test     |

These feature files can be placed in different locations, but you can reduce the amount of configuration you need to do with Serenity if you put them in the src/test/resources/features directory.

|----src
| |----test
| | |----resources
| | | |----features
| | | | |----mail
| | | | | |----sending_mail.feature

The Scenario Runner

package net.serenity_bdd.samples.etsy.features;

import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="src/test/resources/features")
public class AcceptanceTests {}

Step definitions

public class SendingMail {
    @Steps
    BuyerSteps buyer;

    @Given("I have login to the mail box")
    public void buyerWantsToBuy(String article) {
        buyer.opens_etsy_home_page();
    }

    @When("I can enter the details '(.*)' and '(.*)'")
    public void searchByKeyword(String keyword) {
        buyer.searches_for_items_containing(keyword);
    }

    @Then("I should see mail sent successfully")    public void resultsForACategoryAndKeywordInARegion(String keyword) {
        buyer.should_see_items_related_to(keyword);
    }
}



No comments:

Post a Comment