Java Code Examples for org.testng.ITestContext

The following are top voted examples for showing how to use org.testng.ITestContext. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sunshine   File: TestNGStatus.java   View source code 7 votes vote down vote up
private void calculate() {
    if (!this.counts.isEmpty()) return;
    int passed = 0;
    int failed = 0;
    int skipped = 0;

    for (ISuite suite : this.reports) {
        for (ISuiteResult result : suite.getResults().values()) {
            final ITestContext testContext = result.getTestContext();
            passed += testContext.getPassedTests().size();
            failed += testContext.getFailedTests().size();
            skipped += testContext.getSkippedTests().size();
        }
    }
    this.counts.add(0, passed + failed + skipped);
    this.counts.add(1, failed);
    this.counts.add(2, skipped);
}
 
Example 2
Project: DolphinNG   File: EmailableReporter.java   View source code 7 votes vote down vote up
/**
 * Creates a section showing known results for each method
 */
protected void generateMethodDetailReport(List<ISuite> suites)
{
    m_methodIndex = 0;
    for (ISuite suite : suites)
    {
        Map<String, ISuiteResult> r = suite.getResults();
        for (ISuiteResult r2 : r.values())
        {
            ITestContext testContext = r2.getTestContext();
            if (r.values().size() > 0)
            {
                m_out.println("<h1>" + testContext.getName() + "</h1>");
            }
            resultDetail(testContext.getFailedConfigurations(), "failed");
            resultDetail(testContext.getFailedTests(), "failed");
            resultDetail(testContext.getSkippedConfigurations(), "skipped");
            resultDetail(testContext.getSkippedTests(), "skipped");
            resultDetail(testContext.getPassedTests(), "passed");
        }
    }
}
 
Example 3
Project: teasy   File: MethodsInvoker.java   View source code 6 votes vote down vote up
protected TestClassContext(Class testClass, AbstractTest testInstance, Class<? extends Annotation> annotationClassToInvokeMethods, ITestContext testContext) {
    this.testClass = testClass;
    this.testInstance = testInstance;
    this.annotationClassToInvokeMethods = annotationClassToInvokeMethods;
    if (testContext.getExcludedGroups() == null) {
        this.excludedGroups = new String[0];
    } else {
        this.excludedGroups = Arrays.copyOf(testContext.getExcludedGroups(), testContext.getExcludedGroups().length);
    }
    if (testContext.getIncludedGroups() == null) {
        this.includedGroups = new String[0];
    } else {
        this.includedGroups = Arrays.copyOf(testContext.getIncludedGroups(), testContext.getIncludedGroups().length);
    }
    this.testContext = testContext;
}
 
Example 4
Project: allure-java   File: AllureTestNg.java   View source code 6 votes vote down vote up
@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);
        }
    }
}
 
