Java Code Examples for org.testng.Reporter#getCurrentTestResult()

The following examples show how to use org.testng.Reporter#getCurrentTestResult() . 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: 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 2
Source File: QAFTestBase.java    From qaf with MIT License 6 votes vote down vote up
public PropertyUtil getContext() {
	try {
		ITestResult tr = Reporter.getCurrentTestResult();
		if (null != tr) {
			PropertyUtil contextFromTr = (PropertyUtil) Reporter.getCurrentTestResult().getAttribute(CONTEXT);
			if (null == contextFromTr) {
				Reporter.getCurrentTestResult().setAttribute(CONTEXT, context);
				return context;
			}
			return contextFromTr;
		}
	} catch (Exception e) {
		// ignore - none TestNG implementation
	}
	return context;
}
 
Example 3
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@TestPriority(Priority.P1)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P5")
public void testForbiddenPriorityTag() {
    ITestResult result = Reporter.getCurrentTestResult();
    String priority = PriorityManager.getPriority(result);
    Assert.assertEquals(priority, "P1");
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertEquals(tags.size(), 0);
}
 
Example 4
Source File: TagManagerTest.java    From carina-demo with Apache License 2.0 5 votes vote down vote up
@Test
@TestTag(name = TAG_NAME2, value = TAG_VALUE2)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P0")
public void testZafiraGetTagsMethodWoPriority() {
    ITestResult result = Reporter.getCurrentTestResult();
    String priority = PriorityManager.getPriority(result);
    Assert.assertEquals(priority, "P6");
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertTrue(tags.containsKey(TAG_NAME));
    Assert.assertEquals(tags.get(TAG_NAME), TAG_VALUE);
    Assert.assertTrue(tags.containsKey(TAG_NAME2));
    Assert.assertEquals(tags.get(TAG_NAME2), TAG_VALUE2);
    Assert.assertEquals(tags.size(), 2);
    Set<TagType> tagsTypes = getTestTags(result);
    Assert.assertEquals(tagsTypes.size(), 3);
    for (TagType entry : tagsTypes) {
        if (entry.getName().equals(TAG_NAME2)) {
            Assert.assertEquals(entry.getValue(), TAG_VALUE2);
        }
    }

    tagsTypes.stream().forEachOrdered((entry) -> {
        Object currentKey = entry.getName();
        Object currentValue = entry.getValue();
        LOGGER.info(currentKey + "=" + currentValue);
    });
}
 
Example 5
Source File: TagManagerTest.java    From carina-demo with Apache License 2.0 5 votes vote down vote up
@Test
@TestPriority(Priority.P2)
@TestTag(name = TAG_NAME2, value = TAG_VALUE2)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P0")
public void testZafiraGetTagsMethod() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tags = TagManager.getTags(result);
    String priority = PriorityManager.getPriority(result);
    Assert.assertEquals(priority, "P2");
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertTrue(tags.containsKey(TAG_NAME));
    Assert.assertEquals(tags.get(TAG_NAME), TAG_VALUE);
    Assert.assertTrue(tags.containsKey(TAG_NAME2));
    Assert.assertEquals(tags.get(TAG_NAME2), TAG_VALUE2);
    Assert.assertEquals(tags.size(), 2);
    Set<TagType> tagsTypes = getTestTags(result);
    Assert.assertEquals(tagsTypes.size(), 3);
    for (TagType entry : tagsTypes) {
        if (entry.getName().equals(SpecialKeywords.TEST_PRIORITY_KEY)) {
            Assert.assertEquals(entry.getValue(), "P2");
        }
    }

    tagsTypes.stream().forEachOrdered((entry) -> {
        Object currentKey = entry.getName();
        Object currentValue = entry.getValue();
        LOGGER.info(currentKey + "=" + currentValue);
    });
}
 
Example 6
Source File: TagManagerTest.java    From carina-demo with Apache License 2.0 5 votes vote down vote up
@Test
@TestPriority(Priority.P1)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P5")
public void testForbiddenPriorityTag() {
    ITestResult result = Reporter.getCurrentTestResult();
    String priority = PriorityManager.getPriority(result);
    Assert.assertEquals(priority, "P1");
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertEquals(tags.size(), 0);
}
 
Example 7
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@MethodOwner(owner = "qpsdemo")
@TestPriority(Priority.P0)
public void testPriorityCompliance() {
    ITestResult result = Reporter.getCurrentTestResult();
    String priority = PriorityManager.getPriority(result);
    Assert.assertEquals(priority, "P0");
}
 
Example 8
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@TestPriority(Priority.P2)
@TestTag(name = TAG_NAME2, value = TAG_VALUE2)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P0")
public void testForbiddenTags() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertTrue(tags.containsKey(TAG_NAME));
    Assert.assertEquals(tags.get(TAG_NAME), TAG_VALUE);
    Assert.assertTrue(tags.containsKey(TAG_NAME2));
    Assert.assertEquals(tags.get(TAG_NAME2), TAG_VALUE2);
    Assert.assertEquals(tags.size(), 2);
}
 
Example 9
Source File: TagManagerTest.java    From carina-demo with Apache License 2.0 5 votes vote down vote up
@Test
@MethodOwner(owner = "qpsdemo")
@TestPriority(value = Priority.P1)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
public void testTags() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tag = TagManager.getTags(result);
    Assert.assertTrue(tag.containsKey(TAG_NAME));
    Assert.assertEquals(tag.get(TAG_NAME), TAG_VALUE);
}
 
