Java Code Examples for org.testng.IInvokedMethod#isTestMethod()

The following examples show how to use org.testng.IInvokedMethod#isTestMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppiumParallelTestListener.java    From AppiumTestDistribution with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
    JSONObject json = new JSONObject();
    json.put("id", AppiumDeviceManager.getAppiumDevice().getDevice().getUdid());
    json.put("version", new AppiumDeviceManager().getDeviceVersion());
    json.put("platform", AppiumDeviceManager.getMobilePlatform());
    json.put("model", new AppiumDeviceManager().getDeviceModel());
    try {
        if (testResult.getStatus() == ITestResult.SUCCESS
            || testResult.getStatus() == ITestResult.FAILURE) {
            HashMap<String, String> logs = testLogger.endLogging(testResult,
                AppiumDeviceManager.getAppiumDevice().getDevice().getDeviceModel());
            if (atdHost.isPresent() && atdPort.isPresent()) {
                String postTestResults = "http://" + atdHost.get() + ":" + atdPort.get() + "/testresults";
                sendResultsToAtdService(testResult, "Completed", postTestResults, logs);
            }
        }
        if (method.isTestMethod()) {
            appiumDriverManager.stopAppiumDriver();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    SessionContext.remove(Thread.currentThread().getId());
    queueAfterInvocationListener(method, testResult, iTestNGListeners);
}
 
Example 2
Source File: GatekeeperBehaviour.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    if (!isThisSuiteListener(testResult)) {
        return;
    }
    if (method.isTestMethod()) {
        ITestNGMethod thisMethod = method.getTestMethod();
        ITestNGMethod[] allTestMethods = testResult.getTestContext().getAllTestMethods();
        ITestNGMethod firstMethod = allTestMethods[0];

        if (thisMethod.equals(firstMethod)) {
            Map<String, ISuiteResult> results = testResult.getTestContext().getSuite().getResults();
            if (hasFailedGatekeeperTest(results)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        } else {
            IResultMap skippedTests = testResult.getTestContext().getSkippedTests();
            if (anyTestsSkippedBecauseOfGatekeeper(skippedTests)) {
                throw new GatekeeperException(SKIP_MESSAGE);
            }
        }
    }
}
 
Example 3
Source File: FirstLastTestExecutionBehaviour.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
    if (!isThisSuiteListener(testResult)) {
        return;
    }
    if (method.isTestMethod()) {
        ITestNGMethod thisMethod = method.getTestMethod();
        ITestNGMethod[] allTestMethods = testResult.getTestContext().getAllTestMethods();
        ITestNGMethod firstMethod = allTestMethods[0];
        ITestNGMethod lastMethod = allTestMethods[allTestMethods.length - 1];

        if (!thisMethod.equals(firstMethod) && !thisMethod.equals(lastMethod)) {
            IResultMap success = testResult.getTestContext().getPassedTests();
            if (!success.getAllMethods().contains(firstMethod)) {
                throw new SkipException("Skipped because first method was not succcessfull");
            }
        }
    }
}
 
Example 4
Source File: InvokedMethodNameListener.java    From test-data-supplier with Apache License 2.0 5 votes vote down vote up
@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));
    }
}
 
Example 5
Source File: InvokedMethodNameListener.java    From test-data-supplier with Apache License 2.0 5 votes vote down vote up
@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());
            })
        );
    }
}
 
Example 6
Source File: QuantumReportiumListener.java    From Quantum with MIT License 5 votes vote down vote up
@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] + "]" : ""));

	}
}
 
Example 7
Source File: MockitoAfterTestNGMethod.java    From mockito-cookbook with Apache License 2.0 5 votes vote down vote up
public void applyFor(IInvokedMethod method, ITestResult testResult) {
    Mockito.validateMockitoUsage();

    if (method.isTestMethod()) {
        resetMocks(testResult.getInstance());
    }
}
 
Example 8
Source File: MockitoAfterTestNGMethod.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void applyFor(IInvokedMethod method, ITestResult testResult) {
    Mockito.validateMockitoUsage();

    if (method.isTestMethod()) {
        resetMocks(testResult.getInstance());
    }
}
 
Example 9
Source File: AtsTestngListener.java    From ats-framework with Apache License 2.0 2 votes vote down vote up
@Override
public void beforeInvocation( IInvokedMethod method, ITestResult testResult, ITestContext context ) {

    if (!ActiveDbAppender.isAttached) {
        return;
    }

    if (method.isConfigurationMethod()) { // check if method is @BeforeXXX or @AfterXXX

        if (method.getTestMethod().isBeforeClassConfiguration()) { // check if method is @BeforeClass

            if (currentSuiteName == null) {

                // start suite
                startSuite(testResult);

            } else if (!currentSuiteName.equals(testResult.getTestClass()
                                                          .getRealClass()
                                                          .getSimpleName())) {

                endSuite(); // end previously started suite
                startSuite(testResult); // start new suite

            }

        } else if (method.getTestMethod().isBeforeMethodConfiguration()) { // check if method is @BeforeMethod

            if (currentSuiteName == null) {

                // start suite
                startSuite(testResult);

            } else if (!currentSuiteName.equals(testResult.getTestClass()
                                                          .getRealClass()
                                                          .getSimpleName())) {

                endSuite(); // end previously started suite
                startSuite(testResult); // start new suite

            }

            if (currentTestcaseName == null) {

                // start testcase
                startTestcase(testResult);

            }

            logger.info("[TESTNG]: Start @BeforeMethod '" + testResult.getTestClass().getRealClass()
                        + "@" + method.getTestMethod().getMethodName() + "'");

        } else if (method.getTestMethod().isAfterMethodConfiguration()) { // check if method is @AfterMethod

            logger.startAfterMethod();

            logger.info("[TESTNG]: Start @AfterMethod '" + testResult.getTestClass().getRealClass() + "@"
                        + method.getTestMethod().getMethodName() + "'");

        } else if (method.getTestMethod().isAfterClassConfiguration()) { // check if method is @AfterClass

            if (currentSuiteName == null) {

                logger.startAfterClass();
            }

        } else if (method.getTestMethod().isAfterSuiteConfiguration()) { // check if method is @AfterSuite

            logger.startAfterSuite();
        }

    } else if (method.isTestMethod()) { // check if method is not @BeforeXXX or @AfterXXX

        if (method.getTestMethod().isTest()) { // check if method is @Test

            if (currentSuiteName == null) {

                // start suite
                startSuite(testResult);

            } else if (!currentSuiteName.equals(testResult.getTestClass()
                                                          .getRealClass()
                                                          .getSimpleName())) {

                endSuite(); // end previously started suite
                startSuite(testResult); // start new suite

            }

            if (currentTestcaseName == null) {

                // start testcase
                startTestcase(testResult);
            } else {

                // update testcase
                updateTestcase(testResult);
            }
        }
    }
}