Java Code Examples for org.testng.ITestResult#getInstance()

The following examples show how to use org.testng.ITestResult#getInstance() . 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: QuickPerfTestNGListener.java    From quickperf with Apache License 2.0 7 votes vote down vote up
private void executeTestMethodInNewJvmAndRecordPerformance(ITestResult testResult, TestExecutionContext testExecutionContext) {

        Object[] args = new Object[0];
        Method method = extractTestMethod(testResult);

        performanceRecording.start(testExecutionContext);

        try {
            Object target = testResult.getInstance();
            //directly invoke the method to lower the interaction between JUnit, other extensions and QuickPerf.
            method.invoke(target, args);
        } catch (Throwable throwable) {
            testResult.setThrowable(throwable);
            testResult.setStatus(ITestResult.FAILURE);
        } finally {
            performanceRecording.stop(testExecutionContext);
        }

    }
 
Example 2
Source File: TestListener.java    From PatatiumWebUi with Apache License 2.0 6 votes vote down vote up
@Override
public void onTestSkipped(ITestResult tr) {
	TestBaseCase testBaseCase=(TestBaseCase) tr.getInstance();
	WebDriver driver=testBaseCase.driver;
	ScreenShot screenShot=new ScreenShot(driver);
	//设置截图名字
	screenShot.setscreenName(tr.getMethod().getDescription());
	screenShot.takeScreenshot();
	log.warn("测试用例: "+tr.getMethod().getDescription()+"--skipped");
	log.info("测试用例:"+tr.getMethod().getDescription()+"---end");
}
 
Example 3
Source File: DriverListener.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Perform post-invocation processing:
 * <ul>
 *     <li>If indicated, close the driver that was acquired for this method.</li>
 * </ul>
 * 
 * @param invokedMethod an object representing the method that's just been invoked
 * @param testResult test result object for the method that's just been invoked
 */
@Override
public void afterInvocation(final IInvokedMethod invokedMethod, final ITestResult testResult) {
    // ensure current test result is set
    Reporter.setCurrentTestResult(testResult);
    
    Object obj = testResult.getInstance();
    Method method = invokedMethod.getTestMethod().getConstructorOrMethod().getMethod();
    
    DriverManager.afterInvocation(obj, method);
}
 
Example 4
Source File: TestListener.java    From PatatiumAppUi with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onTestSkipped(ITestResult tr) {
	TestBaseCase testBaseCase=(TestBaseCase) tr.getInstance();
	WebDriver driver=testBaseCase.driver;
	ScreenShot screenShot=new ScreenShot(driver);
	//设置截图名字
	screenShot.setscreenName(tr.getMethod().getDescription());
	screenShot.takeScreenshot();
	log.warn("测试用例: "+tr.getMethod().getDescription()+"--skipped");
	log.info("测试用例:"+tr.getMethod().getDescription()+"---end");
}
 
Example 5
Source File: QuantumReportiumListener.java    From Quantum with MIT License 5 votes vote down vote up
private void tearIt(ITestResult testResult) {
	if ((testResult.getTestContext().getCurrentXmlTest().getParallel().toString().equalsIgnoreCase("methods")
			& testResult.getTestClass().getName().toLowerCase().contains("scenario"))
			|| ConfigurationManager.getBundle().getString("global.datadriven.parallel", "false")
					.equalsIgnoreCase("true")
			|| testResult.getTestContext().getCurrentXmlTest().getXmlClasses().get(0).getName()
					.contains("com.qmetry.qaf.automation.step.client.excel.ExcelTestFactory")
			|| testResult.getTestContext().getCurrentXmlTest().getXmlClasses().get(0).getName()
					.contains("com.qmetry.qaf.automation.step.client.csv.KwdTestFactory")

	) {
		Object testInstance = testResult.getInstance();
		((WebDriverTestCase) testInstance).getTestBase().tearDown();
	}
}
 
Example 6
Source File: SeleniumTestHandler.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
private void captureWebDriver(ITestResult result) {
  Set<SeleniumWebDriver> webDrivers = new HashSet<>();
  Object testInstance = result.getInstance();

  collectInjectedWebDrivers(testInstance, webDrivers);
  webDrivers.forEach(webDriver -> captureWebDriver(result, webDriver));
}
 
Example 7
Source File: ScreenshotListener.java    From frameworkium-core with Apache License 2.0 4 votes vote down vote up
private boolean isScreenshotSupported(ITestResult testResult) {
    boolean isElectron = BROWSER.isSpecified()
            && ELECTRON.equals(Browser.valueOf(BROWSER.getValue().toUpperCase()));
    boolean isUITest = testResult.getInstance() instanceof BaseUITest;
    return isUITest && !isElectron;
}
 
Example 8
Source File: AllureTestListener.java    From allure1 with Apache License 2.0 4 votes vote down vote up
public Annotation[] getClassAnnotations(ITestResult iTestResult) {
    if (iTestResult.getInstance() == null) {
        return new Annotation[0];
    }
    return iTestResult.getInstance().getClass().getAnnotations();
}
 
Example 9
Source File: DriverListener.java    From Selenium-Foundation with Apache License 2.0 3 votes vote down vote up
/**
 * Perform pre-invocation processing:
 * <ul>
 *     <li>Ensure that a driver instance has been created for the test.</li>
 *     <li>Store the driver instance for subsequent dispensing.</li>
 *     <li>Manage configured driver timeout intervals.</li>
 *     <li>If specified, open the initial page, storing the page object for subsequent dispensing.</li>
 * </ul>
 * 
 * @param invokedMethod an object representing the method that's about to be invoked
 * @param testResult test result object for the method that's about to be invoked
 */
@Override
public void beforeInvocation(final IInvokedMethod invokedMethod, final ITestResult testResult) {
    // ensure current test result is set
    Reporter.setCurrentTestResult(testResult);
    
    Object obj = testResult.getInstance();
    Method method = invokedMethod.getTestMethod().getConstructorOrMethod().getMethod();
    
    DriverManager.beforeInvocation(obj, method);
}