Example 10
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@MethodOwner(owner = "qpsdemo")
@TestPriority(Priority.P2)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
@TestTag(name = TAG_NAME2, value = TAG_VALUE2)
public void testRepeatableTags() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertTrue(tags.containsKey(TAG_NAME));
    Assert.assertEquals(tags.get(TAG_NAME), TAG_VALUE);
    Assert.assertTrue(tags.containsKey(TAG_NAME2));
    Assert.assertEquals(tags.get(TAG_NAME2), TAG_VALUE2);
}
 
Example 11
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);
            }
        }
    }
}
 
Example 12
Source File: MethodOwnerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test(dependsOnMethods="testDefaultMethodOwner")
@MethodOwner(owner = ANDROID_OWNER, platform = SpecialKeywords.ANDROID)
@MethodOwner(owner = DEFAULT_OWNER)
@MethodOwner(owner = IOS_OWNER, platform = SpecialKeywords.IOS)
public void testAndroidMethodOwner() {
	R.CONFIG.put(SpecialKeywords.PLATFORM, "android");
    ITestResult result = Reporter.getCurrentTestResult();
    String ownerName = Ownership.getMethodOwner(result);
    Assert.assertEquals(ownerName, ANDROID_OWNER);
}
 
Example 13
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@TestPriority(Priority.P2)
@TestTag(name = TAG_NAME2, value = TAG_VALUE2)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
@TestTag(name = FORBIDDEN_KEY_PRIORITY, value = "P0")
public void testForbiddenTags() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tags = TagManager.getTags(result);
    Assert.assertFalse(tags.containsKey(FORBIDDEN_KEY_PRIORITY));
    Assert.assertTrue(tags.containsKey(TAG_NAME));
    Assert.assertEquals(tags.get(TAG_NAME), TAG_VALUE);
    Assert.assertTrue(tags.containsKey(TAG_NAME2));
    Assert.assertEquals(tags.get(TAG_NAME2), TAG_VALUE2);
    Assert.assertEquals(tags.size(), 2);
}
 
Example 14
Source File: TagManagerTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@MethodOwner(owner = "qpsdemo")
@TestPriority(value = Priority.P1)
@TestTag(name = TAG_NAME, value = TAG_VALUE)
public void testTags() {
    ITestResult result = Reporter.getCurrentTestResult();
    Map<String, String> tag = TagManager.getTags(result);
    Assert.assertTrue(tag.containsKey(TAG_NAME));
    Assert.assertEquals(tag.get(TAG_NAME), TAG_VALUE);
}
 
Example 15
Source File: TestNgPlatformBase.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("serial")
public void activatePlatform(WebDriver driver, P platform) throws PlatformActivationFailedException {
    ITestResult testResult = Reporter.getCurrentTestResult();
    if (testResult != null) {
        String description = testResult.getMethod().getDescription();
        PlatformIdentity<P> identity = DataUtils.fromString(description, new TypeToken<PlatformIdentity<P>>(){}.getType());
        if (identity != null) {
            testResult.setAttribute(PLATFORM, identity.deserialize());
        }
    }
}
 
Example 16
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 17
Source File: TestNgBase.java    From Selenium-Foundation with Apache License 2.0 5 votes vote down vote up
/**
 * Get the listener of the specified type that's attached to the listener chain.
 * 
 * @param <T> listener type
 * @param listenerType listener type
 * @return listener of the specified type
 */
public static <T extends ITestNGListener> T getLinkedListener(final Class<T> listenerType) {
    ITestResult testResult = Reporter.getCurrentTestResult();
    Optional<T> optListener = 
                    ListenerChain.getAttachedListener(testResult, listenerType);
    if (optListener.isPresent()) {
        return optListener.get();
    }
    throw new IllegalStateException(listenerType.getSimpleName() + " listener wasn't found on the listener chain");
}
 
Example 18
Source File: TestRailTest.java    From carina with Apache License 2.0 5 votes vote down vote up
@Test
@TestRailCases(testCasesId = FIRST_TEST_ID)
public void testTestRailSimple() {
    ITestResult result = Reporter.getCurrentTestResult();

    Set<String> testRailUdids = getTestRailCasesUuid(result);

    Assert.assertTrue(testRailUdids.contains(FIRST_TEST_ID), "TestRail should contain id=" + FIRST_TEST_ID);

    Assert.assertEquals(testRailUdids.size(), 1);
}
 
Example 19
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 20
Source File: QTestTest.java    From carina with Apache License 2.0 3 votes vote down vote up
@Test
@QTestCases(id = FIRST_TEST_ID, platform = "ios")
@QTestCases(id = SECOND_TEST_ID, platform = "android")
public void testQTestByPlatform() {
    ITestResult result = Reporter.getCurrentTestResult();

    Set<String> QTestUdids = getQTestCasesUuid(result);

    Assert.assertEquals(QTestUdids.size(), 0);

    LOGGER.info(QTestUdids.toString());

    R.CONFIG.put(SpecialKeywords.MOBILE_DEVICE_PLATFORM, SpecialKeywords.IOS);

    QTestUdids = getQTestCasesUuid(result);

    Assert.assertTrue(QTestUdids.contains(FIRST_TEST_ID), "QTest should contain id=" + FIRST_TEST_ID);

    Assert.assertEquals(QTestUdids.size(), 1);

    R.CONFIG.put(SpecialKeywords.MOBILE_DEVICE_PLATFORM, SpecialKeywords.ANDROID);

    QTestUdids = getQTestCasesUuid(result);

    Assert.assertTrue(QTestUdids.contains(SECOND_TEST_ID), "QTest should contain id=" + SECOND_TEST_ID);

    Assert.assertEquals(QTestUdids.size(), 1);

    R.CONFIG.put(SpecialKeywords.MOBILE_DEVICE_PLATFORM, "");
}