Example 5
Project: TestNG-Foundation   File: ListenerChain.java   View source code 6 votes vote down vote up
/**
 * [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);
        }
    }
}
 
Example 6
Project: datarouter   File: ModuleFactory.java   View source code 6 votes vote down vote up
@Override
public Module createModule(ITestContext context, Class<?> testClass){

	Module globalModule = new AbstractModule(){

		@Override
		protected void configure(){
			for(Module module : modules){
				install(module);
			}
		}

	};
	Iterable<? extends Module> overriders = getOverriders();
	return Modules.override(globalModule).with(overriders);
}
 
Example 7
Project: Equella   File: AbstractRestAssuredTest.java   View source code 6 votes vote down vote up
@AfterSuite
public void cleanupAfterSuite(ITestContext context)
{
	if( suite != null )
	{
		@SuppressWarnings("unchecked")
		List<CleanupAfter> cleanups = (List<CleanupAfter>) suite.getAttribute("cleanups");
		if( cleanups != null )
		{
			ListIterator<CleanupAfter> listIterator = cleanups.listIterator(cleanups.size());
			while( listIterator.hasPrevious() )
			{
				CleanupAfter cleanup = listIterator.previous();
				if( cleanup != null )
				{
					cleanup.cleanUp();
				}
			}
		}
	}
}
 
Example 8
Project: Equella   File: AbstractTest.java   View source code 6 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setupContext(ITestContext testContext)
{
	this.suite = testContext.getSuite();
	File rootFolder = testConfig.getTestFolder();
	String contextUrl;

	if( isInstitutional() )
	{
		contextUrl = testConfig.getInstitutionUrlFromShortName(rootFolder.getName());
	}
	else
	{
		contextUrl = testConfig.getAdminUrl();
	}

	context = new PageContext(testConfig, contextUrl);
	context.setIntegUrl(testConfig.getIntegrationUrl(rootFolder.getName()));
	context.setNamePrefix(getNamePrefix());
	customisePageContext();
}
 
Example 9
Project: oldmonk   File: ReporterAPI.java   View source code 6 votes vote down vote up
public Map<String, String> getAllParametersForTest(String testName)
{
    ITestContext overview = null;

    for (ISuite suite : suites)
    {
        Map<String, ISuiteResult> tests = suite.getResults();

        for (ISuiteResult r : tests.values())
        {
            overview = r.getTestContext();

            if (testName.equalsIgnoreCase(overview.getName()))
            {
                return overview.getCurrentXmlTest().getAllParameters();
            }
        }
    }

    return null;
}
 
Example 10
Project: oldmonk   File: ReporterAPI.java   View source code 6 votes vote down vote up
public ITestNGMethod[] getAllMethodsForTest(String testName)
{
    ITestContext overview = null;

    for (ISuite suite : suites)
    {
        suiteName = suite.getName();

        Map<String, ISuiteResult> tests = suite.getResults();

        for (ISuiteResult r : tests.values())
        {
            overview = r.getTestContext();

            if (overview.getName().equalsIgnoreCase(testName))
            {
                return overview.getAllTestMethods();
            }
        }
    }

    return null;
}
 
Example 11
Project: openjdk-jdk10   File: TestReorderInterceptor.java   View source code 6 votes vote down vote up
@Override
public List<IMethodInstance> intercept(final List<IMethodInstance> methods, final ITestContext context) {
    Collections.sort(methods, new Comparator<IMethodInstance>() {
        @Override
        public int compare(final IMethodInstance mi1, final IMethodInstance mi2) {
            // get test instances to order the tests.
            final Object o1 = mi1.getInstance();
            final Object o2 = mi2.getInstance();
            if (o1 instanceof ITest && o2 instanceof ITest) {
                return ((ITest)o1).getTestName().compareTo(((ITest)o2).getTestName());
            }
            // something else, don't care about the order
            return 0;
        }
    });

    return methods;
}
 
Example 12
Project: DolphinNG   File: ProgressReporter.java   View source code 6 votes vote down vote up
public void onFinish(ITestContext context)
{
    System.err.println("TEST finished : " + context.getName());
    testsCompleted.add(context.getName());
    testsInProgress.remove(context.getName());

    totalActualTimeTaken = context.getEndDate().getTime() - context.getStartDate().getTime();
    long timeSaved = timeTakenByTestMethods - totalActualTimeTaken;
    customMessage.replace(0, customMessage.length(), "");
    if (timeTakenByTestMethods < 1)
    {
        timeTakenByTestMethods = 1;
    }
    customMessage.append("<span> " + "Sum of time taken for each test method : " + timeTakenByTestMethods / 1000 + " seconds!" + "</span><br/>" +
            "<span> " + "Actual total time taken for run : " + totalActualTimeTaken / 1000 + " seconds!" + "</span><br/>" +
            "<span>" + "Time saved : " + timeSaved / 1000 + " seconds OR " + timeSaved * 100 / timeTakenByTestMethods + "%</span>");
    update();
    lastUpdate = false;
}
 
Example 13
Project: Reer   File: TestNGTestClassProcessor.java   View source code 5 votes vote down vote up
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    ISuite suite = context.getSuite();
    List<IMethodInstance> filtered = new LinkedList<IMethodInstance>();
    for (IMethodInstance candidate : methods) {
        if (matcher.matchesTest(candidate.getMethod().getTestClass().getName(), candidate.getMethod().getMethodName())
            || matcher.matchesTest(suite.getName(), null)) {
            filtered.add(candidate);
        }
    }
    return filtered;
}
 
Example 14
Project: teasy   File: AbstractSeleniumTest.java   View source code 5 votes vote down vote up
@BeforeSuite(alwaysRun = true)
public void beforeSuite(final ITestContext context) {
    if (methodsInvoker == null) {
        new SeleniumMethodsInvoker().invokeSuiteMethodsByAnnotation(OurBeforeSuite.class, context);
    } else {
        methodsInvoker.invokeSuiteMethodsByAnnotation(OurBeforeSuite.class, context);
    }
}
 
Example 15
Project: teasy   File: AbstractSeleniumTest.java   View source code 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
public void beforeMethod(final Method test, final Object[] params, final ITestContext context) {
    testName = TestUtils.getTestName(test);
    postponeFailureEvent.subscribe(new ScreenshotOnPostponeFailureSubscriber(testName));
    postponeFailureEvent.subscribe(new StorePostponeFailureSubscriber(context, testName));
    passCounter = 0;
}
 
Example 16
Project: teasy   File: AbstractSeleniumTest.java   View source code 5 votes vote down vote up
@AfterSuite(alwaysRun = true)
public void afterSuite(final ITestContext context) {
    if (methodsInvoker == null) {
        new SeleniumMethodsInvoker().invokeSuiteMethodsByAnnotation(OurAfterSuite.class, context);
    } else {
        methodsInvoker.invokeSuiteMethodsByAnnotation(OurAfterSuite.class, context);
    }
}
 
Example 17
Project: heat   File: CustomTestNgListener.java   View source code 5 votes vote down vote up
@Override
public void onStart(ITestContext testContext) {
    String testName = testContext.getCurrentXmlTest().getName();
    MDC.put("testName", testName);
    List<ITestResult> localSkippedTests = new ArrayList<>();
    testContext.setAttribute("skippedTestCases", localSkippedTests);
}
 
Example 18
Project: teasy   File: AbstractWebServiceTest.java   View source code 5 votes vote down vote up
@AfterSuite(alwaysRun = true)
public void afterSuite(final ITestContext context) {
    if (methodsInvoker == null) {
        new WebServiceMethodsInvoker().invokeSuiteMethodsByAnnotation(OurAfterSuite.class, context);
    } else {
        methodsInvoker.invokeSuiteMethodsByAnnotation(OurAfterSuite.class, context);
    }
}
 
Example 19
Project: teasy   File: AbstractWebServiceTest.java   View source code 5 votes vote down vote up
@BeforeGroups
public void doBeforeGroups(final ITestContext context) {
    if (methodsInvoker == null) {
        new WebServiceMethodsInvoker().invokeGroupMethodsByAnnotation(OurBeforeGroups.class, context);
    } else {
        methodsInvoker.invokeGroupMethodsByAnnotation(OurBeforeGroups.class, context);
    }
}
 
Example 20
Project: teasy   File: AbstractWebServiceTest.java   View source code 5 votes vote down vote up
@AfterGroups
public void doAfterGroups(final ITestContext context) {
    if (methodsInvoker == null) {
        new WebServiceMethodsInvoker().invokeGroupMethodsByAnnotation(OurAfterGroups.class, context);
    } else {
        methodsInvoker.invokeGroupMethodsByAnnotation(OurAfterGroups.class, context);
    }
    ParamsHolder.clearForGroup();
}
 
Example 21
Project: heat   File: TestBaseRunner.java   View source code 5 votes vote down vote up
/**
 * Method that takes test suites parameters and sets some environment properties.
 * @param propFilePath path of the property file data
 * @param inputWebappName name of the service to test (optional parameter)
 * @param context testNG context
 */
