Skip to content

A Basic Workflow

james-goddard-magentys edited this page Jul 25, 2017 · 11 revisions

Below is the most basic workflow for automating a BDD scenario. This is already achieved as an example upon generating a template project. Here you see just how easy Cinnamon is to use.

BDD Scenario

 @google
Feature: Google Search
    
 @sanity
Scenario: Valid search returns results
   When I search for "Cinnamon"
   Then I should see results

Step Definition

public class GoogleStepDef{

    private final GooglePage googlePage;
    
    @Inject
    public GoogleStepDef(final GooglePage googlePage){
        this.googlePage = googlePage;
    }

    @When("^I search for (*.?)
    public void i_search_for(String searchTerm){
        googlePage.enterSearchTerm(searchTerm).clickSearchButton();
    }
}

Page Object (read more)

public class GooglePage{

    @FindBy(id = searchInputId)
    public PageElement searchInput;
    @FindBy(id = searchButtonId)
    public PageElement searchButton;

    public GooglePage enterSearchTerm(String searchTerm){
        searchInput.waitUntil(displayed).typeText(searchTerm);
        return this;
    }

    public GooglePage clickSearchButton(){
        searchButton.click();
        return this;
    }
} 

Hooks

public void Hooks{

    private final GooglePage googlePage;

    @Inject
    public Hooks(final GooglePage googlePage) {
        this.googlePage = googlePage;
    }

    @Before("@google")
    public void openWebSite() throws Throwable {
        open(Env.env().config.getString("base-url"));  //Opens the browser and navigates to the URL defined in env.conf
        assertThat("Cannot open the google", googlePage.searchInput.isDisplayed(), equalTo(true));
    }

env.conf (read more)

default : {
  base-url : "http://www.google.com"
}

staging: {
  base-url : "http://googles-staging-site.com"
}

another-env: {
  base-url : "http://another-env-url.com"
}

Running the tests

mvn clean install -DbrowserProfile=chrome -Denv=another-env -Dcucumber.options="--tags @sanity"

Simple huh? Why not try it out for yourself? Start by generating a template project