@BeforeClass public void bc(ITestContext ctx) { ctx.setAttribute("test", "1"); }
@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 class SuiteOneBase extends SuiteBase { @BeforeSuite public void checkSuiteToRun(ITestContext context) throws IOException { // [...] boolean suiteResult = SuiteUtility.checkToRunUtility(FilePath, SheetName,ToRunColumnName,SuiteName); // [...] context.setAttribute("suiteResult", suiteResult); } }
@Test public void setvaluetest(ITestContext context) { String customerId = "GDFg34fDF"; context.setAttribute("customerId", customerId); }
public class Setup { @Inject WebDriver driver; @BeforeSuite public void onStart(ITestContext testContext) { testContext.setAttribute("WebDriver", this.driver); } }
@AfterMethod public void cleanupTestMethod() { testContext.setAttribute(TapestryTestConstants.CURRENT_TEST_METHOD_ATTRIBUTE, null); }
@AfterMethod public void cleanupTestMethod() { testContext.setAttribute(TapestryTestConstants.CURRENT_TEST_METHOD_ATTRIBUTE, null); }
@BeforeMethod public void indicateTestMethodName(Method testMethod) { LOGGER.info("Executing " + testMethod); testContext.setAttribute(TapestryTestConstants.CURRENT_TEST_METHOD_ATTRIBUTE, testMethod); String className = testMethod.getDeclaringClass().getSimpleName(); String testName = testMethod.getName().replace("_", " "); selenium.setContext(className + ": " + testName); }
@BeforeMethod public void indicateTestMethodName(Method testMethod) { LOGGER.info("Executing " + testMethod); testContext.setAttribute(TapestryTestConstants.CURRENT_TEST_METHOD_ATTRIBUTE, testMethod); String className = testMethod.getDeclaringClass().getSimpleName(); String testName = testMethod.getName().replace("_", " "); selenium.setContext(className + ": " + testName); }
/** * Method to set useful parameters in the context managed by testNG. * Parameters that will be set will be: 'testId', 'suiteDescription', 'tcDescription' * @param testCaseParams Map containing test case parameters coming from the json input file */ public void setContextAttributes(Map<String, Object> testCaseParams) { String testCaseID = testCaseParams.get(ATTR_TESTCASE_ID).toString(); testContext.setAttribute(ATTR_TESTCASE_ID, testCaseID); String suiteDescription = TestSuiteHandler.getInstance().getTestCaseUtils().getSuiteDescription(); testContext.setAttribute(SUITE_DESCRIPTION_CTX_ATTR, suiteDescription); String testCaseDesc = testCaseParams.get(ATTR_TESTCASE_NAME).toString(); testContext.setAttribute(TC_DESCRIPTION_CTX_ATTR, testCaseDesc); }
/** * Method to set useful parameters in the context managed by testNG. * Parameters that will be set will be: 'testId', 'suiteDescription', 'tcDescription' * @param testCaseParams Map containing test case parameters coming from the json input file */ public void setContextAttributes(Map<String, Object> testCaseParams) { String testCaseID = testCaseParams.get(ATTR_TESTCASE_ID).toString(); testContext.setAttribute(ATTR_TESTCASE_ID, testCaseID); String suiteDescription = TestSuiteHandler.getInstance().getTestCaseUtils().getSuiteDescription(); testContext.setAttribute(SUITE_DESCRIPTION_CTX_ATTR, suiteDescription); String testCaseDesc = testCaseParams.get(ATTR_TESTCASE_NAME).toString(); testContext.setAttribute(TC_DESCRIPTION_CTX_ATTR, testCaseDesc); }
@Override public void onStart(ITestContext testContext) { String testName = testContext.getCurrentXmlTest().getName(); MDC.put("testName", testName); List<ITestResult> localSkippedTests = new ArrayList(); testContext.setAttribute(SKIPPED_TEST_CASES, localSkippedTests); }
@Override public void onStart(ITestContext testContext) { String testName = testContext.getCurrentXmlTest().getName(); MDC.put("testName", testName); List<ITestResult> localSkippedTests = new ArrayList(); testContext.setAttribute(SKIPPED_TEST_CASES, localSkippedTests); }
/** * 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; }
@BeforeMethod public void beforeTest(Method testMethod, ITestContext testContext){ long startTime = System.currentTimeMillis(); System.out.println("START " + testMethod.getName() + " at " + new Date(startTime)); testContext.setAttribute("StartTime", System.currentTimeMillis()); }
@Override public synchronized List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) { /* * For some unknown reason TestNG calls method interceptors more than once for * same methods set. We determine if we already seen method by looking at type of internal TestNGMethod field. */ List<IMethodInstance> allExpandedMethods = Lists.newArrayList(); for (IMethodInstance method : methods) { if (isMethodAlreadyExpanded(method)) { allExpandedMethods.add(method); } else { List<IMethodInstance> newExpandedMethods = expandMethod(method); incrementSeenMethodsCount(newExpandedMethods); allExpandedMethods.addAll(newExpandedMethods); } } context.setAttribute(METHODS_COUNT_KEY, seenMethodsCount); return allExpandedMethods; }
@BeforeMethod public void beforeTest(Method testMethod, ITestContext testContext){ long startTime = System.currentTimeMillis(); System.out.println("START " + testMethod.getName() + " at " + new Date(startTime)); testContext.setAttribute("StartTime", System.currentTimeMillis()); setup(); }
public void onStart(ITestContext context) { ITestNGMethod[] allTestMethods = context.getAllTestMethods(); if (allTestMethods == null) { return; } if (httpServer == null && hasEverrestJettyListenerTestHierarchy(allTestMethods)) { httpServer = new JettyHttpServer(); context.setAttribute(JETTY_PORT, httpServer.getPort()); context.setAttribute(JETTY_SERVER, httpServer); try { httpServer.start(); httpServer.resetFactories(); httpServer.resetFilter(); RestAssured.port = httpServer.getPort(); RestAssured.basePath = JettyHttpServer.UNSECURE_REST; } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); throw new RuntimeException(e.getLocalizedMessage(), e); } } }
@Override public void startTest(ITestContext testContext) { if (hasMethodsToRun(testContext)) { StartTestItemRQ rq = buildStartTestItemRq(testContext); final Maybe<String> testID = launch.get().startTestItem(this.<Maybe<String>>getAttribute(testContext.getSuite(), RP_ID), rq); testContext.setAttribute(RP_ID, testID); } }
protected String getFailureReason(ITestResult result) { String errorMessage = ""; String message = ""; if (result.getThrowable() != null) { Throwable thr = result.getThrowable(); errorMessage = getFullStackTrace(thr); message = thr.getMessage(); result.getTestContext().setAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE, message); } // handle in case of failed config (exclusion of expected skip) if (errorMessage.isEmpty()) { String methodName; Collection<ITestResult> results = result.getTestContext().getSkippedConfigurations().getAllResults(); for (ITestResult resultItem : results) { methodName = resultItem.getMethod().getMethodName(); if (methodName.equals(SpecialKeywords.BEFORE_TEST_METHOD)) { errorMessage = getFullStackTrace(resultItem.getThrowable()); } } } return errorMessage; }