@Override public boolean isTakingAction(Event event, TestResult result) { if (event instanceof After) { if (configuration.getTakeAfterTest()) { return true; } if (result.getStatus() == Status.FAILED && configuration.getTakeWhenTestFailed()) { return true; } } return false; }
public void afterTest(@Observes After event) { TestResult result = testResult.get(); if (strategy.get().isTakingAction(event, result)) { ScreenshotType screenshotType = getScreenshotType(); ScreenshotMetaData metaData = getMetaData(event); metaData.setTestResult(result); beforeScreenshotTaken.fire(new BeforeScreenshotTaken(screenshotType, metaData)); takeScreenshot.fire( new TakeScreenshot( screenshotType, metaData, result.getStatus() == TestResult.Status.FAILED ? When.FAILED : When.AFTER)); afterScreenshotTaken.fire(new AfterScreenshotTaken(screenshotType, metaData)); } }
public void on( @Observes AfterTestLifecycleEvent event, TestResult testResult, GovernorRegistry governorRegistry, JiraGovernorConfiguration jiraGovernorConfiguration, JiraGovernorClient jiraGovernorClient) { int count = 0; try { Integer c = lifecycleCountRegister.get(event.getTestMethod()); count = (c != null ? c.intValue() : 0); if (count == 0) { // skip first event - see // https://github.com/arquillian/arquillian-governor/pull/16#issuecomment-166590210 return; } final ExecutionDecision decision = TestMethodExecutionRegister.resolve(event.getTestMethod(), provides()); // if we passed some test method annotated with Jira, we may eventually close it if (jiraGovernorConfiguration.getClosePassed()) { // we decided we run this test method even it has annotation on it if (testResult.getStatus() == Status.PASSED && decision.getDecision() == Decision.EXECUTE && (JiraGovernorStrategy.FORCING_EXECUTION_REASON_STRING) .equals(decision.getReason())) { for (Map.Entry<Method, List<Annotation>> entry : governorRegistry.get().entrySet()) { if (entry.getKey().toString().equals(event.getTestMethod().toString())) { for (Annotation annotation : entry.getValue()) { if (annotation.annotationType() == provides()) { String id = ((Jira) annotation).value(); jiraGovernorClient.close(id); return; } } } } } } } finally { lifecycleCountRegister.put(event.getTestMethod(), ++count); } }