Skip to content

Instantly share code, notes, and snippets.

@williamboxhall
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save williamboxhall/f4bd17ade309b3d90432 to your computer and use it in GitHub Desktop.
Save williamboxhall/f4bd17ade309b3d90432 to your computer and use it in GitHub Desktop.
BDD End-to-End Scenario example
package org.example.feature;
...
public class BDDContrivedScenario extends Scenario {
private Mail mail;
@Given("I have sent a mail to two people with response required")
public void givenIHaveSentAMailToTwoPeopleWithResponseRequired() {
as(ME).on(HOTEL_VIP).onThe(NEW_MAIL_PAGE).createAndSend(responseRequiredMailTo(COLLEAGUE, AFFILIATE));
}
@When("they both reply to the mail")
public void whenTheyBothReplyToTheMail() {
as(COLLEAGUE).on(HOTEL_VIP).onThe(MAIL_SEARCH_PAGE).findAndOpen(mail).reply().createAndSend(tokenReply());
as(AFFILIATE).on(HOTEL_VIP).onThe(MAIL_SEARCH_PAGE).findAndOpen(mail);
onThe(VIEW_MAIL_PAGE).reply().createAndSend(tokenReply());
}
@When("one replies to the mail")
public void whenOneRepliesToTheMail() {
as(COLLEAGUE).on(HOTEL_VIP).onThe(MAIL_SEARCH_PAGE).findAndOpen(mail).reply().createAndSend(tokenReply());
}
@When("I view the original mail")
public void whenIViewTheOriginalMail() {
as(ME).onThe(MAIL_SEARCH_PAGE).sent().findAndOpen(mail);
}
@Then("the status of the mail is $status")
public void thenTheStatusOfTheMailIs(@Named("status") String status) {
assertThat(onThe(VIEW_MAIL_PAGE).status(), is(status));
}
private Mail responseRequiredMailTo(LoginCredentials... recipients) {
Date today = new Date();
String todayAsString = DateFormatUtils.format(today "yyyy-MM-dd_HH-mm-ss");
mail = new Mail().to(recipients).responseRequiredMessage("Respond by")
.responseRequiredDate(today).mailType("Request For Information")
.mailSubject("BDDContrivedScenario-" + todayAsString);
return mail;
}
private Mail tokenReply() {
return new Mail().mailType("Request For Information");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment