/** * Create a new instance of a class containing test steps. * This method will instrument the class appropriately and inject any nested step libraries or * other dependencies. */ public <T> T instantiateNewStepLibraryFor(Class<T> scenarioStepsClass) { StepInterceptor stepInterceptor = new StepInterceptor(scenarioStepsClass); stepInterceptor.setThowsExceptionImmediately(throwExceptionImmediately); return instantiateNewStepLibraryFor(scenarioStepsClass, stepInterceptor); }
private boolean shouldSkip(final Method methodOrStep) { if (aPreviousStepHasFailed() && !isSoftAssert()) { return true; } return testIsPending() || isDryRun() || isPending(methodOrStep) || isIgnored(methodOrStep); }
private Object skipStepMethod(final Object obj, Method method, final Object[] args, final MethodProxy proxy) throws Exception { if ((aPreviousStepHasFailed() || testAssumptionViolated()) && (!shouldExecuteNestedStepsAfterFailures())) { notifySkippedStepStarted(obj, method, args); notifySkippedStepFinishedFor(method, args); return appropriateReturnObject(obj, method); } else { notifySkippedStepStarted(obj, method, args); return skipTestStep(obj, method, args, proxy); } }
public Object intercept(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { Object result; if (baseClassMethod(method, obj)) { result = runBaseObjectMethod(obj, method, args, proxy); } else { result = testStepResult(obj, method, args, proxy); } return result; }
private Object executeTestStepMethod(Object obj, Method method, Object[] args, MethodProxy proxy, Object result) throws Throwable { try { result = invokeMethod(obj, args, proxy); notifyStepFinishedFor(method, args); } catch (PendingStepException pendingStep) { notifyStepPending(pendingStep.getMessage()); } catch (IgnoredStepException ignoredStep) { notifyStepIgnored(ignoredStep.getMessage()); } catch (AssumptionViolatedException assumptionViolated) { notifyAssumptionViolated(assumptionViolated.getMessage()); } Preconditions.checkArgument(true); return result; }
private Object skipTestStep(Object obj, Method method, Object[] args, MethodProxy proxy) throws Exception { Object skippedReturnObject = runSkippedMethod(obj, method, args, proxy); notifyStepSkippedFor(method, args); LOGGER.info("SKIPPED STEP: {}", method.getName()); return appropriateReturnObject(skippedReturnObject, obj, method); }
private boolean shouldRunInDryRunMode(final Method methodOrStep, final Class callingClass) { return ((aPreviousStepHasFailed() || testIsPending() || isDryRun()) && declaredInSameDomain(methodOrStep, callingClass)); }
private Object runTestStep(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { String callingClass = testContext(); LOGGER.info("STARTING STEP: {} - {}", callingClass, method.getName()); Object result = null; try { result = executeTestStepMethod(obj, method, args, proxy, result); LOGGER.info("STEP DONE: {}", method.getName()); } catch (AssertionError failedAssertion) { error = failedAssertion; logStepFailure(method, args, failedAssertion); result = appropriateReturnObject(obj, method); } catch (AssumptionViolatedException assumptionFailed) { result = appropriateReturnObject(obj, method); } catch (Throwable testErrorException) { error = SerenityWebDriverException.detachedCopyOf(testErrorException); logStepFailure(method, args, forError(error).convertToAssertion()); result = appropriateReturnObject(obj, method); } return result; }
private Object invokeMethodAndNotifyFailures(Object obj, Method method, Object[] args, MethodProxy proxy, Object result) throws Throwable { try { result = invokeMethod(obj, args, proxy); } catch (Throwable generalException) { error = generalException; Throwable assertionError = forError(error).convertToAssertion(); notifyStepStarted(method, args); notifyOfStepFailure(method, args, assertionError); } return result; }
private boolean shouldSkipMethod(final Method methodOrStep, final Class callingClass) { return ((aPreviousStepHasFailed() || testIsPending()) && declaredInSameDomain(methodOrStep, callingClass)); }
private Object runTestStep(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { LOGGER.info("STARTING STEP: {}", method.getName()); Object result = null; try { result = executeTestStepMethod(obj, method, args, proxy, result); LOGGER.info("STEP DONE: {}", method.getName()); } catch (AssertionError failedAssertion) { error = failedAssertion; logStepFailure(method, args, failedAssertion); return appropriateReturnObject(obj, method); } catch (AssumptionViolatedException assumptionFailed) { return appropriateReturnObject(obj, method); } catch (Throwable testErrorException) { error = testErrorException; logStepFailure(method, args, forError(error).convertToAssertion()); return appropriateReturnObject(obj, method); } return result; }
private boolean declaredInSameDomain(Method method, final Class callingClass) { return domainPackageOf(getRoot(method)).equals(domainPackageOf(callingClass)); }
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(); result = runIfNestedMethodsShouldBeRun(obj, method, args, proxy); StepEventBus.getEventBus().reenableWebdriverCalls(); return result; }
private void notifyOfStepFailure(final Method method, final Object[] args, final Throwable cause) throws Throwable { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args)); StepFailure failure = new StepFailure(description, cause); StepEventBus.getEventBus().stepFailed(failure); if (shouldThrowExceptionImmediately()) { throw cause; } }
private void notifyOfStepFailure(final Object object, final Method method, final Object[] args, final Throwable cause) throws Throwable { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args), args) .withDisplayedFields(fieldValuesIn(object)); StepFailure failure = new StepFailure(description, cause); StepEventBus.getEventBus().stepFailed(failure); if (shouldThrowExceptionImmediately()) { throw cause; } }
private String getTestNameFrom(final Method method, final Object[] args) { return getTestNameFrom(method, args, true); }
private Object runBaseObjectMethod(final Object obj, final Method method, final Object[] args, final MethodProxy proxy) throws Throwable { return invokeMethod(obj, args, proxy); }
/** * Create a new instance of a class containing test steps. * This method will instrument the class appropriately and inject any nested step libraries or * other dependencies. */ public <T> T instantiateNewStepLibraryFor(Class<T> scenarioStepsClass) { StepInterceptor stepInterceptor = new StepInterceptor(scenarioStepsClass); return instantiateNewStepLibraryFor(scenarioStepsClass, stepInterceptor); }
private void notifyStepStarted(final Object object, final Method method, final Object[] args) { ExecutedStepDescription description = ExecutedStepDescription.of(testStepClass, getTestNameFrom(method, args), args) .withDisplayedFields(fieldValuesIn(object)); StepEventBus.getEventBus().stepStarted(description); }
private Object runIfNestedMethodsShouldBeRun(Object obj, Method method, Object[] args, MethodProxy proxy) { Object result = null; try { if (shouldRunNestedMethodsIn(method)) { result = invokeMethod(obj, args, proxy); } } catch (Throwable anyException) { LOGGER.trace("Ignoring exception thrown during a skipped test", anyException); } return result; }