org.testng.xml.XmlTest Java Examples
The following examples show how to use
org.testng.xml.XmlTest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AllureTestListenerTest.java From allure1 with Apache License 2.0 | 6 votes |
@Before public void setUp() { testngListener = spy(new AllureTestListener()); allure = mock(Allure.class); testngListener.setLifecycle(allure); ISuite suite = mock(ISuite.class); when(suite.getName()).thenReturn(DEFAULT_SUITE_NAME); XmlTest xmlTest = mock(XmlTest.class); when(xmlTest.getName()).thenReturn(DEFAULT_XML_TEST_NAME); testContext = mock(ITestContext.class); when(testContext.getSuite()).thenReturn(suite); when(testContext.getCurrentXmlTest()).thenReturn(xmlTest); // mocking test method parameters ConstructorOrMethod constructorOrMethod = mock(ConstructorOrMethod.class); when(constructorOrMethod.getMethod()).thenReturn(parametrizedTestMethod(0, null, null, null)); method = mock(ITestNGMethod.class); when(method.getConstructorOrMethod()).thenReturn(constructorOrMethod); testResult = mock(ITestResult.class); when(testResult.getMethod()).thenReturn(method); when(testResult.getParameters()).thenReturn(new Object[]{}); IClass iClass = mock(IClass.class); when(testResult.getTestClass()).thenReturn(iClass); }
Example #2
Source File: SuiteAlterer.java From Quantum with MIT License | 6 votes |
public List<String> getTestNameList(List<XmlTest> originalTest) { List<String> hasParams = new ArrayList<String>(); for (int z = 0; z < originalTest.size(); z++) { Map<String, String> testPars = originalTest.get(z).getParameters(); Iterator it2 = testPars.entrySet().iterator(); while (it2.hasNext()) { Map.Entry pair = (Map.Entry) it2.next(); if (pair.getKey().toString().equals("csvParams")) { hasParams.add(originalTest.get(z).getName()); } } } return hasParams; }
Example #3
Source File: MetaDataScanner.java From qaf with MIT License | 6 votes |
/** * * @param xmlTest * @param parameter * @return */ public static String getParameter(XmlTest xmlTest, String parameter) { String paramValue = ""; boolean overrideUsingSystemProp = System.getProperties().containsKey(parameter); Map<String, String> context = xmlTest.getAllParameters(); context.keySet().removeAll(System.getProperties().keySet()); if (overrideUsingSystemProp) { paramValue = System.getProperty(parameter); } else if (context.containsKey(parameter)) { paramValue = context.get(parameter); } else if (getBundle().containsKey(parameter)) { try { // unresolved value paramValue = (String) getBundle().configurationAt(parameter).getRoot().getValue(); } catch (Exception e) { paramValue = getBundle().getString(parameter, ""); } } paramValue = StrSubstitutor.replace(paramValue, context); paramValue = getBundle().getSubstitutor().replace(paramValue); return paramValue; }
Example #4
Source File: BaseTest.java From video-recorder-java with MIT License | 6 votes |
protected ITestResult prepareMock(Class<?> tClass, Method method) { ITestResult result = mock(ITestResult.class); IClass clazz = mock(IClass.class); ITestNGMethod testNGMethod = mock(ITestNGMethod.class); ConstructorOrMethod cm = mock(ConstructorOrMethod.class); String methodName = method.getName(); when(result.getTestClass()).thenReturn(clazz); when(result.getTestClass().getRealClass()).thenReturn(tClass); when(clazz.getName()).thenReturn(this.getClass().getName()); when(result.getMethod()).thenReturn(testNGMethod); when(cm.getMethod()).thenReturn(method); when(result.getMethod().getConstructorOrMethod()).thenReturn(cm); when(testNGMethod.getMethodName()).thenReturn(methodName); ITestContext context = mock(ITestContext.class); when(result.getTestContext()).thenReturn(context); XmlTest xmlTest = new XmlTest(); XmlSuite suite = new XmlSuite(); xmlTest.setXmlSuite(suite); suite.setListeners(Arrays.asList(VideoListener.class.getName())); when(context.getCurrentXmlTest()).thenReturn(xmlTest); return result; }
Example #5
Source File: AllureTestListenerTest.java From allure1 with Apache License 2.0 | 6 votes |
@Test public void currentSuiteTitleTest() throws Exception { Map<String, String> params = new HashMap<>(); params.put("key", "value"); XmlTest xmlTest = mock(XmlTest.class); when(xmlTest.getLocalParameters()).thenReturn(params); when(xmlTest.getName()).thenReturn("xmlName"); ITestContext iTestContext = mock(ITestContext.class); when(iTestContext.getCurrentXmlTest()).thenReturn(xmlTest); ISuite iSuite = mock(ISuite.class); when(iSuite.getName()).thenReturn("name"); when(iTestContext.getSuite()).thenReturn(iSuite); String name = testngListener.getCurrentSuiteTitle(iTestContext); assertThat(name, is("name : xmlName[key=value]")); }
Example #6
Source File: TestRunner.java From qaf with MIT License | 6 votes |
/** * The main entry method for TestRunner. * * This is where all the hard work is done: * - Invoke configuration methods * - Invoke test methods * - Catch exceptions * - Collect results * - Invoke listeners * - etc... */ public void run() { beforeRun(); try { XmlTest test= getTest(); if(test.isJUnit()) { privateRunJUnit(test); } else { privateRun(test); } } finally { afterRun(); } }
Example #7
Source File: TestRunner.java From qaf with MIT License | 6 votes |
private void initRunInfo(final XmlTest xmlTest) { // Groups m_xmlMethodSelector.setIncludedGroups(createGroups(m_xmlTest.getIncludedGroups())); m_xmlMethodSelector.setExcludedGroups(createGroups(m_xmlTest.getExcludedGroups())); m_xmlMethodSelector.setExpression(m_xmlTest.getExpression()); // Methods m_xmlMethodSelector.setXmlClasses(m_xmlTest.getXmlClasses()); m_runInfo.addMethodSelector(m_xmlMethodSelector, 10); // Add user-specified method selectors (only class selectors, we can ignore // script selectors here) if (null != xmlTest.getMethodSelectors()) { for (org.testng.xml.XmlMethodSelector selector : xmlTest.getMethodSelectors()) { if (selector.getClassName() != null) { IMethodSelector s = ClassHelper.createSelector(selector); m_runInfo.addMethodSelector(s, selector.getPriority()); } } } }
Example #8
Source File: EarlReporter.java From teamengine with Apache License 2.0 | 6 votes |
/** * Adds the list of conformance classes to the TestRun resource. A * conformance class corresponds to a {@literal <test>} tag in the TestNG * suite definition; it is represented as an earl:TestRequirement resource. * * @param earl * An RDF model containing EARL statements. * @param testList * The list of test sets comprising the test suite. */ void addTestRequirements(Model earl, final List<XmlTest> testList) { Seq reqs = earl.createSeq(); String key = null; for (XmlTest xmlTest : testList) { String testName = xmlTest.getName(); Resource testReq = earl.createResource(testName.replaceAll("\\s", "-"), EARL.TestRequirement); testReq.addProperty(DCTerms.title, testName); String testOptionality = xmlTest.getParameter(CITE.CC_OPTIONALITY); if (null != testOptionality && !testOptionality.isEmpty()) { testReq.addProperty(CITE.optionality, testOptionality); } if (isBasicConformanceClass(testName)) { testReq.addProperty(CITE.isBasic, "true"); } reqs.add(testReq); } this.testRun.addProperty(CITE.requirements, reqs); }
Example #9
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 6 votes |
public XmlSuite constructXmlSuiteForDistribution(List<String> tests, Map<String, List<Method>> methods, String suiteName, String category, int deviceCount) { XmlSuite suite = new XmlSuite(); suite.setName(suiteName); suite.setThreadCount(deviceCount); suite.setParallel(ParallelMode.CLASSES); suite.setVerbose(2); listeners.add("com.appium.manager.AppiumParallelMethodTestListener"); listeners.add("com.appium.utils.RetryListener"); include(listeners, LISTENERS); suite.setListeners(listeners); XmlTest test = new XmlTest(suite); test.setName(category); test.addParameter("device", ""); include(groupsExclude, EXCLUDE_GROUPS); include(groupsInclude, INCLUDE_GROUPS); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); List<XmlClass> xmlClasses = writeXmlClass(tests, methods); test.setXmlClasses(xmlClasses); writeTestNGFile(suite); return suite; }
Example #10
Source File: TestClass.java From qaf with MIT License | 6 votes |
private void init(IClass cls, ITestMethodFinder testMethodFinder, IAnnotationFinder annotationFinder, RunInfo runInfo, XmlTest xmlTest, XmlClass xmlClass) { log(3, "Creating TestClass for " + cls); m_iClass = cls; m_testClass = cls.getRealClass(); m_xmlTest = xmlTest; m_xmlClass = xmlClass; m_runInfo = runInfo; m_testMethodFinder = testMethodFinder; m_annotationFinder = annotationFinder; initTestClassesAndInstances(); initMethods(); }
Example #11
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 6 votes |
public XmlSuite constructXmlSuiteForParallelCucumber( int deviceCount, List<AppiumDevice> deviceSerail) { ArrayList<String> listeners = new ArrayList<>(); listeners.add("com.cucumber.listener.CucumberListener"); XmlSuite suite = new XmlSuite(); suite.setName("TestNG Forum"); suite.setThreadCount(deviceCount); suite.setParallel(ParallelMode.TESTS); suite.setVerbose(2); suite.setListeners(listeners); for (int i = 0; i < deviceCount; i++) { XmlTest test = new XmlTest(suite); test.setName("TestNG Test" + i); test.setPreserveOrder(false); test.addParameter("device", deviceSerail.get(i).getDevice().getUdid()); test.setPackages(getPackages()); } return getXmlSuite(suite); }
Example #12
Source File: ArkTestNGAlterSuiteListener.java From sofa-ark with Apache License 2.0 | 6 votes |
protected void resetSingleXmlSuite(XmlSuite suite) { for (XmlTest xmlTest : suite.getTests()) { for (XmlClass xmlClass : xmlTest.getClasses()) { Class testClass = xmlClass.getSupportClass(); if (testClass.getAnnotation(TestNGOnArk.class) != null) { if (!DelegateArkContainer.isStarted()) { DelegateArkContainer.launch(testClass); } try { xmlClass.setClass(DelegateArkContainer.getTestClassLoader().loadClass( testClass.getCanonicalName())); } catch (ClassNotFoundException ex) { throw new ArkRuntimeException(String.format( "Load testNG test class %s failed.", testClass.getCanonicalName()), ex); } } } } }
Example #13
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
public XmlSuite constructXmlSuiteForParallel(String pack, List<String> testcases, Map<String, List<Method>> methods, String suiteName, String category, int deviceCount, List<AppiumDevice> deviceSerail) { ArrayList<String> listeners = new ArrayList<>(); listeners.add("com.appium.manager.AppiumParallelTestListener"); listeners.add("com.appium.utils.RetryListener"); include(listeners, LISTENERS); include(groupsInclude, INCLUDE_GROUPS); include(groupsExclude, EXCLUDE_GROUPS); XmlSuite suite = new XmlSuite(); suite.setName(suiteName); suite.setThreadCount(deviceCount); suite.setDataProviderThreadCount(deviceCount); suite.setParallel(ParallelMode.TESTS); suite.setVerbose(2); suite.setListeners(listeners); for (int i = 0; i < deviceCount; i++) { XmlTest test = new XmlTest(suite); test.setName(category + "-" + i); test.setPreserveOrder(false); test.addParameter("device", deviceSerail.get(i).getDevice().getUdid()); test.addParameter("hostName", deviceSerail.get(i).getHostName()); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); List<XmlClass> xmlClasses = writeXmlClass(testcases, methods); test.setXmlClasses(xmlClasses); } writeTestNGFile(suite); return suite; }
Example #14
Source File: MultiSuiteTest.java From sofa-ark with Apache License 2.0 | 5 votes |
protected List<XmlTest> generateXmlTest(Class testClass) { XmlTest xmlTest = new XmlTest(); XmlClass xmlClass = new XmlClass(); xmlClass.setClass(testClass); xmlTest.setClasses(Collections.singletonList(xmlClass)); return Collections.singletonList(xmlTest); }
Example #15
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
public XmlSuite constructXmlSuiteForDistributionMethods(List<String> tests, Map<String, List<Method>> methods, String suiteName, String category, int deviceCount) { include(groupsInclude, INCLUDE_GROUPS); XmlSuite suite = new XmlSuite(); suite.setName(suiteName); suite.setThreadCount(deviceCount); suite.setDataProviderThreadCount(deviceCount); suite.setVerbose(2); suite.setParallel(ParallelMode.METHODS); listeners.add("com.appium.manager.AppiumParallelMethodTestListener"); listeners.add("com.appium.utils.RetryListener"); include(listeners, LISTENERS); suite.setListeners(listeners); CreateGroups createGroups = new CreateGroups(tests, methods, category, suite).invoke(); List<XmlClass> xmlClasses = createGroups.getXmlClasses(); XmlTest test = createGroups.getTest(); List<XmlClass> writeXml = createGroups.getWriteXml(); for (XmlClass xmlClass : xmlClasses) { writeXml.add(new XmlClass(xmlClass.getName())); test.setClasses(writeXml); } writeTestNGFile(suite); return suite; }
Example #16
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
public XmlSuite constructXmlSuiteDistributeCucumber(int deviceCount) { ArrayList<String> listeners = new ArrayList<>(); listeners.add("com.cucumber.listener.CucumberListener"); XmlSuite suite = new XmlSuite(); suite.setName("TestNG Forum"); suite.setThreadCount(deviceCount); suite.setParallel(ParallelMode.CLASSES); suite.setVerbose(2); suite.setListeners(listeners); XmlTest test = new XmlTest(suite); test.setName("TestNG Test"); test.addParameter("device", ""); test.setPackages(getPackages()); return getXmlSuite(suite); }
Example #17
Source File: SeleniumTestsContextManager.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
public static void initTestLevelContext(final ITestContext testNGCtx, final XmlTest xmlTest) { SeleniumTestsContext seleniumTestsCtx = new SeleniumTestsContext(testNGCtx); if (xmlTest != null) { Map<String, String> testParameters = xmlTest.getTestParameters(); // parse the test level parameters for (Entry<String, String> entry : testParameters.entrySet()) { seleniumTestsCtx.setAttribute(entry.getKey(), entry.getValue()); } } testLevelContext.put(xmlTest.getName(), seleniumTestsCtx); }
Example #18
Source File: SeleniumTestPlan.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
/** * clean up. * * @param parameters * @param method * @param testContex * @param xmlTest */ @AfterMethod(alwaysRun = true) public void afterTestMethod(final Object[] parameters, final Method method, final ITestContext testContex, final XmlTest xmlTest) { final List<TearDownService> serviceList = SeleniumTestsContextManager.getThreadContext().getTearDownServices(); if (serviceList != null && !serviceList.isEmpty()) { for (final TearDownService service : serviceList) { service.tearDown(); } } WebUIDriver.cleanUp(); logger.info(Thread.currentThread() + " Finish method " + method.getName()); }
Example #19
Source File: SeleniumTestPlan.java From seleniumtestsframework with Apache License 2.0 | 5 votes |
@BeforeMethod(alwaysRun = true) public void beforeTestMethod(final Object[] parameters, final Method method, final ITestContext testContex, final XmlTest xmlTest) { logger.info(Thread.currentThread() + " Start method " + method.getName()); SeleniumTestsContextManager.initThreadContext(testContex, xmlTest); if (method != null) { SeleniumTestsContextManager.getThreadContext().setAttribute(SeleniumTestsContext.TEST_METHOD_SIGNATURE, buildMethodSignature(method, parameters)); } }
Example #20
Source File: TestNGTestUnit.java From pitest with Apache License 2.0 | 5 votes |
private XmlSuite createSuite() { final XmlSuite suite = new XmlSuite(); suite.setName(this.clazz.getName()); suite.setSkipFailedInvocationCounts(true); final XmlTest test = new XmlTest(suite); test.setName(this.clazz.getName()); final XmlClass xclass = new XmlClass(this.clazz.getName()); test.setXmlClasses(Collections.singletonList(xclass)); if (!this.includedTestMethods.isEmpty()) { final List<XmlInclude> xmlIncludedTestMethods = new ArrayList<>(); for (final String includedTestMethod : this.includedTestMethods) { final XmlInclude includedMethod = new XmlInclude(includedTestMethod); xmlIncludedTestMethods.add(includedMethod); } xclass.setIncludedMethods(xmlIncludedTestMethods); } if (!this.config.getExcludedGroups().isEmpty()) { suite.setExcludedGroups(this.config.getExcludedGroups()); } if (!this.config.getIncludedGroups().isEmpty()) { suite.setIncludedGroups(this.config.getIncludedGroups()); } return suite; }
Example #21
Source File: SuiteAlterer.java From Quantum with MIT License | 5 votes |
public List<Map<String, String>> getParameterList(XmlTest test) throws IOException { Map<String, String> testPars = test.getParameters(); Iterator it2 = testPars.entrySet().iterator(); String path = null; while (it2.hasNext()) { Map.Entry pair = (Map.Entry) it2.next(); if (pair.getKey().toString().equals("csvParams")) { path = pair.getValue().toString(); break; } } return getArrayFromCsv(new File(path)); }
Example #22
Source File: MyTestExecutor.java From AppiumTestDistribution with GNU General Public License v3.0 | 5 votes |
public CreateGroups invoke() { xmlClasses = writeXmlClass(tests, methods); test = new XmlTest(suite); test.setName(category); test.addParameter("device", ""); include(groupsExclude, EXCLUDE_GROUPS); test.setIncludedGroups(groupsInclude); test.setExcludedGroups(groupsExclude); writeXml = new ArrayList<>(); return this; }
Example #23
Source File: CreateXmlFile.java From Leo with Apache License 2.0 | 5 votes |
private void addTest(XmlTest test){ if (null==test){ log.error("测试集为null,添加失败"); return; } suite.addTest(test); }
Example #24
Source File: TestStarter.java From dockerfile-image-update with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * This will provide a test suite for TestNG which will be based on the package. * It delegates any class inspection / reflection to TestNG. * * @return the XmlSuite for com.salesforce.dockerfileimageupdate.itest.tests.* */ private List<XmlSuite> getXmlSuites() { XmlSuite suite = new XmlSuite(); suite.setName("Full Integration Test"); XmlTest test = new XmlTest(suite); test.setName("all-tests"); XmlRun xmlRun = new XmlRun(); xmlRun.onInclude(test.getName()); List<XmlPackage> packages = new ArrayList<>(); packages.add(new XmlPackage("com.salesforce.dockerfileimageupdate.itest.tests.*")); test.setXmlPackages(packages); List<XmlSuite> suites = new ArrayList<>(); suites.add(suite); return suites; }
Example #25
Source File: TestRunnerFactory.java From qaf with MIT License | 5 votes |
@Override public TestRunner newTestRunner(ISuite suite, XmlTest test, Collection<IInvokedMethodListener> listeners, List<IClassListener> classListeners) { TestRunner runner = null!=testRunnerFactory?testRunnerFactory.newTestRunner(suite, test, listeners, classListeners): new TestRunner(configuration, suite, test, false /*skipFailedInvocationCounts */, listeners,classListeners);; init(runner); return runner; }
Example #26
Source File: TestClass.java From qaf with MIT License | 5 votes |
protected TestClass(IClass cls, ITestMethodFinder testMethodFinder, IAnnotationFinder annotationFinder, RunInfo runInfo, XmlTest xmlTest, XmlClass xmlClass) { init(cls, testMethodFinder, annotationFinder, runInfo, xmlTest, xmlClass); }
Example #27
Source File: CreateXmlFile.java From Leo with Apache License 2.0 | 5 votes |
private void addClassToXmlTest(String pkgAndClsName,String testName) { XmlTest xmltest=new XmlTest(); XmlClass classe=new XmlClass(pkgAndClsName); xmltest.setName(testName); xmltest.setClasses(Arrays.asList(classe)); addTest(xmltest); }
Example #28
Source File: TestRunner.java From qaf with MIT License | 5 votes |
protected TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, String outputDirectory, IAnnotationFinder finder, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners) { init(configuration, suite, test, outputDirectory, finder, skipFailedInvocationCounts, invokedMethodListeners, classListeners); }
Example #29
Source File: TestRunner.java From qaf with MIT License | 5 votes |
public TestRunner(IConfiguration configuration, ISuite suite, XmlTest test, boolean skipFailedInvocationCounts, Collection<IInvokedMethodListener> invokedMethodListeners, List<IClassListener> classListeners) { init(configuration, suite, test, suite.getOutputDirectory(), suite.getAnnotationFinder(), skipFailedInvocationCounts, invokedMethodListeners, classListeners); }
Example #30
Source File: TestRunner.java From qaf with MIT License | 5 votes |
/** * Initialize meta groups */ private void initMetaGroups(XmlTest xmlTest) { Map<String, List<String>> metaGroups = xmlTest.getMetaGroups(); for (Map.Entry<String, List<String>> entry : metaGroups.entrySet()) { addMetaGroup(entry.getKey(), entry.getValue()); } }