Java Code Examples for org.testng.ITestContext#getAllTestMethods()

The following examples show how to use org.testng.ITestContext#getAllTestMethods() . 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: WebTesterTestNGListener.java    From webtester-core with Apache License 2.0 6 votes vote down vote up
private void initializeClassLevel(ITestContext iTestContext) {
    classBrowsers.clear();
    ITestNGMethod[] testMethods = iTestContext.getAllTestMethods();
    for (ITestNGMethod method : testMethods) {
        Class<?> testClass = method.getRealClass();
        for (Field field : ReflectionUtils.getAllFieldsOfClassHierarchy(testClass)) {
            boolean fieldIsStatic = Modifier.isStatic(field.getModifiers());
            boolean fieldIsABrowser = Browser.class.isAssignableFrom(field.getType());
            boolean fieldIsAnnotatedAsResource = field.getAnnotation(Resource.class) != null;
            boolean isNoDuplicate = fieldIsNoDuplicateOfAnExistingClassBrowserField(field);
            if (fieldIsStatic && fieldIsABrowser && fieldIsAnnotatedAsResource && isNoDuplicate) {
                classBrowserFields.add(field);
                classBrowsers.add(new ClassTestBrowser(field));
            }
        }
    }
}
 
Example 2
Source File: EverrestJetty.java    From everrest with Eclipse Public License 2.0 6 votes vote down vote up
public void onStart(ITestContext context) {

        ITestNGMethod[] allTestMethods = context.getAllTestMethods();
        if (allTestMethods == null) {
            return;
        }
        if (httpServer == null && hasEverrestJettyListenerTestHierarchy(allTestMethods)) {
            httpServer = new JettyHttpServer();

            context.setAttribute(JETTY_PORT, httpServer.getPort());
            context.setAttribute(JETTY_SERVER, httpServer);

            try {
                httpServer.start();
                httpServer.resetFactories();
                httpServer.resetFilter();
                RestAssured.port = httpServer.getPort();
                RestAssured.basePath = JettyHttpServer.UNSECURE_REST;
            } catch (Exception e) {
                LOG.error(e.getLocalizedMessage(), e);
                throw new RuntimeException(e.getLocalizedMessage(), e);
            }
        }
    }
 
Example 3
Source File: ExpectedSkipManager.java    From carina with Apache License 2.0 6 votes vote down vote up
/**
 * Collect rules based on tests and its context
 * 
 * @param testMethod
 * @param context
 * @return rules list
 */
private List<Class<? extends IRule>> collectRules(Method testMethod, ITestContext context) {
    List<Class<? extends IRule>> rules = new ArrayList<>();
    // collect rules from current class and method
    ExpectedSkip classSkipAnnotation = testMethod.getDeclaringClass().getAnnotation(ExpectedSkip.class);
    ExpectedSkip methodSkipAnnotation = testMethod.getAnnotation(ExpectedSkip.class);
    rules.addAll(getRulesFromAnnotation(classSkipAnnotation));
    rules.addAll(getRulesFromAnnotation(methodSkipAnnotation));

    // analyze all dependent methods and collect rules
    ITestNGMethod[] methods = context.getAllTestMethods();
    for (ITestNGMethod iTestNGMethod : methods) {
        if (iTestNGMethod.getMethodName().equalsIgnoreCase(testMethod.getName())) {
            String[] methodsDep = iTestNGMethod.getMethodsDependedUpon();
            for (String method : methodsDep) {
                rules.addAll(getDependentMethodsRules(method));
            }
        }
    }

    return rules;
}
 
Example 4
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
    TestDescriptorInternal testInternal;
    synchronized (lock) {
        testInternal = new DefaultTestSuiteDescriptor(idGenerator.generateId(), iTestContext.getName());
        suites.put(testInternal.getName(), testInternal.getId());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.put(method, testInternal.getId());
        }
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestContext.getStartDate().getTime()));
}
 
Example 5
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFinish(ITestContext iTestContext) {
    Object id;
    synchronized (lock) {
        id = suites.remove(iTestContext.getName());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.remove(method);
        }
    }
    resultProcessor.completed(id, new TestCompleteEvent(iTestContext.getEndDate().getTime()));
}
 
Example 6
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
    TestDescriptorInternal testInternal;
    synchronized (lock) {
        testInternal = new DefaultTestSuiteDescriptor(idGenerator.generateId(), iTestContext.getName());
        suites.put(testInternal.getName(), testInternal.getId());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.put(method, testInternal.getId());
        }
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestContext.getStartDate().getTime()));
}
 