@BeforeSuite
@Override
@Parameters(value = {ENV_PROP_FILE_PATH, WEBAPP_NAME})
public void beforeTestSuite(String propFilePath,
                            @Optional(NO_INPUT_WEBAPP_NAME) String inputWebappName,
                            ITestContext context) {
    TestSuiteHandler testSuiteHandler = TestSuiteHandler.getInstance();
    testSuiteHandler.setPropertyFilePath(propFilePath);
    testSuiteHandler.populateEnvironmentHandler();
    testSuiteHandler.populateTestCaseUtils();

}
 
Example 22
Project: teasy   File: WebServiceMethodsInvoker.java   View source code 5 votes vote down vote up
public <T extends Annotation> void invokeGroupMethodsByAnnotation(final Class<T> annotationClass, final ITestContext testContext) {
    final TestClassContext testClassContext = new TestClassContext(((TestRunner) testContext).getTest()
            .getXmlClasses()
            .get(0)
            .getSupportClass(), null, annotationClass, testContext);
    invokeMethodsByAnnotation(testClassContext, true);
}
 
Example 23
Project: selenium-testng-template   File: HtmlReporter.java   View source code 5 votes vote down vote up
private String buildReport(ITestContext test) {
	try {
		InputStream is = HtmlReporter.class.getResourceAsStream(REPORT_TEMPLATE);
		Configuration cfg = new Configuration(Configuration.getVersion());
		Template template = new Template("Report", new InputStreamReader(is), cfg);
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("context", test);
		StringWriter writer = new StringWriter();
		template.process(parameters, writer);
		return writer.toString();
	} catch (Exception e) {
		log.error("Build Report error", e);
		return "Exception: " + e.getMessage();
	}
}
 
