static void copyAttributes(ITestResult source, ITestResult target) { source .getAttributeNames() .forEach(name -> target.setAttribute(name, source.getAttribute(name))); }
@Override public boolean retry(ITestResult iTestResult) { String attribute = (String) iTestResult.getAttribute(RETRY); if (NO.equalsIgnoreCase(attribute)) { return false; } else if (YES.equalsIgnoreCase(attribute) || retryCount < MAX_RETRY_COUNT) { retryCount++; return true; } return false; } }
@Test public void pass() { Assert.assertEquals(Reporter.getCurrentTestResult().getAttribute("before"), 10); Assert.assertEquals(m_testResult.getAttribute("before"), 10); }
private void addTestResultAttributes(XMLStringBuffer xmlBuffer, ITestResult testResult) { if (testResult.getAttributeNames() != null && testResult.getAttributeNames().size() > 0) { xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTES); for (String attrName: testResult.getAttributeNames()) { if (attrName == null) { continue; } Object attrValue = testResult.getAttribute(attrName); Properties attributeAttrs = new Properties(); attributeAttrs.setProperty(XMLReporterConfig.ATTR_NAME, attrName); if (attrValue == null) { attributeAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true"); xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs); } else { xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs); xmlBuffer.addCDATA(attrValue.toString()); xmlBuffer.pop(); } } xmlBuffer.pop(); } }
@Test public void testPlugin() { ITestResult result = Reporter.getCurrentTestResult(); Assert.assertEquals(result.getAttribute("class").toString(), getClass().getName()); Assert.assertNotNull(result.getAttribute("toString")); } }
private void extractAttributes(ITestResult result) { Consumer<String> attribute = each -> attributes.put(each, result.getAttribute(each).toString()); result.getAttributeNames().forEach(attribute); }
/** * Gets the appenders. * * @param tr the ITestResult * @return the appenders */ public static Appenders getAppenders(ITestResult tr) { Appenders appenders = (Appenders) tr.getAttribute(NAME); return appenders; }
private void addTestResultAttributes(XMLStringBuffer xmlBuffer, ITestResult testResult) { if (testResult.getAttributeNames() != null && testResult.getAttributeNames().size() > 0) { xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTES); for (String attrName : testResult.getAttributeNames()) { if (attrName == null) { continue; } Object attrValue = testResult.getAttribute(attrName); Properties attributeAttrs = new Properties(); attributeAttrs.setProperty(XMLReporterConfig.ATTR_NAME, attrName); if (attrValue == null) { attributeAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true"); xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs); } else { xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs); xmlBuffer.addCDATA(attrValue.toString()); xmlBuffer.pop(); } } xmlBuffer.pop(); } } }
/** * Gets the log file. * * @param tr the tr * @return the log file */ public static File getLogFile(ITestResult tr) { return (File) tr.getAttribute(NAME); }
private static Map<String, Object> attributesFrom(ITestResult r) { Map<String, Object> attributes = Maps.newHashMap(); for (String key : r.getAttributeNames()) { attributes.put(key, r.getAttribute(key)); } return attributes; } }
/** * Gets the attachment files. * * @param tr the ITestResult * @return the attachment files */ @SuppressWarnings("unchecked") public static List<File> getAttachmentFiles(ITestResult tr) { return (List<File>) tr.getAttribute(NAME); }
private static Map<String, Object> extractAttributes(ITestResult result) { Map<String, Object> attributes = new HashMap<String, Object>(); for (String eachAttribute : result.getAttributeNames()) { attributes.put(eachAttribute, result.getAttribute(eachAttribute)); } return attributes; }
private ScenarioBase getScenario(ITestResult paramITestResult ) { return (ScenarioBase) paramITestResult.getAttribute(SCENARIO_ATTRIBUTE); }
@Override protected Object resolveAnnotatedResource(ITestResult testResult, Class<?> parameterType, TestContext context) { if (TestDesigner.class.isAssignableFrom(parameterType)) { return testResult.getAttribute(DESIGNER_ATTRIBUTE); } else if (TestRunner.class.isAssignableFrom(parameterType)) { return testResult.getAttribute(RUNNER_ATTRIBUTE); } return super.resolveAnnotatedResource(testResult, parameterType, context); }
@Override public List<String> getKeys(ITestResult result) { SeLionLogger.getLogger().entering(result); String testName = null; if (result.getAttribute(HtmlReporterListener.TEST_NAME_KEY) != null) { testName = result.getAttribute(HtmlReporterListener.TEST_NAME_KEY).toString(); } List<String> res = new ArrayList<String>(); if (StringUtils.isNotBlank(testName)) { res.add(testName); } SeLionLogger.getLogger().exiting(res); return res; } }
/** * Generate result for a single test method * @param ve velocity engine used to generate file * @param testResult result for this test method */ public JSONObject generateExecutionLogs(final ITestResult testResult) { JSONObject executionLogs = new JSONObject(); executionLogs.put("logs", SeleniumRobotLogger.getTestLogs().get(testResult.getAttribute(SeleniumRobotLogger.UNIQUE_METHOD_NAME))); // exception handling StringBuilder stackString = new StringBuilder(); if (testResult.getThrowable() != null) { generateTheStackTrace(testResult.getThrowable(), testResult.getThrowable().getMessage(), stackString); } executionLogs.put("stacktrace", stackString.toString()); return executionLogs; }
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); } } }
private void onBeforeEvent() { // 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 != videoArtifact.getTestId()) { videoArtifact.setTestId(ztid); LOGGER.debug("Registered recorded video artifact " + videoArtifact.getName() + " into zafira"); ZafiraSingleton.INSTANCE.getClient().addTestArtifact(videoArtifact); } } } }
private void onBeforeEvent() { // 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 != videoArtifact.getTestId()) { videoArtifact.setTestId(ztid); LOGGER.debug("Registered recorded video artifact " + videoArtifact.getName() + " into zafira"); ZafiraSingleton.INSTANCE.getClient().addTestArtifact(videoArtifact); } } }
@Override public void finishTestMethod(String status, ITestResult testResult) { if (Statuses.SKIPPED.equals(status) && !isRetry(testResult) && null == testResult.getAttribute(RP_ID)) { startTestMethod(testResult); } FinishTestItemRQ rq = buildFinishTestMethodRq(status, testResult); launch.get().finishTestItem(this.<Maybe<String>>getAttribute(testResult, RP_ID), rq); }