@Test public void should_record_nested_pending_steps() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); steps.step1(); steps.step9(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-step1\n" + "---> STEP DONE\n" + "-step9\n" + "--step1\n" + "----> STEP DONE\n" + "--pendingStep\n" + "----> STEP PENDING\n" + "--step4\n" + "---step5\n" + "-----> STEP DONE\n" + "---step6\n" + "-----> STEP DONE\n" + "----> STEP DONE\n" + "---> STEP DONE\n" + "TEST DONE\n"; System.out.println(consoleStepListener.toString()); assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void shouldIndicateWhenATestIsRunningHasNotStarted() { StepEventBus.getEventBus().dropAllListeners(); assertThat(StepEventBus.getEventBus().areStepsRunning(), is(false)); }
private void notifyStepSkippedFor(final Method method, final Object[] args) throws Exception { if (isPending(method)) { StepEventBus.getEventBus().stepPending(); } else { StepEventBus.getEventBus().stepIgnored(); } }
@Test public void when_an_entier_test_is_ignored_the_test_is_marked_as_ignored() { StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().testIgnored(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "--> TEST IGNORED\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
private boolean aPreviousStepHasFailed() { boolean aPreviousStepHasFailed = false; if (StepEventBus.getEventBus().aStepInTheCurrentTestHasFailed() && !StepEventBus.getEventBus().isCurrentTestDataDriven()) { aPreviousStepHasFailed = true; } return aPreviousStepHasFailed; }
@Test public void a_step_can_be_marked_pending() { StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); StepEventBus.getEventBus().stepPending(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-a step\n" + "---> STEP PENDING\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void shouldIndicateWhenATestIsRunning() { StepEventBus.getEventBus().dropAllListeners(); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); assertThat(StepEventBus.getEventBus().areStepsRunning(), is(true)); }
@Test public void the_step_event_bus_can_be_used_to_sent_notification_events_about_steps() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testSuiteStarted(SampleTestScenario.class); StepEventBus.getEventBus().testStarted("some_test"); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); verify(listener).stepStarted(any(ExecutedStepDescription.class)); }
@Test public void should_record_when_a_test_starts_and_finishes() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); steps.step1(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-step1\n" + "---> STEP DONE\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void should_clear_all_listeners_when_requested() { StepEventBus.getEventBus().dropAllListeners(); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().stepStarted(ExecutedStepDescription.withTitle("a step")); StepEventBus.getEventBus().stepPending(); StepEventBus.getEventBus().testFinished(testOutcome); assertThat(consoleStepListener.toString(), is("")); }
@Before public void initMocks() { MockitoAnnotations.initMocks(this); factory = new StepFactory(new Pages(driver)); consoleStepListener = new ConsoleStepListener(); StepEventBus.getEventBus().clear(); StepEventBus.getEventBus().registerListener(listener); StepEventBus.getEventBus().registerListener(consoleStepListener); }
@Test public void should_notify_listeners_when_the_test_suite_finishes() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testSuiteStarted(SampleTestScenario.class); StepEventBus.getEventBus().testStarted("some_test", SampleTestScenario.class); steps.step1(); StepEventBus.getEventBus().testFinished(testOutcome); StepEventBus.getEventBus().testSuiteFinished(); verify(listener).testSuiteFinished(); }
private Object runSkippedMethod(Object obj, Method method, Object[] args, MethodProxy proxy) { LOGGER.trace("Running test step " + getTestNameFrom(method, args, false)); Object result = null; StepEventBus.getEventBus().temporarilySuspendWebdriverCalls(); try { result = invokeMethod(obj, method, args, proxy); } catch (Throwable anyException) { LOGGER.trace("Ignoring exception thrown during a skipped test", anyException); } StepEventBus.getEventBus().reenableWebdriverCalls(); return result; }
@Test public void should_execute_steps_transparently() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("some_test", SampleTestScenario.class); steps.step1(); steps.step2(); steps.step3(); StepEventBus.getEventBus().testFinished(testOutcome); verify(driver).get("step_one"); verify(driver).get("step_two"); verify(driver).get("step_three"); }
@Test public void should_notify_listeners_when_a_step_starts() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("some_test", SampleTestScenario.class); steps.step1(); StepEventBus.getEventBus().testFinished(testOutcome); ArgumentCaptor<ExecutedStepDescription> argument = ArgumentCaptor.forClass(ExecutedStepDescription.class); verify(listener).stepStarted(argument.capture()); assertThat(argument.getValue().getName(), is("step1")); }
private static void initStepListener() { Configuration configuration = Injectors.getInjector().getInstance(Configuration.class); File outputDirectory = configuration.getOutputDirectory(); StepListener listener = new BaseStepListener(outputDirectory, getPages()); stepListenerThreadLocal.set(listener); StepEventBus.getEventBus().registerListener(getStepListener()); }
@Test public void a_step_can_return_a_step_object_if_a_failure_occurs() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); steps.stepThatFailsAndReturnsAStep().stepThatReturnsAStep(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-stepThatFailsAndReturnsAStep\n" + "---> STEP FAILED\n" + "-stepThatReturnsAStep\n" + "---> STEP IGNORED\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
private void notifyOfStepFailure(final Method method, final Object[] args, final Throwable cause) throws Exception { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args)); StepFailure failure = new StepFailure(description, cause); StepEventBus.getEventBus().stepFailed(failure); }
@Test public void should_record_groups_as_nested_test_steps() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); steps.nested_steps(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-nested_steps\n" + "--step1\n" + "----> STEP DONE\n" + "--nested_steps1\n" + "---step1\n" + "-----> STEP DONE\n" + "---nested_steps2\n" + "----step1\n" + "------> STEP DONE\n" + "----step4\n" + "-----step5\n" + "-------> STEP DONE\n" + "-----step6\n" + "-------> STEP DONE\n" + "------> STEP DONE\n" + "-----> STEP DONE\n" + "---step4\n" + "----step5\n" + "------> STEP DONE\n" + "----step6\n" + "------> STEP DONE\n" + "-----> STEP DONE\n" + "----> STEP DONE\n" + "--step4\n" + "---step5\n" + "-----> STEP DONE\n" + "---step6\n" + "-----> STEP DONE\n" + "----> STEP DONE\n" + "---> STEP DONE\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void when_an_entier_test_is_pending_all_the_contained_steps_are_skipped() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); StepEventBus.getEventBus().testPending(); steps.step1(); steps.step2(); steps.step3(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-step1\n" + "---> STEP IGNORED\n" + "-step2\n" + "---> STEP IGNORED\n" + "-step3\n" + "---> STEP IGNORED\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
@Test public void should_not_use_the_browser() { SimpleTestScenarioSteps steps = factory.getStepLibraryFor(SimpleTestScenarioSteps.class); StepEventBus.getEventBus().testStarted("a_test", SampleTestScenario.class); steps.step1(); steps.step7(); StepEventBus.getEventBus().testFinished(testOutcome); String expectedSteps = "TEST a_test\n" + "-step1\n" + "---> STEP DONE\n" + "-step7\n" + "--step1\n" + "----> STEP DONE\n" + "--failingStep\n" + "----> STEP FAILED\n" + "--step2\n" + "----> STEP IGNORED\n" + "---> STEP DONE\n" + "TEST DONE\n"; assertThat(consoleStepListener.toString(), is(expectedSteps)); }
private boolean testIsPending() { return StepEventBus.getEventBus().currentTestIsPending(); }
private void notifyStepFinishedFor(final Method method, final Object[] args) { StepEventBus.getEventBus().stepFinished(); }
private void notifyStepPending(String message) { StepEventBus.getEventBus().stepPending(message); }
private void notifyStepIgnored(String message) { StepEventBus.getEventBus().stepIgnored(); }
private void notifyOfTestFailure(final Method method, final Object[] args, final Throwable cause) throws Exception { StepEventBus.getEventBus().testFailed(cause); }
private void notifySkippedStepStarted(final Method method, final Object[] args) { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args)); StepEventBus.getEventBus().skippedStepStarted(description); }
@After public void clearListener() { StepEventBus.getEventBus().dropListener(consoleStepListener); StepEventBus.getEventBus().dropListener(listener); }
public static void takeScreenshot() { StepEventBus.getEventBus().takeScreenshot(); }