Example 24
Project: heat   File: SingleMode.java   View source code 5 votes vote down vote up
/**
 * Method that takes test suites parameters and sets some environment properties.
 * @param propFilePath path of the property file data
 * @param inputWebappName name of the service to test (optional parameter)
 * @param context testNG context
 */
@BeforeSuite
@Override
@Parameters(value = {ENV_PROP_FILE_PATH, WEBAPP_NAME})
public void beforeTestSuite(String propFilePath,
                            @Optional(NO_INPUT_WEBAPP_NAME) String inputWebappName,
                            ITestContext context) {
    super.beforeTestSuite(propFilePath, inputWebappName, context);
    TestSuiteHandler.getInstance().setWebappName(inputWebappName);
}
 
Example 25
Project: teasy   File: ProcessPostponedFailureListener.java   View source code 5 votes vote down vote up
@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)));
    }
}
 
Example 26
Project: allure-java   File: AllureTestNg.java   View source code 5 votes vote down vote up
@Override
public void onStart(final ITestContext context) {
    final String parentUuid = getUniqueUuid(context.getSuite());
    final String uuid = getUniqueUuid(context);
    final TestResultContainer container = new TestResultContainer()
            .withUuid(uuid)
            .withName(context.getName())
            .withStart(System.currentTimeMillis());
    getLifecycle().startTestContainer(parentUuid, container);

    Stream.of(context.getAllTestMethods())
            .map(ITestNGMethod::getTestClass)
            .distinct()
            .forEach(this::onBeforeClass);
}
 
Example 27
Project: allure-java   File: AllureTestNg.java   View source code 5 votes vote down vote up
@Override
public void onFinish(final ITestContext context) {
    final String uuid = getUniqueUuid(context);
    getLifecycle().stopTestContainer(uuid);
    getLifecycle().writeTestContainer(uuid);

    Stream.of(context.getAllTestMethods())
            .map(ITestNGMethod::getTestClass)
            .distinct()
            .forEach(this::onAfterClass);
}
 
Example 28
Project: allure-java   File: AllureTestNg.java   View source code 5 votes vote down vote up
@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);
    }
}
 
Example 29
Project: test-data-supplier   File: DataSupplierMetaData.java   View source code 5 votes vote down vote up
public DataSupplierMetaData(final ITestContext context, final ITestNGMethod testMethod) {
    this.context = context;
    this.testMethod = testMethod;
    this.dataSupplierMethod = findDataSupplier();

    val dataSupplier = ofNullable(dataSupplierMethod.getDeclaredAnnotation(DataSupplier.class));
    this.transpose = dataSupplier.map(DataSupplier::transpose).orElse(false);
    this.flatMap = dataSupplier.map(DataSupplier::flatMap).orElse(false);
    this.indices = dataSupplier.map(DataSupplier::indices).orElse(new int[0]);
    this.testData = transform();
}
 
Example 30
Project: WebAndAppUITesting   File: PowerEmailableReporter.java   View source code 5 votes vote down vote up
/** Creates a section showing known results for each method */
protected void generateMethodDetailReport(List<ISuite> suites) {
	for (ISuite suite : suites) {
		Map<String, ISuiteResult> r = suite.getResults();
		for (ISuiteResult r2 : r.values()) {
			ITestContext testContext = r2.getTestContext();
			if (r.values().size() > 0) {
				m_out.println("<h1>" + testContext.getName() + "</h1>");
			}
			resultDetail(testContext.getFailedConfigurations());
			resultDetail(testContext.getFailedTests());
			resultDetail(testContext.getSkippedConfigurations());
			resultDetail(testContext.getSkippedTests());
			resultDetail(testContext.getPassedTests());
		}
	}
}
 
