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);
}
}
}
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();
}
}
}
}
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");
}
}
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.");
}
Aggregations