@Override @SuppressWarnings("rawtypes") public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { // if @Test for test method if (testMethod != null) { // get TestNG Foundation configuration TestNGConfig config = TestNGConfig.getConfig(); // if default test timeout is defined if (config.containsKey(TestNGSettings.TEST_TIMEOUT.key())) { // get default test timeout long defaultTimeout = config.getLong(TestNGSettings.TEST_TIMEOUT.key()); // if current timeout is less than default if (defaultTimeout > annotation.getTimeOut()) { // set test timeout interval annotation.setTimeOut(defaultTimeout); } } } }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { Bug bugAnnotation = testMethod.getAnnotation(Bug.class); if (bugAnnotation != null) { try { MantisConnectLocator mcl = new MantisConnectLocator(); MantisConnectPortType mcp = mcl.getMantisConnectPort( new URL("http://localhost/mantisbt-1.2.17/api/soap/mantisconnect.php")); IssueData issue = mcp.mc_issue_get("administrator", "root", BigInteger.valueOf(bugAnnotation.value())); String status = issue.getStatus().getName(); if (! ("closed".equals(status) || "resolved".equals(status))) { annotation.setEnabled(false); } } catch (Exception e) { e.printStackTrace(); } } }
@Override @SuppressWarnings("rawtypes") public void transform(final ITestAnnotation test, final Class testClass, final Constructor testConstructor, final Method testMethod) { //Set DataProvider for the test if (testMethod != null){ if(dataType(testMethod)!=null) { if(dataType(testMethod).equals(Data.PROPERTIES)) { test.setDataProviderClass(DataSources.class); test.setDataProvider(dataPropertiesSource); } else if(dataType(testMethod).equals(Data.EXCEL)){ test.setDataProviderClass(DataSources.class); test.setDataProvider(dataExcelSource); } } } //Set retry analyzer class for all @Test methods IRetryAnalyzer retry = test.getRetryAnalyzer(); if (retry==null){ test.setRetryAnalyzer(RetryAnalyzer.class); } }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { Ignores ignores = testMethod.getAnnotation(Ignores.class); if (ignores != null) { for (Ignores.Driver ignore : ignores.value()) { if (Browser.CHROME.name().equals(ignore.name())) { annotation.setEnabled(false); } else if (Browser.FIREFOX.name().equals(ignore.name())) { annotation.setEnabled(false); } else if (Browser.IEXPLORE.name().equals(ignore.name())) { annotation.setEnabled(false); } else if ("ALL".equals(ignore.name())) { annotation.setEnabled(false); } } } }
@SuppressWarnings("rawtypes") @Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { IRetryAnalyzer retry = annotation.getRetryAnalyzer(); if (retry == null) { annotation.setRetryAnalyzer(TestngRetry.class); } // 设置 默认循环次数 ConfigUtil property = ConfigUtil.getInstance(); int count = Integer.valueOf(property.getProperty("loopCount")); LogUtil.info("默认每个方法循环" + count + "次"); annotation.setInvocationCount(count); // 设置 需要特殊处理方法的循环次数 String excepLoopCount = property.getProperty("excepLoopCount"); String[] excepCount = excepLoopCount.split(";"); for (int i = 0; i < excepCount.length; i++) { String[] temp = excepCount[i].split(","); if (testMethod.getName().equals(temp[0])) { LogUtil.info("该方法循环" + temp[1] + "次"); annotation.setInvocationCount(Integer.valueOf(temp[1])); } } }
public void transform( ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod ) { annotation.setDependsOnMethods(null); annotation.setDependsOnGroups(null); }
@SuppressWarnings("rawtypes") @Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testCtor, Method testMethod) { if (testClass != null) { xformTest.add("class: " + testClass.getSimpleName()); } else if (testCtor != null) { xformTest.add("ctor: " + testCtor.getName()); } else { xformTest.add("method: " + testMethod.getName()); } }
@SuppressWarnings("rawtypes") public void transform(final ITestAnnotation annotation, final Class testClass, final Constructor testConstructor, final Method testMethod) { final IRetryAnalyzer retry = annotation.getRetryAnalyzer(); if (retry == null) { annotation.setRetryAnalyzer(Retry.class); } }
protected static boolean isEnabled(Method m, IAnnotationFinder finder) { ITestAnnotation annotation = AnnotationHelper.findTest(finder, m); // If no method annotation, look for one on the class if (null == annotation) { annotation = AnnotationHelper.findTest(finder, m.getDeclaringClass()); } return isEnabled(annotation); }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { if (testMethod == null || annotation == null) { return; } String clazzName = testMethod.getDeclaringClass().getName(); exclusions.forEach(s -> { if(s.equals(clazzName)) { annotation.setEnabled(false); } }); }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { IRetryAnalyzer retry = annotation.getRetryAnalyzer(); if (retry == null) { annotation.setRetryAnalyzer(TestngRetry.class); } }
public void transform(final ITestAnnotation annotation, final Class testClass, final Constructor testConstructor, final Method testMethod) { IRetryAnalyzer retryAnalyzer = annotation.getRetryAnalyzer(); if (retryAnalyzer == null) { annotation.setRetryAnalyzer(TestRetryAnalyzer.class); } }
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { IRetryAnalyzer analyzer = annotation.getRetryAnalyzer(); if (analyzer == null) { annotation.setRetryAnalyzer(FailedTestsRetryListner.class); } }
@Override public void transform(ITestAnnotation iTestAnnotation, Class aClass, Constructor constructor, Method method) { IRetryAnalyzer retry = iTestAnnotation.getRetryAnalyzer(); if (retry == null) { iTestAnnotation.setRetryAnalyzer(Retry.class); } }
@SuppressWarnings("rawtypes") public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { if (performanceTestMethod != null && performanceTestMethod.equalsIgnoreCase(testMethod.getName())) { annotation.setThreadPoolSize(threadPoolSize); annotation.setInvocationCount(threadPoolSize); } }
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor constructor, Method method) { IRetryAnalyzer retry = annotation.getRetryAnalyzer(); if(retry == null) { annotation.setRetryAnalyzer(RetryFailed.class); } }
@Override @SuppressWarnings("rawtypes") public void transform( ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { if (testMethod == null) { return; } String className = testMethod.getDeclaringClass().getName(); String methodName = testMethod.getName(); TestDescription description = new TestDescription(className, methodName); TestSelector matchingSelector = testSelectorList.findSelector(description); if (!matchingSelector.isInclusive()) { // For tests that have been filtered out, record it now and don't run it if (shouldExplainTestSelectors) { String reason = "Excluded by filter: " + matchingSelector.getExplanation(); results.add(TestResult.forExcluded(className, methodName, reason)); } annotation.setEnabled(false); return; } if (!annotation.getEnabled()) { // on a dry run, have to record it now -- since it doesn't run, listener can't do it results.add(TestResult.forDisabled(className, methodName)); return; } if (isDryRun) { // on a dry run, record it now and don't run it results.add(TestResult.forDryRun(className, methodName)); annotation.setEnabled(false); return; } }
@SuppressWarnings("rawtypes") @Override public void transform(ITestAnnotation testAnnotation, Class clazz, Constructor test, Method method) { IRetryAnalyzer retry = testAnnotation.getRetryAnalyzer(); if (retry == null) { testAnnotation.setRetryAnalyzer(RetryAnalyzer.class); } LOGGER.debug("retry analyzer: " + method.getName() + testAnnotation.getRetryAnalyzer()); }
protected static boolean isEnabled(Class<?> objectClass, IAnnotationFinder finder) { ITestAnnotation testClassAnnotation = AnnotationHelper.findTest(finder, objectClass); return isEnabled(testClassAnnotation); }
@Override public void transform( ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {}
@Override public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) { ensureAnnotationIsOnlyOnTestMethod(testClass, testConstructor, testMethod); }