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

The following examples show how to use org.testng.ITestResult#getAttribute() . 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: QAFTestNGListener2.java    From qaf with MIT License 6 votes vote down vote up
@Override
protected void report(ITestResult tr) {
	super.report(tr);
	if(!getBundle().getBoolean("cucumber.run.mode", false)) {
		deployResult(tr);
		if (!getBundle().getBoolean("disable.qaf.testng.reporter", false)) {
			QAFTestBase stb = TestBaseProvider.instance().get();
			final List<CheckpointResultBean> checkpoints = new ArrayList<CheckpointResultBean>(
					stb.getCheckPointResults());

			// pro
			final List<LoggingBean> logs = new ArrayList<LoggingBean>(stb.getLog());
			ITestContext testContext = (ITestContext) tr.getAttribute("context");
			ReporterUtil.createMethodResult(testContext, tr, logs, checkpoints);
		}
	}
	if (tr.getStatus() != ITestResult.SKIP) {
		getBundle().clearProperty(RetryAnalyzer.RETRY_INVOCATION_COUNT);
	}
}
 
Example 2
Source File: DriverListener.java    From carina with Apache License 2.0 6 votes vote down vote up
private void onBeforeAction() {
	// 4a. if "tzid" not exist inside vncArtifact and exists in Reporter -> register new vncArtifact in Zafira.
	// 4b. if "tzid" already exists in current artifact but in Reporter there is another value. Then this is use case for class/suite mode when we share the same
	// driver across different tests

	ITestResult res = Reporter.getCurrentTestResult();
	if (res != null && res.getAttribute("ztid") != null) {
		Long ztid = (Long) res.getAttribute("ztid");
		if (ztid != vncArtifact.getTestId() && vncArtifact != null && ! StringUtils.isBlank(vncArtifact.getName())) {
			vncArtifact.setTestId(ztid);
			LOGGER.debug("Registered live video artifact " + vncArtifact.getName() + " into zafira");
			ZafiraSingleton.INSTANCE.getClient().addTestArtifact(vncArtifact);
		}

	}
}
 
Example 3
Source File: TestNgBase.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Store the specified object in the attributes collection, tracking reference propagation.
 * 
 * @param obj object to be stored; 'null' to discard value and release tracked references
 */
private void track(final Object obj) {
    ITestResult result = Reporter.getCurrentTestResult();
    if (obj != null) {
        new TrackedObject<>(result, key, obj);
    } else {
        Object val = result.getAttribute(key);
        if (val instanceof TrackedObject) {
            ((TrackedObject<?>) val).release();
        } else {
            result.removeAttribute(key);
        }
    }
}
 
Example 4
Source File: TestNgBase.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * If present, get the object from the attributes collection.
 * 
 * @return (optional) stored object
 */
private Optional<?> nab() {
    Object obj;
    ITestResult result = Reporter.getCurrentTestResult();
    Object val = result.getAttribute(key);
    if (val instanceof TrackedObject) {
        obj = ((TrackedObject<?>) val).getValue();
    } else {
        obj = val;
    }
    return TestBase.optionalOf(obj);
}
 
Example 5
Source File: TestNgPlatformBase.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public P getTargetPlatform() {
    ITestResult testResult = Reporter.getCurrentTestResult();
    if (testResult != null) {
        return (P) testResult.getAttribute(PLATFORM);
    }
    return null;
}
 
Example 6
Source File: ReporterUtil.java    From qaf with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private static String getMethodIdentifier(ITestResult result){

	if(result.getAttribute(QAF_TEST_IDENTIFIER)!=null){
		return (String) result.getAttribute(QAF_TEST_IDENTIFIER);
	}
	
	String id = getMethodName(result);
	String identifierKey = ApplicationProperties.TESTCASE_IDENTIFIER_KEY.getStringVal("testCaseId");

	Map<String, Object> metadata =
			new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);

	if (result.getMethod() instanceof TestNGScenario) {
		TestNGScenario scenario = (TestNGScenario) result.getMethod();
		metadata.putAll(scenario.getMetaData());
	}
	if(result.getParameters()!=null && result.getParameters().length>0){
		if(result.getParameters()[0] instanceof Map<?, ?>){
			metadata.putAll((Map<String, Object>)result.getParameters()[0]);
		}
	}
	String idFromMetaData = metadata.getOrDefault(identifierKey,"").toString();
	if (StringUtil.isNotBlank(idFromMetaData) ) {
		id = idFromMetaData;
	}
	id=StringUtil.toTitleCaseIdentifier(id);
	
	if(id.length()>45){
		id=id.substring(0, 45);
	}
	result.setAttribute(QAF_TEST_IDENTIFIER,id);
	return (String) result.getAttribute(QAF_TEST_IDENTIFIER);
}
 
