/** * Created by nickebbutt on 20/03/2018. * * An execution listener which can be added to pause execution after each failed scenario to give the * user a chance to inspect state * * This listener has a priority which will ensure it is called before system execution listeners run clean up * (e.g. before closing Selenium web drivers and web sockets to shut down browsers..) */ @ExecutionPriority(200) public class PromptOnScenarioFailExecutionListener extends PromptOnScenarioEndExecutionListener { protected boolean shouldPrompt(ScenarioToken scenarioToken) { return scenarioToken.getEndState() == EndState.FAILED; } }
private void addListener(ExecutionListener l) { if ( ! containsListener(l)) { ExecutionPriority p = l.getClass().getAnnotation(ExecutionPriority.class); int priority = p == null ? ExecutionPriority.DEFAULT_USER_LISTENER_PRIORITY : p.value(); PrioritisedListener prioritisedListener = new PrioritisedListener(priority, l); listeners.add(prioritisedListener); } }
/** * Load and remove properties at the appropriate points in the chorus lifecyle */ @ExecutionPriority(ExecutionPriority.PROPERTY_SUBSYSTEM_PRIORITY) private class PropertySubsystemExecutionListener extends ExecutionListenerAdapter { public void testsStarted(ExecutionToken testExecutionToken, List<FeatureToken> features) { currentProfile = testExecutionToken.getProfile(); loadSessionProperties(); } @Override public void featureStarted(ExecutionToken testExecutionToken, FeatureToken feature) { currentFeature = feature; loadFeatureProperties(feature); } @Override public void featureCompleted(ExecutionToken testExecutionToken, FeatureToken feature) { clearFeatureProperties(); } }
@ExecutionPriority(ExecutionPriority.PROCESS_MANAGER_PRIORITY) private class ProcessManagerExecutionListener extends ExecutionListenerAdapter { public void featureStarted(ExecutionToken testExecutionToken, FeatureToken feature) { ProcessManagerImpl.this.featureToken = feature; } /** * @param testExecutionToken a token representing the current suite of tests running * @param scenario a token representing the scenario which has just completed */ @Override public void scenarioCompleted(ExecutionToken testExecutionToken, ScenarioToken scenario) { stopProcesses(Scope.SCENARIO); } /** * @param testExecutionToken a token representing the current suite of tests running * @param feature a token representing the feature which has just completed */ @Override public void featureCompleted(ExecutionToken testExecutionToken, FeatureToken feature) { stopProcesses(Scope.FEATURE); } }}
@ExecutionPriority(ExecutionPriority.REMOTING_MANAGER_PRIORITY) private class RemotingManagerExecutionListener extends ExecutionListenerAdapter { public void featureCompleted(ExecutionToken testExecutionToken, FeatureToken feature) { try { closeAllConnections(); } catch (Throwable t) { log.error("Failed during destroyFeature jmx remoting manager", t); } } public void scenarioCompleted(ExecutionToken testExecutionToken, ScenarioToken scenario) { try { disposeForScope(Scope.SCENARIO); } catch (Throwable t) { log.error("Failed during destroyScenario() jmx remoting manager", t); } } private void disposeForScope(Scope scope) { for ( RemotingManagerConfig c : new ArrayList<>(remotingConfigs)) { if ( c.getScope() == scope) { closeConnection(c); } } } } }
@ExecutionPriority(200) public class PromptOnScenarioEndExecutionListener extends ExecutionListenerAdapter {
@ExecutionPriority(ExecutionPriority.JUNIT_SUITE_LISTENER_PRIORITY) private class JUnitSuiteExecutionListener extends ExecutionListenerAdapter {
@ExecutionPriority(ExecutionPriority.INTERPRETER_OUTPUT_PRIORITY) public class InterpreterOutputExecutionListener extends AbstractChorusOutputWriterDecorator implements ExecutionListener {
@ExecutionPriority(300) class PriorityThreeHundred extends ExecutionTrackingExecutionListener {}
@ExecutionPriority(200) class PriorityTwoHundred extends ExecutionTrackingExecutionListener {}
@ExecutionPriority(100) class PriorityOneHundred extends ExecutionTrackingExecutionListener {}
@ExecutionPriority(2000) //set the priority high to generate the properties file before anything else runs! public class PropertyWritingExecutionListener extends ExecutionListenerAdapter {