Example 7
Source File: TestNGTestResultProcessorAdapter.java    From pushfish-android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFinish(ITestContext iTestContext) {
    Object id;
    synchronized (lock) {
        id = suites.remove(iTestContext.getName());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.remove(method);
        }
    }
    resultProcessor.completed(id, new TestCompleteEvent(iTestContext.getEndDate().getTime()));
}
 
Example 8
Source File: BaseClassForTests.java    From xian with Apache License 2.0 5 votes vote down vote up
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context)
{
    for ( ITestNGMethod method : context.getAllTestMethods() )
    {
        method.setRetryAnalyzer(new RetryTest());
    }
}
 
Example 9
Source File: CustomAutomationReport.java    From pxf with Apache License 2.0 5 votes vote down vote up
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String outputDirectory) {

	StringBuilder sBuilder = new StringBuilder();

	// Iterating over each suite
	for (ISuite suite : suites) {

		// Getting the results for the each suite
		Map<String, ISuiteResult> suiteResults = suite.getResults();
		for (ISuiteResult sr : suiteResults.values()) {
			// get context for result
			ITestContext tc = sr.getTestContext();
			// go over all cases
			for (ITestNGMethod method : tc.getAllTestMethods()) {
				// if a case has "ExpectedFaiGPDBWritable.javalure" annotation, insert to sBuilder

				if (method.getConstructorOrMethod().getMethod().getAnnotation(ExpectedFailure.class) != null) {
					sBuilder.append(method.getInstance().getClass().getName() + "/" + method.getMethodName()).append(System.lineSeparator());
				}
			}
		}
	}

	// write results to file
	try {
		FileUtils.writeStringToFile(new File(outputDirectory + "/automation_expected_failures.txt"), sBuilder.toString(), false);
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 10
Source File: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
    TestDescriptorInternal testInternal;
    synchronized (lock) {
        testInternal = new DefaultTestSuiteDescriptor(idGenerator.generateId(), iTestContext.getName());
        suites.put(testInternal.getName(), testInternal.getId());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.put(method, testInternal.getId());
        }
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestContext.getStartDate().getTime()));
}
 
Example 11
Source File: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFinish(ITestContext iTestContext) {
    Object id;
    synchronized (lock) {
        id = suites.remove(iTestContext.getName());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.remove(method);
        }
    }
    resultProcessor.completed(id, new TestCompleteEvent(iTestContext.getEndDate().getTime()));
}
 
Example 12
Source File: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onStart(ITestContext iTestContext) {
    TestDescriptorInternal testInternal;
    synchronized (lock) {
        testInternal = new DefaultTestSuiteDescriptor(idGenerator.generateId(), iTestContext.getName());
        suites.put(testInternal.getName(), testInternal.getId());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.put(method, testInternal.getId());
        }
    }
    resultProcessor.started(testInternal, new TestStartEvent(iTestContext.getStartDate().getTime()));
}
 
Example 13
Source File: TestNGTestResultProcessorAdapter.java    From Pushjet-Android with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void onFinish(ITestContext iTestContext) {
    Object id;
    synchronized (lock) {
        id = suites.remove(iTestContext.getName());
        for (ITestNGMethod method : iTestContext.getAllTestMethods()) {
            testMethodToSuiteMapping.remove(method);
        }
    }
    resultProcessor.completed(id, new TestCompleteEvent(iTestContext.getEndDate().getTime()));
}
 
Example 14
Source File: WebTesterTestNGListener.java    From webtester-core with Apache License 2.0 5 votes vote down vote up
private void injectConfigurationValuesIntoStaticFields(ITestContext iTestContext) {
    ITestNGMethod[] testMethods = iTestContext.getAllTestMethods();
    for (ITestNGMethod method : testMethods) {
        Class<?> testClass = method.getRealClass();
        if (configurationValuesAnnotationIsUsedOnClassLevel(testClass)) {
            Configuration configuration = getPrimaryBrowser().getBrowser().getConfiguration();
            ConfigurationValueInjector.injectStatics(configuration, testClass);
        }
    }
}
 
Example 15
Source File: BenchmarkTestListener.java    From oxAuth with MIT License 5 votes vote down vote up
private long getMethodThreqads(ITestContext context, String methodName) {
	ITestNGMethod[] allTestMethods = context.getAllTestMethods();
	for (int i = 0; i < allTestMethods.length; i++) {
		if (StringHelper.equalsIgnoreCase(allTestMethods[i].getMethodName(), methodName)) {
			return allTestMethods[i].getThreadPoolSize();
		}
	}

	return 1;
}
 
Example 16
Source File: ReporterUtil.java    From qaf with MIT License 2 votes vote down vote up
private static int getTotal(ITestContext context) {

		return (context == null) || (null == context.getAllTestMethods()) ? 0
				: context.getAllTestMethods().length;

	}