Skip to content

Commit

Permalink
Support for multiple matchers in Consequences
Browse files Browse the repository at this point in the history
You can now make multiple assertions against a single question
  • Loading branch information
wakaleo committed Feb 5, 2016
1 parent 3f1a76a commit c28a95e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ public void danaCanMakeAssertionsAboutWebElements() {
and(dana).should(seeThat(the(ProfilePage.NAME), isCurrentlyEnabled()));
}

@Test
public void danaCanMakeAssertionsAboutWebElementsInTheSameAssertion() {

Actor dana = new Actor("Dana");
dana.can(BrowseTheWeb.with(firstBrowser));

givenThat(dana).has(openedTheApplication);

when(dana).attemptsTo(viewHerProfile);
and(dana).attemptsTo(UpdateHerProfile.withName("Dana").andCountryOfResidence("France"));

then(dana).should(seeThat(the(ProfilePage.NAME),
isVisible(),
isCurrentlyVisible(),
isEnabled()));
}

@Test
public void multipleUsersCanUpdateTheirProfilesSimultaneously() {

Expand Down Expand Up @@ -141,6 +158,9 @@ public void shouldSeeCorrectClientDetails() {
seeThat(Client.country(), is(equalTo("France"))));

}



@Steps
OpenTheApplication openedTheApplication;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.serenitybdd.screenplay;

import com.beust.jcommander.internal.Lists;
import org.hamcrest.Matcher;

import java.util.List;

import static org.hamcrest.MatcherAssert.assertThat;

public class GivenWhenThen {
Expand All @@ -22,4 +25,13 @@ public static <T> void then(T actual, Matcher<? super T> matcher) {
public static <T> Consequence<T> seeThat(Question<? extends T> actual, Matcher<T> expected) {
return new QuestionConsequence(actual, expected);
}

public static <T> Consequence<T>[] seeThat(Question<? extends T> actual, Matcher<T>... expectedMatchers) {
List<Consequence<T>> consequences = Lists.newArrayList();
for(Matcher<T> matcher : expectedMatchers) {
consequences.add(new QuestionConsequence(actual, matcher));
}
return consequences.toArray(new Consequence[]{});
}

}

0 comments on commit c28a95e

Please sign in to comment.