Example 7
Source File: Log.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private static TestContextReporter getReporter() {
    ITestResult res = Reporter.getCurrentTestResult();
    if (res == null) {
        return null;
    }
    TestContextReporter reporter = (TestContextReporter) res.getAttribute(TEST_CONTEXT_REPORTER);
    if (reporter == null) {
        reporter = new TestContextReporter();
        res.setAttribute(TEST_CONTEXT_REPORTER, reporter);
    }

    return reporter;
}
 
Example 8
Source File: EarlReporter.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * Processes any attributes that were attached to a test result. Attributes
 * should describe relevant test events in order to help identify the root
 * cause of a fail verdict. Specifically, the following statements are added
 * to the report:
 * <ul>
 * <li>{@value #REQ_ATTR} : Information about the request message
 * (earl:TestResult --cite:message-- http:Request)</li>
 * <li>{@value #RSP_ATTR} : Information about the response message
 * (http:Request --http:resp-- http:Response)</li>
 * </ul>
 * 
 * @param earlResult
 *            An earl:TestResult resource.
 * @param tngResult
 *            The TestNG test result.
 */
void processResultAttributes(Resource earlResult, final ITestResult tngResult) {
    if (!tngResult.getAttributeNames().contains(REQ_ATTR))
        return;
    // keep it simple for now
    String reqVal = tngResult.getAttribute(REQ_ATTR).toString();
    String httpMethod = (reqVal.startsWith("<")) ? HttpMethod.POST : HttpMethod.GET;
    Resource httpReq = this.earlModel.createResource(HTTP.Request);
    httpReq.addProperty(HTTP.methodName, httpMethod);
    if (httpMethod.equals(HttpMethod.GET)) {
        httpReq.addProperty(HTTP.requestURI, reqVal);
    } else {
    	httpReq.addProperty(HTTP.requestURI, reqVal);
        Resource reqContent = this.earlModel.createResource(CONTENT.ContentAsXML);
        // XML content may be truncated and hence not well-formed
        reqContent.addProperty(CONTENT.rest, reqVal);
        httpReq.addProperty(HTTP.body, reqContent);
    }
    Object rsp = tngResult.getAttribute(RSP_ATTR);
    if (null != rsp) {
        Resource httpRsp = this.earlModel.createResource(HTTP.Response);
        // safe assumption, but need more response info to know for sure
        Resource rspContent = this.earlModel.createResource(CONTENT.ContentAsXML);
        rspContent.addProperty(CONTENT.rest, rsp.toString());
        httpRsp.addProperty(HTTP.body, rspContent);
        httpReq.addProperty(HTTP.resp, httpRsp);
    }
    earlResult.addProperty(CITE.message, httpReq);
}
 
Example 9
Source File: IDriverCommandListener.java    From carina with Apache License 2.0 5 votes vote down vote up
default public void registerArtifact(Command command, TestArtifactType artifact) {
    // 4a. if "tzid" not exist inside videoArtifact and exists in Reporter -> register new videoArtifact in Zafira.
    // 4b. if "tzid" already exists in current artifact but in Reporter there is another value. Then this is use case for class/suite mode when we share the same driver across different tests
    ITestResult res = Reporter.getCurrentTestResult();
    if (res != null && res.getAttribute("ztid") != null) {
        Long ztid = (Long) res.getAttribute("ztid");
        if (ztid != artifact.getTestId()) {
            artifact.setTestId(ztid);
            LISTENER_LOGGER.debug("Registered artifact " + artifact.getName() + " into zafira");
            if (ZafiraSingleton.INSTANCE.isRunning()) {
                ZafiraSingleton.INSTANCE.getClient().addTestArtifact(artifact);
            }
        }
    }
}