/** * A tense-neutral synonyme for has() for use with given() clauses */ public final void wasAbleTo(Performable... todos) { attemptsTo(todos); }
public final void can(Consequence... consequences) { should(consequences); }
public static Actor named(String name) { return new Actor(name); }
public final void should(Consequence... consequences) { beginPerformance(); for (Consequence consequence : consequences) { check(consequence); } endPerformance(); }
public final void attemptsTo(Performable... tasks) { beginPerformance(); for (Performable task : tasks) { perform(task); } endPerformance(); }
public <ANSWER> void remember(String key, Question<ANSWER> question) { beginPerformance(); ANSWER answer = this.asksFor(question); notepad.put(key, answer); endPerformance(); }
@Test public void should_be_able_to_acquire_token_and_then_acquire_silent() { //clear cache givenThat(james).wasAbleTo(clearCache, clickDone, readCache); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(0))); givenThat(james).wasAbleTo( clickDone, acquireToken, clickDone, readCache); int expectedCacheCountToken = james.asksFor(ExpectedCacheItemCount.displayed()); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedCacheCountToken))); when(james).attemptsTo( clickDone, acquireTokenSilent, clickDone, readCache ); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedCacheCountToken))); }
then(james).should(seeThat(TokenCacheItemCount.displayed(), is(0))); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedCacheCountToken))); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedFinalCacheCountCount))); clickDone); andThat(james).wasAbleTo( expireATAndInvalidateRT .withTokenCacheItem(cacheItem) clickDone); when(james).attemptsTo( acquireTokenSilent.withUniqueId(cacheItem.uniqueUserId), WaitUntil.the(Results.RESULT_FIELD, isVisible()).forNoMoreThan(10).seconds()); then(james).should(seeThat(ADALError.displayed(), is(com.microsoft.identity.common.adal.error.ADALError.AUTH_REFRESH_FAILED_PROMPT_NOT_ALLOWED.name()))); when(james).attemptsTo(clickDone, readCache); then(james).should(seeThat(TokenCacheItemCount.displayed(), is((expectedCacheCountToken == 20) ? 12 : 8)));
private <T extends Performable> void perform(T todo) { if (isPending(todo)) { StepEventBus.getEventBus().stepPending(); } try { notifyPerformanceOf(todo); taskTally.newTask(); performTask(todo); if (anOutOfStepErrorOccurred()) { eventBusInterface.mergePreviousStep(); } } catch (Throwable exception) { if (!pendingOrIgnore(exception)) { eventBusInterface.reportStepFailureFor(todo, exception); } if (Serenity.shouldThrowErrorsImmediately() || isAnAssumptionFailure(exception)) { throw exception; } } finally { eventBusInterface.updateOverallResult(); } }
public final void attemptsTo(Performable... tasks) { beginPerformance(); for (Performable task : tasks) { if (isNestedInSilentTask()) { performSilently(task); } else if (isSilent(task)) { performSilently(task); } else if (isHidden(task) || shouldNotReport(task)) { performWithoutReporting(task); } else { perform(InstrumentedTask.of(task)); } } endPerformance(); }
public final void should(String groupStepName, Consequence... consequences) { try { String groupTitle = injectActorInto(groupStepName); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle(groupTitle)); should(consequences); } catch (Throwable error) { throw error; } finally { StepEventBus.getEventBus().stepFinished(); } }
then(james).should(seeThat(TokenCacheItemCount.displayed(), is(0))); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedCacheCountToken))); then(james).should(seeThat(TokenCacheItemCount.displayed(), is(expectedFinalCacheCountCount))); clickDone); andThat(james).wasAbleTo( acquireTokenSilent .withUniqueId(result.uniqueUserId) readCache); then(james).should(seeThat(AccessToken.displayed(Constants.OUTLOOK_CLIENT_ID), not(accessToken1)));
public <ANSWER> ANSWER asksFor(Question<ANSWER> question) { beginPerformance(); ANSWER answer = question.answeredBy(this); endPerformance(); return answer; }
public final void should(Consequence... consequences) { //if (StepEventBus.getEventBus().isDryRun()) { return; } ErrorTally errorTally = new ErrorTally(eventBusInterface); startConsequenceCheck(); for (Consequence consequence : consequences) { check(consequence, errorTally); } endConsequenceCheck(); errorTally.reportAnyErrors(); }
public Actor actorNamed(String actorName, Ability... abilities) { if (! actors.containsKey(actorName)) { Actor newActor = Actor.named(actorName); for(Ability doSomething : abilities) { newActor.can(doSomething); } assignGeneralAbilitiesTo(newActor); actors.put(actorName, newActor); } return actors.get(actorName); }
/** * A more readable way to access an actor's abilities. */ public <T extends Ability> T usingAbilityTo(Class<? extends T> doSomething) { return abilityTo(doSomething); }
public <T extends Ability> Actor whoCan(T doSomething) { return can(doSomething); }
public <ANSWER> void remember(String key, Question<ANSWER> question) { ANSWER answer = this.asksFor(question); notepad.put(key, answer); }