Example 31
Project: WebAndAppUITesting   File: PowerEmailableReporter.java   View source code 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 32
Project: heat   File: CustomTestNgListener.java   View source code 5 votes vote down vote up
/**
 * This method is invoked at the end of each test suite. Is useful to create console output logs, in terms of summary of the output
 * of the test suite just executed. In particular it prints the lists of success test cases, failing ones and skipped ones.
 * Data about the test case outputs are collected in 'onTestSuccess' and 'onTestFailure' methods.
 * @param testContext test context - testNG handling
 */
@Override
public void onFinish(ITestContext testContext) {
    String testName = testContext.getCurrentXmlTest().getName(); //test suite name
    int numTestSuccess = testContext.getPassedTests().size(); //number of successful test cases in the current test suite
    int numTestFailed = testContext.getFailedTests().size(); //number of failed test cases in the current test suite
    List<ITestResult> localSkippedTests = (List<ITestResult>) testContext.getAttribute("skippedTestCases");
    int numTestSkipped = localSkippedTests.size() + testContext.getSkippedTests().size(); //number of skipped test cases in the current test suite
    if (!localSkippedTests.isEmpty()) {
        numTestSuccess = numTestSuccess - numTestSkipped;
    }
    if (numTestSkipped > 0 && numTestSuccess == 0 && numTestFailed == 0) {
        // test suite totally skipped
        logger.trace("*************[{}][Suite description: {}] SKIPPED Test Suite", testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString());
        logger.info("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}",
            testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(), numTestSuccess, numTestFailed, numTestSkipped);
    } else {
        logger.debug("*************[{}][{}] END Test Suite: Success: {} / Failed: {} / Skipped: {}",
            testName, testContext.getAttribute(TestBaseRunner.SUITE_DESCRIPTION_CTX_ATTR).toString(), numTestSuccess, numTestFailed, numTestSkipped);
    }

    if (numTestFailed > 0) {
        Iterator testFailedIterator = testContext.getFailedTests().getAllResults().iterator();
        while (testFailedIterator.hasNext()) {
            ITestResult singleResult = (ITestResult) testFailedIterator.next();
            logger.error("******* TC FAILED >> {}",
                    singleResult.getThrowable().getMessage());
        }
    }
}
 
Example 33
Project: AutomationFrameworkTPG   File: TestBase.java   View source code 5 votes vote down vote up
@AfterMethod(alwaysRun = true)
public void baseCleanup(ITestContext context, ITestResult result, Object[] params) throws IOException {
	if (params.length > 0 && params[0] instanceof WebDriverInstance){
		WebDriverInstance webDriverInstance = (WebDriverInstance)params[0];
		webDriverInstance.cleanup();
	}
	logTestResult(result);
	String tag = ThreadContext.get(THREAD_TAG);
	logger.info("Test is finished, removing the tag [{}]...", tag);
	ThreadContext.remove(THREAD_TAG);
	result.setAttribute(THREAD_TAG, tag);
}
 
Example 34
Project: TestNG-Foundation   File: ListenerChain.java   View source code 5 votes vote down vote up
/**
 * [ITestListener]
 * Invoked after the test class is instantiated and before
 * any configuration method is called.
 * 
 * @param context context for the test run
 */
@Override
public void onStart(ITestContext context) {
    synchronized (testListeners) {
        for (ITestListener testListener : Lists.reverse(testListeners)) {
            testListener.onStart(context);
        }
    }
}
 
