public void onTestStart(ITestResult result) { ITestContext context = result.getTestContext(); if (context != null) { contextProvided = true; } }
protected static void invokeWithTimeout(ITestNGMethod tm, Object instance, Object[] parameterValues, ITestResult testResult, IHookable hookable) throws InterruptedException, ThreadExecutionException { if (ThreadUtil.isTestNGThread() && testResult.getTestContext().getCurrentXmlTest().getParallel() != XmlSuite.ParallelMode.TESTS) { // We are already running in our own executor, don't create another one (or we will // lose the time out of the enclosing executor). invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable); } else { invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult, hookable); } }
@Override public void onConfigurationSuccess(ITestResult itr) { String xmlTestName = itr.getTestContext().getCurrentXmlTest().getName(); Integer count = CALLS.get(xmlTestName); if (count == null) { count = 0; } count++; CALLS.put(xmlTestName, count); }
protected static void invokeWithTimeout( ITestNGMethod tm, Object instance, Object[] parameterValues, ITestResult testResult, IHookable hookable) throws InterruptedException, ThreadExecutionException { if (ThreadUtil.isTestNGThread() && testResult.getTestContext().getCurrentXmlTest().getParallel() != XmlSuite.ParallelMode.TESTS) { // We are already running in our own executor, don't create another one (or we will // lose the time out of the enclosing executor). invokeWithTimeoutWithNoExecutor(tm, instance, parameterValues, testResult, hookable); } else { invokeWithTimeoutWithNewExecutor(tm, instance, parameterValues, testResult, hookable); } }
private TestNgRunStateTracker.EventLogBuilder buildEventLog(ITestResult result, TestNgRunEvent event) { return(buildEventLog(result.getTestContext(), event)) .addData(METHOD_NAME, result.getMethod().getMethodName()) .addData(CLASS_NAME, result.getMethod().getRealClass().getCanonicalName()) .addData(CLASS_INSTANCE, result.getMethod().getInstance()) .addData(GROUPS_DEPENDED_ON, result.getMethod().getGroupsDependedUpon()) .addData(METHODS_DEPENDED_ON, result.getMethod().getMethodsDependedUpon()) .addData(GROUPS_BELONGING_TO, result.getMethod().getGroups()); }
@Override public void onTestFailure(ITestResult result) { Object webDriverAttribute = result.getTestContext().getAttribute("WebDriver"); // test, cast, and use...
private String getCurrentSuitePrefix(ITestResult iTestResult) { return "{" + getCurrentSuiteTitle(iTestResult.getTestContext()) + "}"; }
@Override public void onTestStart(ITestResult testCase) { testStartTime = currentTimeMillis(); started++; int total = getMethodsCountFromContext(testCase.getTestContext()); LOGGER.info("[{} of {}] {}", started, total, formatTestName(testCase)); }
@Override public void onTestStart(ITestResult testCase) { testStartTime = currentTimeMillis(); started++; int total = getMethodsCountFromContext(testCase.getTestContext()); LOGGER.info("[{} of {}] {}", started, total, formatTestName(testCase)); }
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); }
private void closeDriverIfRunningInParallel(ITestResult result) { ITestContext testContext = result.getTestContext(); if (getDriver() == null) { getLogger().debug("No WebDriver to close for thread " + Thread.currentThread().getName()); } else if (isRunningTestsInSeparateThreads(testContext)) { getLogger().info("Closing WebDriver for thread " + Thread.currentThread().getName() + " on host '" + testContext.getSuite().getHost() + "'"); closeDriver(); } else { getLogger().debug("Reusing WebDriver for thread " + Thread.currentThread().getName()); } }
private void closeDriverIfRunningInParallel(ITestResult result) { ITestContext testContext = result.getTestContext(); if (getDriver() == null) { getLogger().debug("No WebDriver to close for thread " + Thread.currentThread().getName()); } else if (isRunningTestsInSeparateThreads(testContext)) { getLogger().info("Closing WebDriver for thread " + Thread.currentThread().getName() + " on host '" + testContext.getSuite().getHost() + "'"); closeDriver(); } else { getLogger().debug("Reusing WebDriver for thread " + Thread.currentThread().getName()); } }
public boolean shouldIntercept(ITestResult result) { List<String> listeners = result.getTestContext().getCurrentXmlTest().getSuite().getListeners(); return listeners.contains(this.getClass().getName()) || shouldIntercept(result.getTestClass().getRealClass(), this.getClass()); }
@Override public void beforeConfiguration(ITestResult result) { // startItem(result, Messager.CONFIG_STARTED); // // do failure test cleanup in this place as right after the test // // context doesn't have up-to-date information. // // This context cleanup is required to launch dependent steps if parent method pass from Nth retry! removeIncorrectlyFailedTests(result.getTestContext()); // added 3 below lines to be able to track log/screenshots for before suite/class/method actions too TestNamingUtil.releaseTestInfoByThread(); super.beforeConfiguration(result); }
/** * Calculate parent id for configuration */ @VisibleForTesting Maybe<String> getConfigParent(ITestResult testResult, TestMethodType type) { Maybe<String> parentId; if (TestMethodType.BEFORE_SUITE.equals(type) || TestMethodType.AFTER_SUITE.equals(type)) { parentId = getAttribute(testResult.getTestContext().getSuite(), RP_ID); } else { parentId = getAttribute(testResult.getTestContext(), RP_ID); } return parentId; }
private String failRetryItem(ITestResult result, Messager messager, int count, int maxCount) { String test = TestNamingUtil.getCanonicalTestName(result); String errorMessage = getFailureReason(result); takeScreenshot(result, "TEST FAILED - " + errorMessage); String deviceName = getDeviceName(); messager.info(deviceName, test, String.valueOf(count), String.valueOf(maxCount), errorMessage); result.getTestContext().removeAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE); return errorMessage; }
@Override public void startTestMethod(ITestResult testResult) { StartTestItemRQ rq = buildStartStepRq(testResult); if (rq == null) { return; } Maybe<String> stepMaybe = launch.get().startTestItem(this.<Maybe<String>>getAttribute(testResult.getTestContext(), RP_ID), rq); testResult.setAttribute(RP_ID, stepMaybe); }
@Override public void onTestStart(ITestResult result) { TestPhase.setActivePhase(Phase.METHOD); // handle expected skip Method testMethod = result.getMethod().getConstructorOrMethod().getMethod(); if (ExpectedSkipManager.getInstance().isSkip(testMethod, result.getTestContext())) { skipExecution("Based on rule listed above"); } super.onTestStart(result); }
private void passItem(ITestResult result, Messager messager) { String test = TestNamingUtil.getCanonicalTestName(result); String deviceName = getDeviceName(); messager.info(deviceName, test, DateUtils.now()); EmailReportItemCollector .push(createTestResult(result, TestResultType.PASS, null, result.getMethod().getDescription())); result.getTestContext().removeAttribute(SpecialKeywords.TEST_FAILURE_MESSAGE); }
private void createConfigEvent(ITestResult iTestResult) { String description = iTestResult.getMethod().getDescription(); if (description == null || description.isEmpty()) { description = getConfigMethodType(iTestResult).getName(); } String suiteUid = getSuiteUid(iTestResult.getTestContext()); TestCaseStartedEvent event = new TestCaseStartedEvent(suiteUid, iTestResult.getName()); event.setDescription(new Description().withValue(description)); AnnotationManager am = new AnnotationManager(getMethodAnnotations(iTestResult)); am.setDefaults(getClassAnnotations(iTestResult)); am.update(event); getLifecycle().fire(event); }