public void beforeInvocation(IInvokedMethod method, ITestResult tr, ITestContext context) { QAFTestBase stb = TestBaseProvider.instance().get(); stb.getLog().clear(); stb.clearVerificationErrors(); stb.getCheckPointResults().clear(); logger.debug("beforeInvocation: " + method.getTestMethod().getMethodName()); tr.setAttribute("context", context); ConfigurationManager.getBundle().setProperty(ApplicationProperties.CURRENT_TEST_CONTEXT.key, context); ConfigurationManager.getBundle().setProperty(ApplicationProperties.CURRENT_TEST_NAME.key, tr.getName()); ConfigurationManager.getBundle().setProperty(ApplicationProperties.CURRENT_TEST_DESCRIPTION.key, tr.getMethod().getDescription()); ConfigurationManager.getBundle().setProperty(ApplicationProperties.CURRENT_TEST_RESULT.key, tr); }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult, final ITestContext context) { final ITestNGMethod testMethod = method.getTestMethod(); if (isSupportedConfigurationFixture(testMethod)) { final String executableUuid = currentExecutable.get(); currentExecutable.remove(); if (testResult.isSuccess()) { getLifecycle().updateFixture(executableUuid, result -> result.withStatus(Status.PASSED)); } else { getLifecycle().updateFixture(executableUuid, result -> result .withStatus(getStatus(testResult.getThrowable())) .withStatusDetails(getStatusDetails(testResult.getThrowable()).orElse(null))); } getLifecycle().stopFixture(executableUuid); if (testMethod.isBeforeMethodConfiguration() || testMethod.isAfterMethodConfiguration()) { final String containerUuid = currentTestContainer.get(); validateContainerExists(getQualifiedName(testMethod), containerUuid); currentTestContainer.remove(); getLifecycle().stopTestContainer(containerUuid); getLifecycle().writeTestContainer(containerUuid); } } }
/** * [ITestListener] * Invoked each time a test is skipped. * * @param result {@code ITestResult} containing information about the run test * @see ITestResult#SKIP */ @Override public void onTestSkipped(ITestResult result) { // >>>>> ENTER workaround for TestNG bug // https://github.com/cbeust/testng/issues/1602 ITestContext context = result.getTestContext(); IInvokedMethod method = new InvokedMethod( result.getTestClass(), result.getMethod(), System.currentTimeMillis(), result); beforeInvocation(method, result, context); // <<<<< LEAVE workaround for TestNG bug synchronized (testListeners) { for (ITestListener testListener : testListeners) { testListener.onTestSkipped(result); } } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (testResult.getInstance() instanceof IInvokedMethodListenerEx) { ((IInvokedMethodListenerEx) testResult.getInstance()).afterInvocation(method, testResult); } if (method.getTestMethod().isBeforeMethodConfiguration()) { // merge with attributes from prior methods Map<String, Object> attributes = fromBefore.get(); attributes.putAll(PropertyManager.extractAttributes(testResult)); fromBefore.set(attributes); } else if (method.isTestMethod()) { fromMethod.set(PropertyManager.extractAttributes(testResult)); } else if (method.getTestMethod().isAfterMethodConfiguration()) { // nothing to do here } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeMethodConfiguration()) { // nothing to do here } else if (method.isTestMethod()) { PropertyManager.injectAttributes(fromBefore.get(), testResult); fromBefore.remove(); } else if (method.getTestMethod().isAfterMethodConfiguration()) { PropertyManager.injectAttributes(fromMethod.get(), testResult); fromMethod.remove(); } if (testResult.getInstance() instanceof IInvokedMethodListenerEx) { ((IInvokedMethodListenerEx) testResult.getInstance()).beforeInvocation(method, testResult); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { Object testInstance = method.getTestMethod().getInstance(); if (runningTests.containsValue(testInstance)) { return; } long currentThreadId = Thread.currentThread().getId(); if (isNewTestInProgress(testInstance)) { preDestroy(runningTests.remove(currentThreadId)); } String testName = testInstance.getClass().getName(); try { LOG.info("Dependencies injection in {}", testName); injectDependencies(testResult.getTestContext(), testInstance); } catch (Exception e) { String errorMessage = "Failed to inject fields in " + testName; LOG.error(errorMessage, e); throw new TestException(errorMessage, e); } finally { runningTests.put(currentThreadId, testInstance); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { try { SkipIf skip = method.getTestMethod() .getConstructorOrMethod() .getMethod().getAnnotation(SkipIf.class); if (skip != null) { String info = skip.platform(); if (AppiumDriverManager.getDriver().getPlatformName().contains(info)) { System.out.println("skipping childTest"); throw new SkipException("Skipped because property was set to :::" + info); } } } catch (Exception e) { e.printStackTrace(); } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeClassConfiguration() | method.getTestMethod().isBeforeGroupsConfiguration() | method.getTestMethod().isBeforeMethodConfiguration() | method.getTestMethod().isBeforeSuiteConfiguration() | method.getTestMethod().isBeforeTestConfiguration()) { afterSetup(method, testResult); } else if (method.getTestMethod().isAfterClassConfiguration() | method.getTestMethod().isAfterGroupsConfiguration() | method.getTestMethod().isAfterMethodConfiguration() | method.getTestMethod().isAfterSuiteConfiguration() | method.getTestMethod().isAfterTestConfiguration()) { afterTeardown(method, testResult); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeClassConfiguration() | method.getTestMethod().isBeforeGroupsConfiguration() | method.getTestMethod().isBeforeMethodConfiguration() | method.getTestMethod().isBeforeSuiteConfiguration() | method.getTestMethod().isBeforeTestConfiguration()) { beforeSetup(method, testResult); } else if (method.getTestMethod().isAfterClassConfiguration() | method.getTestMethod().isAfterGroupsConfiguration() | method.getTestMethod().isAfterMethodConfiguration() | method.getTestMethod().isAfterSuiteConfiguration() | method.getTestMethod().isAfterTestConfiguration()) { beforeTeardown(method, testResult); } }
/** * After invocation. * * @param method * the method * @param result * the result * @see org.testng.IInvokedMethodListener#afterInvocation(org.testng.IInvokedMethod, * org.testng.ITestResult) */ @Override public final void afterInvocation(final IInvokedMethod method, final ITestResult result) { if (method.isTestMethod()) { if (result.getStatus() == ITestResult.SKIP) { endTestReporting("skipped"); } else if (result.getStatus() == ITestResult.FAILURE) { endTestReporting("failed"); } else if (result.getStatus() == ITestResult.SUCCESS) { endTestReporting("passed"); } } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { if ( method.isTestMethod() ) { RetryContext retryContext = (RetryContext)context.getAttribute(ATTRIBUTE_NAME); if ( retryContext == null ) { log.error("No retryContext!"); } else { if ( testResult.isSuccess() || (testResult.getStatus() == ITestResult.FAILURE) ) { retryContext.isRetrying.set(false); if ( retryContext.runVersion.incrementAndGet() > 1 ) { context.setAttribute(ATTRIBUTE_NAME, null); } } } } }
@Override public void beforeInvocation(IInvokedMethod m, ITestResult res) { if (m.isTestMethod()) { File videoFile = new File( res.getTestContext().getOutputDirectory(), m.getTestMethod().getMethodName() + ".flv"); screencaster = new VideoCreator(videoFile); videoThread = new Thread(new Runnable() { @Override public void run() { screencaster.createVideoFromScreens(); } }); videoThread.start(); } }
@Override public void afterInvocation(IInvokedMethod m, ITestResult res) { if (m.isTestMethod() && screencaster != null) { try { Thread.sleep(2000); screencaster.setPleaseStop(true); while (! screencaster.isStoppedCreation()) { Thread.sleep(500); } videoThread.join(); } catch (InterruptedException e) { e.printStackTrace(); } screencaster = null; videoThread = null; } }
@Override public boolean apply(IInvokedMethod method) { if (!method.isTestMethod()) { return false; } Test testAnnotation = method.getTestMethod().getConstructorOrMethod().getMethod().getAnnotation(Test.class); if (null == testAnnotation) { return false; } if (testAnnotation.expectedExceptions().length == 0) { return false; } return Arrays.asList(testAnnotation.expectedExceptions()).contains(SoftAssertException.class); }
@Override public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { if (iInvokedMethod.isTestMethod()) { Reporter.setCurrentTestResult(iTestResult); removeAttributes(iTestResult); Method testMethod = iInvokedMethod.getTestMethod().getConstructorOrMethod().getMethod(); if (testMethod.isAnnotationPresent(Test.class)) { String message = "Test "; message += testMethod.getName() + " started."; ReporterNG.logBusiness(message); ReporterNG.setAttribute(TestBase.ATTRIBUTES.ATTRIBUTE_NAME.toString(), "_" + id++); } ReporterNG.LOG.info("Processing Test " + iInvokedMethod.toString()); } TestBase.setPassed(); }
@Override public void afterInvocation(IInvokedMethod method, ITestResult result) { Throwable throwable = result.getThrowable(); if (throwable != null) { TestBase.setFailed(throwable.getMessage()); } super.afterInvocation(method, result); if (method.isTestMethod()) { if (!TestBase.getPassed()) { logBusinessScreenshot("Error Occurred!"); } else { if (TestBaseWebDriver.takePassedScreenshot) { logBusinessScreenshot("Test Passed"); } } } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { int failed = findFailed(context); if (failed > 0) { LOG.error("Masking will not proceed. {} Configurations have failed",failed); return; } Method rmethod = method.getTestMethod().getConstructorOrMethod().getMethod(); if (rmethod.getAnnotation(Test.class) != null || rmethod.getAnnotation(BeforeClass.class) != null || rmethod.getAnnotation(BeforeTest.class) != null) { if (rmethod.getAnnotation(RunsWithController.class) != null || rmethod.getDeclaringClass().getAnnotation(RunsWithController.class) != null) { LOG.warn("Method or Class of {} asks Controller to be masked", rmethod.getName()); AnnotationsHelper p = SteviaContext.getSpringContext().getBean(AnnotationsHelper.class); try { p.maskExistingController(rmethod); masked = true; } catch (Throwable e) { throw new IllegalStateException("failed to replace controller",e); } } } }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult, final ITestContext context) { final String testName = getTestName(testResult); final Boolean isTestFailed = (Boolean) context.getAttribute(format("%s postpone fail", testName)); final Boolean isBeforeGroupFailed = (Boolean) context.getAttribute(format("%s postpone fail", "E4BeforeGroups")); if ((isTestFailed != null && isTestFailed) || (isBeforeGroupFailed != null && isBeforeGroupFailed)) { testResult.setStatus(FAILURE); testResult.setThrowable(new PostponedFailureException(getErrorMessage(testName))); } }
@Override @CheckReturnValue public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod()) { final String fileName = String.format("http://localhost:4444/video/%s.mp4", testResult.getAttribute("sessionId")); attachUri("Video", fileName); } }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod() && testResult.getStatus() == SUCCESS) { try { getSoftAssert().assertAll(); } catch (AssertionError e) { testResult.getTestContext().getPassedTests().removeResult(testResult.getMethod()); testResult.setStatus(TestResult.FAILURE); testResult.setThrowable(e); } THREAD_LOCAL_CONTAINER_FOR_SOFT_ASSERTIONS.remove(); } }
/** * Perform post-invocation processing: * <ul> * <li>If indicated, close the driver that was acquired for this method.</li> * </ul> * * @param invokedMethod an object representing the method that's just been invoked * @param testResult test result object for the method that's just been invoked */ @Override public void afterInvocation(IInvokedMethod invokedMethod, ITestResult testResult) { // ensure current test result is set Reporter.setCurrentTestResult(testResult); Object obj = testResult.getInstance(); Method method = invokedMethod.getTestMethod().getConstructorOrMethod().getMethod(); DriverManager.afterInvocation(obj, method); }
public void onFinish(ISuite suite) { if (!skipMode) { for (IInvokedMethod testNGMethod : suite.getAllInvokedMethods()) { updateTestCaseInTargetProcess(testNGMethod.getTestResult()); } } }
@Override public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult, final ITestContext context) { final ITestNGMethod testMethod = method.getTestMethod(); if (isSupportedConfigurationFixture(testMethod)) { ifSuiteFixtureStarted(context.getSuite(), testMethod); ifTestFixtureStarted(context, testMethod); ifClassFixtureStarted(testMethod); ifMethodFixtureStarted(testMethod); } }
/** Arranges methods by classname and method name */ @Override public int compare(IInvokedMethod o1, IInvokedMethod o2) { // System.out.println("Comparing " + o1.getMethodName() + " " + // o1.getDate() // + " and " + o2.getMethodName() + " " + o2.getDate()); return (int) (o1.getDate() - o2.getDate()); // int r = ((T) o1).getTestClass().getName().compareTo(((T) // o2).getTestClass().getName()); // if (r == 0) { // r = ((T) o1).getMethodName().compareTo(((T) o2).getMethodName()); // } // return r; }
/** * Get All tests id by class + method + parameters hash code. * * @param context * @param suite */ private void getAllTestIds(ITestContext context, ISuite suite) { IResultMap passTests = context.getPassedTests(); IResultMap failTests = context.getFailedTests(); List<IInvokedMethod> invokedMethods = suite.getAllInvokedMethods(); for (IInvokedMethod im : invokedMethods) { if (passTests.getAllMethods().contains(im.getTestMethod()) || failTests.getAllMethods().contains(im.getTestMethod())) { int testId = getId(im.getTestResult()); // m_out.println("ALLtestid=" + testId); allRunTestIds.add(testId); } } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeMethodConfiguration()) { beforeMethodBefore = true; } else if (method.isTestMethod()) { testMethodBefore = true; } else if (method.getTestMethod().isAfterMethodConfiguration()) { afterMethodBefore = true; } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeMethodConfiguration()) { beforeMethodAfter = true; } else if (method.isTestMethod()) { testMethodAfter = true; } else if (method.getTestMethod().isAfterMethodConfiguration()) { afterMethodAfter = true; } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeMethodConfiguration()) { beforeMethodBefore.add(testResult.getName()); } else if (method.isTestMethod()) { testMethodBefore.add(testResult.getName()); } else if (method.getTestMethod().isAfterMethodConfiguration()) { afterMethodBefore.add(testResult.getName()); } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (method.getTestMethod().isBeforeMethodConfiguration()) { beforeMethodAfter.add(testResult.getName()); } else if (method.isTestMethod()) { testMethodAfter.add(testResult.getName()); } else if (method.getTestMethod().isAfterMethodConfiguration()) { afterMethodAfter.add(testResult.getName()); } }
@Override public void beforeInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { if(iInvokedMethod.isTestMethod() && ReflectionUtils.shouldBeInvoked(iInvokedMethod.getTestMethod().getRealClass(), MethodInGroupsListener.class)){ Stream.of(getAllMethods(iInvokedMethod.getTestMethod().getRealClass(), new Method[]{})) .filter(method -> method.isAnnotationPresent(BeforeMethodInGroups.class)) .filter(method -> intersects(iInvokedMethod.getTestMethod().getGroups(), method.getAnnotation(BeforeMethodInGroups.class).groups())) .sorted(Comparator.comparingInt(method -> method.getAnnotation(BeforeMethodInGroups.class).priority())) .forEach(method -> { method.setAccessible(true); ReflectionUtils.invokeMethod(method, iTestResult.getInstance()); }); } }
@Override public void afterInvocation(IInvokedMethod iInvokedMethod, ITestResult iTestResult) { if(iInvokedMethod.isTestMethod() && ReflectionUtils.shouldBeInvoked(iInvokedMethod.getTestMethod().getRealClass(), MethodInGroupsListener.class)){ Stream.of(getAllMethods(iInvokedMethod.getTestMethod().getRealClass(), new Method[]{})) .filter(method -> method.isAnnotationPresent(AfterMethodInGroups.class)) .filter(method -> intersects(iInvokedMethod.getTestMethod().getGroups(), method.getAnnotation(AfterMethodInGroups.class).groups())) .sorted(Comparator.comparingInt(method -> method.getAnnotation(AfterMethodInGroups.class).priority())) .forEach(method -> { method.setAccessible(true); ReflectionUtils.invokeMethod(method, iTestResult.getInstance()); }); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if(shouldBeInvoked(testResult.getInstance().getClass(), FastFailListener.class) && failedClasses.containsKey(testResult.getInstance())) throw new SkipException(String.format("Skipped because of the failed test '%s'", failedClasses.get(testResult.getInstance()).getTestMethod().getMethodName())); }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod()) { addByteAttachmentAsync("Test log", "text/plain", "afterInvocationContent"::getBytes); if (!testResult.isSuccess()) { addStreamAttachmentAsync("Failure screenshot", "image/png", () -> getSystemResourceAsStream("attachments/screenshot.png")); } } }
protected static void logInvocation(final TestStatus testStatus, final IInvokedMethod method) { ITestNGMethod iTestNGMethod = method.getTestMethod(); String methodName = iTestNGMethod.getTestClass().getName() + '#' + iTestNGMethod.getMethodName(); String methodType = "test"; if (method.isConfigurationMethod()) { methodType = "configuration"; } LOGGER.info("{} {} {} method: {}", (testStatus == TestStatus.ERRORED_OUT ? "!!!" : "==="), testStatus, methodType, methodName); }
@Override public void beforeInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod()) { final String rawMethodName = method.getTestMethod().getMethodName(); final long currentThreadId = Thread.currentThread().getId(); threads.putIfAbsent(rawMethodName, new CopyOnWriteArrayList<>()); threads.computeIfPresent(rawMethodName, (s, l) -> StreamEx.of(l).append(currentThreadId).distinct().toList()); invokedMethodNames.add(getName(testResult)); } }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult testResult) { if (method.isTestMethod()) { final String name = getName(testResult); Match(testResult.getStatus()).of( Case($(FAILURE), () -> failedMethodNames.add(name)), Case($(SKIP), () -> skippedMethodNames.add(name)), Case($(SUCCESS), () -> succeedMethodNames.add(name)), Case($(), () -> { throw new AssertionError("Unexpected value: " + testResult.getStatus()); }) ); } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult) { if (method.isTestMethod()) { System.out.println("-----------------------------------------------"); System.out.println("Test: " + testResult.getMethod().getMethodName()); System.out.println("Duration [ms]: " + (testResult.getEndMillis() - testResult.getStartMillis())); System.out.println("Exit status: " + (testResult.getStatus() - 1)); System.out.println("-----------------------------------------------"); } }
@Override public void beforeInvocation(IInvokedMethod method, ITestResult testResult) { if (method.isTestMethod()) { // Before execution of test method ConsoleUtils.surroundWithSquare("TEST STARTED: " + getTestName(testResult) + (testResult.getParameters().length > 0 ? " [" + testResult.getParameters()[0] + "]" : "")); } }
public void afterInvocation(final IInvokedMethod method, final ITestResult tr, final ITestContext context) { logger.debug("afterInvocation: " + method.getTestMethod().getMethodName() + " - " + method.getTestMethod().getConstructorOrMethod() .getDeclaringClass().getPackage().getName() + " is test:" + method.isTestMethod()); // if (method.isTestMethod()) { processResult(tr, context); // } logger.debug("afterInvocation: Done"); }
@Override public void afterInvocation(final IInvokedMethod method, final ITestResult tr, final ITestContext context) { super.afterInvocation(method, tr, context); // pro if (method.isTestMethod() && !shouldRetry(tr)) { deployResult(tr, context); } }