Search in sources :

Example 21 with ITestResult

use of org.testng.ITestResult in project java.webdriver by sayems.

the class ScreenshotListener method onFinish.

/**
 * Remove failed attempts (retry analyzer).
 * <p>
 * 1. Collect all passed test. If i encounter a failed test with at least one passed test i remove the failed test (That would cover case 2 and 3 from
 * above)
 * 2. Iterate over all failed test. If i encounter a failed test which previously failed i remove the current failed result. (That would cover case 3 and 4
 * actually). That also means i will only keep the first failed result if there are several failed results.
 */
@Override
public final void onFinish(final ITestContext pTestContext) {
    super.onFinish(pTestContext);
    // List of test results which we will delete later
    final List<ITestResult> testsToBeRemoved = new ArrayList<ITestResult>();
    // collect all id's from passed test
    final Set<Integer> passedTestIds = new HashSet<Integer>();
    for (final ITestResult passedTest : pTestContext.getPassedTests().getAllResults()) {
        passedTestIds.add(getId(passedTest));
    }
    final Set<Integer> failedTestIds = new HashSet<Integer>();
    for (final ITestResult failedTest : pTestContext.getFailedTests().getAllResults()) {
        // id = class + method + dataprovider
        final int failedTestId = getId(failedTest);
        // or delete this failed test if there is at least one passed version
        if (failedTestIds.contains(failedTestId) || passedTestIds.contains(failedTestId)) {
            testsToBeRemoved.add(failedTest);
        } else {
            failedTestIds.add(failedTestId);
        }
    }
    // finally delete all tests that are marked
    for (final Iterator<ITestResult> iterator = pTestContext.getFailedTests().getAllResults().iterator(); iterator.hasNext(); ) {
        final ITestResult testResult = iterator.next();
        if (testsToBeRemoved.contains(testResult)) {
            iterator.remove();
        }
    }
    // TNG: force SKIP state for skipped tests
    for (final ITestResult r : pTestContext.getSkippedTests().getAllResults()) {
        if (r.getStatus() != ITestResult.SKIP) {
            r.setStatus(ITestResult.SKIP);
        }
    }
}
Also used : ITestResult(org.testng.ITestResult)

Example 22 with ITestResult

use of org.testng.ITestResult in project java.webdriver by sayems.

the class TestNGListener method onFinish.

@Override
public void onFinish(ITestContext context) {
    Iterator<ITestResult> listOfFailedTests = context.getFailedTests().getAllResults().iterator();
    while (listOfFailedTests.hasNext()) {
        ITestResult failedTest = listOfFailedTests.next();
        ITestNGMethod method = failedTest.getMethod();
        if (context.getFailedTests().getResults(method).size() > 1) {
            listOfFailedTests.remove();
        } else {
            if (context.getPassedTests().getResults(method).size() > 0) {
                listOfFailedTests.remove();
            }
        }
    }
}
Also used : ITestResult(org.testng.ITestResult) ITestNGMethod(org.testng.ITestNGMethod)

Example 23 with ITestResult

use of org.testng.ITestResult in project selenium_java by sergueik.

the class ShareDataTest method dataConsumingTest.

@Test
@Inject
public void dataConsumingTest() {
    ITestResult testresult = Reporter.getCurrentTestResult();
    Object data = testresult.getAttribute("element");
    if (data instanceof Element) {
        Assert.assertNotNull(((Element) data).getName(), "Data element must provide the name");
        Assert.assertTrue(((Element) data).getCount() != 0, "Data element must provide nonzero count");
    }
}
Also used : ITestResult(org.testng.ITestResult) Element(org.utils.ShareDataTest.Element) Test(org.testng.annotations.Test)

Example 24 with ITestResult

use of org.testng.ITestResult in project selenium_java by sergueik.

the class DataSupplierTests method nullObjectsDataSuppliersShouldWork.

@Test
public void nullObjectsDataSuppliersShouldWork() {
    final InvokedMethodNameListener listener = run(NullObjectsDataSupplierTests.class);
    assertThat(listener.getSkippedBeforeInvocationMethodNames()).hasSize(5).containsExactly("supplyExtractedNullObject()", "supplyNullArrayData()", "supplyNullCollectionData()", "supplyNullObjectData()", "supplyNullStreamData()");
    assertThat(EntryStream.of(listener.getResults()).values().toList()).extracting(ITestResult::getThrowable).extracting(Throwable::getMessage).containsExactly("java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullCollectionData.", "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullStreamData.", "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyExtractedNullObject.", "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullArrayData.", "java.lang.IllegalArgumentException: Nothing to return from data supplier. The following test will be skipped: NullObjectsDataSupplierTests.supplyNullObjectData.");
}
Also used : InvokedMethodNameListener(io.github.sskorol.listeners.InvokedMethodNameListener) ITestResult(org.testng.ITestResult) Test(org.testng.annotations.Test)

Aggregations

ITestResult (org.testng.ITestResult)24 ArrayList (java.util.ArrayList)5 ITestNGMethod (org.testng.ITestNGMethod)5 Test (org.testng.annotations.Test)4 InvokedMethodNameListener (io.github.sskorol.listeners.InvokedMethodNameListener)3 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 List (java.util.List)2 EntryStream (one.util.streamex.EntryStream)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ITestClass (org.testng.ITestClass)2 TestResultItem (com.qaprosoft.carina.core.foundation.report.TestResultItem)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Properties (java.util.Properties)1 IInvokedMethod (org.testng.IInvokedMethod)1 IResultMap (org.testng.IResultMap)1 ITestContext (org.testng.ITestContext)1