Example 35
Project: heat   File: CustomJUnitReportListener.java   View source code 5 votes vote down vote up
private Properties setTestSuiteAttribute(Properties testSuiteAttr, String suiteName, ITestContext suiteContext) {
    Properties testSuiteAttributes = testSuiteAttr;
    int numFailures = getList(FAILED_TC, suiteContext).size();
    int numSuccess = getList(PASSED_TC, suiteContext).size();
    int numSkipped = getList(SKIPPED_TC, suiteContext).size();
    testSuiteAttributes.setProperty(XMLConstants.ATTR_NAME, suiteName);
    int tests = numFailures + numSuccess + numSkipped;
    if (tests == 0) {
        testSuiteAttributes.setProperty(PROP_STATUS, SKIPPED_STATUS);
    } else {
        testSuiteAttributes.setProperty(SUCCESS_STATUS, String.valueOf(numSuccess));
        testSuiteAttributes.setProperty(SKIPPED_STATUS, String.valueOf(numSkipped));
        int numberOfTests = numFailures + numSuccess + numSkipped;
        testSuiteAttributes.setProperty(XMLConstants.ATTR_TESTS, String.valueOf(numberOfTests));
        Date timeStamp = Calendar.getInstance().getTime();
        testSuiteAttributes.setProperty(XMLConstants.ATTR_FAILURES, String.valueOf(numFailures));
        testSuiteAttributes.setProperty(XMLConstants.ATTR_TIMESTAMP, timeStamp.toGMTString());
        if (numFailures > 0) {
            testSuiteAttributes.setProperty(PROP_STATUS, FAILED_STATUS);
        } else {
            testSuiteAttributes.setProperty(PROP_STATUS, SUCCESS_STATUS);
            numberOfPassedSuites += 1;
        }
    }

    return testSuiteAttributes;
}
 
Example 36
Project: TestNG-Foundation   File: ExecutionFlowController.java   View source code 5 votes vote down vote up
@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
    // target platform support: filter out non-targeted methods
    // target platform support: set method target descriptions
    
    return methods;
}
 
Example 37
Project: heat   File: BasicMultipleChecks.java   View source code 5 votes vote down vote up
public BasicMultipleChecks(ITestContext context) {
    this.logUtils = TestSuiteHandler.getInstance().getLogUtils();
    this.context = context;
    this.steps = new TreeMap<>();
    this.paths = new HashMap<>();
    this.httpMethods = new HashMap<>();
}
 
Example 38
Project: teemo   File: DataProviderX.java   View source code 5 votes vote down vote up
@DataProvider(name = NAME_LAZY)
public static Iterator<Object[]> dataLazy(Method method, ITestContext cxt) {
	if (logger.isInfoEnabled()) {
		logger.info(method.getName() + " is using DataProviderX for Iterator<Object[]>");
	}

	// 检查配置
	checkConfig();
	// 检查参数
	Parameter[] vParams = checkAndGetParam(method);
	// 方法变更时清除Resolver缓存
	clearResolverCache(method);
	// 获取数据分组名
	String vGroup = mConfig.getGroupResovler().resolve(method);
	logger.debug("Group Name: " + vGroup);
	// 处理Reader
	IDataReader vReader = mConfig.getReader();
	// 调用changeGroup方法的线程和调用Iterator方法的线程为同一个
	// 因此无需特殊处理
	vReader.changeGroup(vGroup);
	boolean vUseCriteria = resetCriteria(vReader, method);
	IRowFilter vFilter = null;
	if (!vUseCriteria) {
		vFilter = getFilter(method);
		if (vFilter != null) {
			vFilter.setContext(new ProviderContext(method, vGroup, cxt));
		}
	}
	return new DataIterator(vReader, vFilter, vParams);
}
 
Example 39
Project: Equella   File: AbstractRestAssuredTest.java   View source code 5 votes vote down vote up
@BeforeSuite
public void setupProxy(ITestContext testContext)
{
	testContext.getSuite().setAttribute("cleanups", Lists.newArrayList());
	String proxyHost = testConfig.getProperty("proxy.host");
	String proxyPortString = testConfig.getProperty("proxy.port");
	if( proxyPortString != null )
	{
		System.setProperty("http.proxyHost", proxyHost);
		System.setProperty("http.proxyPort", proxyPortString);
	}
}
 
Example 40
Project: Equella   File: AbstractTest.java   View source code 5 votes vote down vote up
@AfterClass(alwaysRun = true)
public void finishedClass(ITestContext testContext) throws Exception
{
	if( context == null )
	{
		return;
	}
	String delValue = testConfig.getProperty("test.deleteitems");
	if( delValue == null || Boolean.parseBoolean(delValue) )
	{
		cleanupAfterClass();
	}
}