@Test(dependsOnMethods = "f1") public void f2(ITestContext ctx) { Set<String> names = ctx.getAttributeNames(); assertThat(names).hasSize(1); assertThat(names).contains("test2"); assertThat(ctx.getAttribute("test2")).isEqualTo("2"); } }
public static int getMethodsCountFromContext(ITestContext context) { return (int) context.getAttribute(METHODS_COUNT_KEY); }
@Test public void getvaluetest(ITestContext context) { String id = context.getAttribute("customerId"); }
@Test public void f1(ITestContext ctx) { Set<String> names = ctx.getAttributeNames(); assertThat(names).hasSize(1); assertThat(names).contains("test"); assertThat(ctx.getAttribute("test")).isEqualTo("1"); Object v = ctx.removeAttribute("test"); assertThat(v).isNotNull(); ctx.setAttribute("test2", "2"); }
public static int getMethodsCountFromContext(ITestContext context) { return (int) context.getAttribute(METHODS_COUNT_KEY); }
private List<ITestResult> getList(String listName, ITestContext context) { List<ITestResult> outputList = new ArrayList(); if (context.getAttributeNames().contains(listName)) { outputList = (List<ITestResult>) context.getAttribute(listName); } return outputList; }
@BeforeClass public void setup(ITestContext context) { this.testContext = context; selenium = (Selenium) context.getAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE); baseURL = (String) context.getAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE); errorReporter = (ErrorReporter) context.getAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE); }
private List<ITestResult> getList(String listName, ITestContext context) { List<ITestResult> outputList = new ArrayList(); if (context.getAttributeNames().contains(listName)) { outputList = (List<ITestResult>) context.getAttribute(listName); } return outputList; }
public class SuiteOneCaseOne extends SuiteOneBase { @BeforeTest public void checkCaseToRun(ITestContext context) throws IOException { boolean suiteResult = context.getAttribute("suiteResult"); System.out.println("suiteResult "+suiteResult ); // [...] } }
@Test(dependsOnMethods = {"testOne"}) public void testTwo(ITestContext ctx) { System.out.println(ctx.getAttribute("waterfallId")); //returns null }
@BeforeClass public void setup(ITestContext context) { this.testContext = context; selenium = (Selenium) context.getAttribute(TapestryTestConstants.SELENIUM_ATTRIBUTE); webDriver = ((WrapsDriver) selenium).getWrappedDriver(); baseURL = (String) context.getAttribute(TapestryTestConstants.BASE_URL_ATTRIBUTE); errorReporter = (ErrorReporter) context.getAttribute(TapestryTestConstants.ERROR_REPORTER_ATTRIBUTE); }
/** * Package private. Used in unit test. * * @return UID for the current suite */ String getSuiteUid(ITestContext iTestContext) { String uid; if (iTestContext.getAttribute(SUITE_UID) != null) { uid = (String) iTestContext.getAttribute(SUITE_UID); } else { uid = UUID.randomUUID().toString(); iTestContext.setAttribute(SUITE_UID, uid); } return uid; }
public void onFinish(ITestContext context) { JettyHttpServer httpServer = (JettyHttpServer)context.getAttribute(JETTY_SERVER); if (httpServer != null) { try { httpServer.stop(); httpServer = null; } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); throw new RuntimeException(e.getLocalizedMessage(), e); } } }
@SuppressWarnings("unchecked") public static Object[][] getNeedRerunDataProvider(Annotation[] annotations, ITestContext context, ITestNGMethod m) { Object[][] dp = getDataProvider(annotations, context, m); List<String> doNotRunRowIDs = (List<String>) context.getAttribute(SpecialKeywords.DO_NOT_RUN_TESTS); Map<String, String> testNameArgsMap = (Map<String, String>) context.getAttribute(SpecialKeywords.CANONICAL_TEST_NAME_ARGS_MAP); if (!doNotRunRowIDs.isEmpty()) { for (int i = dp.length - 1; i >= 0; i--) { String testUniqueName = testNameArgsMap.get(testNameArgsMap.keySet().toArray()[i]); if (testUniqueName != null) { if (doNotRunRowIDs.contains(testUniqueName)) { dp = ArrayUtils.remove(dp, i); } } } } return dp; }
public static String getCanonicalTestMethodName(ITestResult result) { String testMethodName = result.getMethod().getMethodName(); // TODO: remove test method name map as soon as possible @SuppressWarnings("unchecked") Map<Object[], String> testMethodNameMap = (Map<Object[], String>) result.getTestContext() .getAttribute(SpecialKeywords.TEST_METHOD_NAME_ARGS_MAP); if (testMethodNameMap != null) { String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); if (testMethodNameMap.containsKey(testHash)) { LOGGER.error("Error message to check how often this feature is used."); testMethodName = testMethodNameMap.get(testHash); } } return StringEscapeUtils.escapeHtml4(testMethodName); }
public static String getCanonicalTestMethodName(ITestResult result) { String testMethodName = result.getMethod().getMethodName(); // TODO: remove test method name map as soon as possible @SuppressWarnings("unchecked") Map<Object[], String> testMethodNameMap = (Map<Object[], String>) result.getTestContext() .getAttribute(SpecialKeywords.TEST_METHOD_NAME_ARGS_MAP); if (testMethodNameMap != null) { String testHash = String.valueOf(Arrays.hashCode(result.getParameters())); if (testMethodNameMap.containsKey(testHash)) { LOGGER.error("Error message to check how often this feature is used."); testMethodName = testMethodNameMap.get(testHash); } } return StringEscapeUtils.escapeHtml4(testMethodName); }
@AfterMethod public void endTest(Method testMethod, ITestContext testContext) { Long startTime = (Long) testContext.getAttribute("StartTime"); long endTime = System.currentTimeMillis(); System.out.println("END " + testMethod.getName() + " at " + new Date(endTime) + ", took: " + (endTime - startTime) + "ms."); }
@AfterMethod public void endTest(Method testMethod, ITestContext testContext) { Long startTime = (Long) testContext.getAttribute("StartTime"); long endTime = System.currentTimeMillis(); System.out.println( "END " + testMethod.getName() + " at " + new Date(endTime) + ", took: " + (endTime - startTime) + "ms."); }
@Test public void command_processor_available(ITestContext context) { assertNotNull(context.getAttribute(TapestryTestConstants.COMMAND_PROCESSOR_ATTRIBUTE)); }
/** * Elaboration of test case parameters before any request (method executed as first step in the runner). * @param testCaseParams Map containing test case parameters coming from the json input file * @return the same structure as the input parameters but with placeholders resolved */ @Override public Map resolvePlaceholdersInTcParams(Map<String, Object> testCaseParams, List<String> paramsToSkip) { TestSuiteHandler testSuiteHandler = TestSuiteHandler.getInstance(); testSuiteHandler.getLogUtils().setTestCaseId(testContext.getAttribute(ATTR_TESTCASE_ID).toString()); // now we start elaborating the parameters. placeholderHandler = new PlaceholderHandler(); placeholderHandler.setPreloadedVariables(testSuiteHandler.getTestCaseUtils().getBeforeSuiteVariables()); TestCaseMapHandler tcMapHandler = new TestCaseMapHandler(testCaseParams, placeholderHandler, paramsToSkip); return tcMapHandler.retrieveProcessedMap(); }