How to use getMethodSelectors method of org.testng.xml.XmlSuite class

Best Testng code snippet using org.testng.xml.XmlSuite.getMethodSelectors

Source:XmlSuite.java Github

copy

Full Screen

...271 * Returns the method selectors.272 *273 * @return the method selectors.274 */275 public List<XmlMethodSelector> getMethodSelectors() {276 if (m_xmlMethodSelectors != null) {277 return m_xmlMethodSelectors.getMethodSelectors();278 } else {279 // deprecated280 return m_methodSelectors;281 }282 }283 /**284 * Sets the method selectors.285 *286 * @param methodSelectors the method selectors.287 */288 public void setMethodSelectors(List<XmlMethodSelector> methodSelectors) {289 m_methodSelectors = Lists.newArrayList(methodSelectors);290 }291 /**292 * Updates the list of parameters that apply to this XML suite. This method293 * should be invoked any time there is a change in the state of this suite that294 * would affect the parameter list.<br>295 * NOTE: Currently being invoked after a parent suite is added or if parameters296 * for this suite are updated.297 */298 private void updateParameters() {299 /*300 * Whatever parameters are set by user or via XML, should be updated301 * using parameters from parent suite, if it exists. Parameters from this302 * suite override the same named parameters from parent suite.303 */304 if (m_parentSuite != null) {305 Set<String> keySet = m_parentSuite.getParameters().keySet();306 for (String name : keySet) {307 if (!m_parameters.containsKey(name)) {308 m_parameters.put(name, m_parentSuite.getParameter(name));309 }310 }311 }312 }313 /**314 * Sets parameters.315 * @param parameters the parameters.316 */317 public void setParameters(Map<String, String> parameters) {318 m_parameters = parameters;319 updateParameters();320 }321 /**322 * Gets the parameters that apply to tests in this suite.<br>323 * Set of parameters for a suite is appended with parameters from parent suite.324 * Also, parameters from this suite override the same named parameters from325 * parent suite.326 */327 public Map<String, String> getParameters() {328 return m_parameters;329 }330 /**331 * @return The parameters defined in this suite and all its XmlTests.332 */333 public Map<String, String> getAllParameters() {334 Map<String, String> result = Maps.newHashMap();335 for (Map.Entry<String, String> entry : m_parameters.entrySet()) {336 result.put(entry.getKey(), entry.getValue());337 }338 for (XmlTest test : getTests()) {339 Map<String, String> tp = test.getLocalParameters();340 for (Map.Entry<String, String> entry : tp.entrySet()) {341 result.put(entry.getKey(), entry.getValue());342 }343 }344 return result;345 }346 /**347 * Returns the parameter defined in this suite only.348 * @param name the parameter name.349 * @return The parameter defined in this suite only.350 */351 public String getParameter(String name) {352 return m_parameters.get(name);353 }354 /**355 * @return The threadCount.356 */357 public int getThreadCount() {358 return m_threadCount;359 }360 /**361 * Set the thread count.362 * @param threadCount The thread count to set.363 */364 public void setThreadCount(int threadCount) {365 m_threadCount = threadCount;366 }367 /**368 * @return The JUnit compatibility flag.369 */370 public Boolean isJUnit() {371 return m_isJUnit;372 }373 /**374 * Sets the JUnit compatibility flag.375 *376 * @param isJUnit the JUnit compatibility flag.377 */378 public void setJUnit(Boolean isJUnit) {379 m_isJUnit = isJUnit;380 }381 // For YAML382 public void setJunit(Boolean j) {383 setJUnit(j);384 }385 public Boolean skipFailedInvocationCounts() {386 return m_skipFailedInvocationCounts;387 }388 public void setSkipFailedInvocationCounts(boolean skip) {389 m_skipFailedInvocationCounts = skip;390 }391 /**392 * Sets the XML packages.393 *394 * @param packages the XML packages.395 */396 public void setXmlPackages(List<XmlPackage> packages) {397 m_xmlPackages = Lists.newArrayList(packages);398 }399 /**400 * Returns the XML packages.401 *402 * @return the XML packages.403 */404 public List<XmlPackage> getXmlPackages() {405 return m_xmlPackages;406 }407 // For YAML408 public List<XmlPackage> getPackages() {409 return getXmlPackages();410 }411 @Tag(name = "method-selectors")412 public void setMethodSelectors(XmlMethodSelectors xms) {413 m_xmlMethodSelectors = xms;414 }415 // For YAML416 public void setPackages(List<XmlPackage> packages) {417 setXmlPackages(packages);418 }419 /**420 * @return A String representation of this XML suite.421 */422 public String toXml() {423 XMLStringBuffer xsb = new XMLStringBuffer();424 xsb.setDocType("suite SYSTEM \"" + Parser.TESTNG_DTD_URL + '\"');425 Properties p = new Properties();426 p.setProperty("name", getName());427 if (getVerbose() != null) {428 XmlUtils.setProperty(p, "verbose", getVerbose().toString(), DEFAULT_VERBOSE.toString());429 }430 final ParallelMode parallel= getParallel();431 if(parallel != null && !DEFAULT_PARALLEL.equals(parallel)) {432 p.setProperty("parallel", parallel.toString());433 }434 XmlUtils.setProperty(p, "group-by-instances", String.valueOf(getGroupByInstances()),435 DEFAULT_GROUP_BY_INSTANCES.toString());436 XmlUtils.setProperty(p, "configfailurepolicy", getConfigFailurePolicy().toString(),437 DEFAULT_CONFIG_FAILURE_POLICY.toString());438 XmlUtils.setProperty(p, "thread-count", String.valueOf(getThreadCount()),439 DEFAULT_THREAD_COUNT.toString());440 XmlUtils.setProperty(p, "data-provider-thread-count", String.valueOf(getDataProviderThreadCount()),441 DEFAULT_DATA_PROVIDER_THREAD_COUNT.toString());442 if (! DEFAULT_JUNIT.equals(m_isJUnit)) {443 p.setProperty("junit", m_isJUnit != null ? m_isJUnit.toString() : "false"); // TESTNG-141444 }445 XmlUtils.setProperty(p, "skipfailedinvocationcounts", m_skipFailedInvocationCounts.toString(),446 DEFAULT_SKIP_FAILED_INVOCATION_COUNTS.toString());447 if(null != m_objectFactory) {448 p.setProperty("object-factory", m_objectFactory.getClass().getName());449 }450 if (isStringNotEmpty(m_parentModule)) {451 p.setProperty("parent-module", getParentModule());452 }453 if (isStringNotEmpty(m_guiceStage)) {454 p.setProperty("guice-stage", getGuiceStage());455 }456 XmlUtils.setProperty(p, "allow-return-values", String.valueOf(getAllowReturnValues()),457 DEFAULT_ALLOW_RETURN_VALUES.toString());458 xsb.push("suite", p);459 XmlUtils.dumpParameters(xsb, m_parameters);460 if (hasElements(m_listeners)) {461 xsb.push("listeners");462 for (String listenerName: m_listeners) {463 Properties listenerProps = new Properties();464 listenerProps.setProperty("class-name", listenerName);465 xsb.addEmptyElement("listener", listenerProps);466 }467 xsb.pop("listeners");468 }469 if (hasElements(getXmlPackages())) {470 xsb.push("packages");471 for (XmlPackage pack : getXmlPackages()) {472 xsb.getStringBuffer().append(pack.toXml(" "));473 }474 xsb.pop("packages");475 }476 if (getXmlMethodSelectors() != null) {477 xsb.getStringBuffer().append(getXmlMethodSelectors().toXml(" "));478 } else {479 // deprecated480 if (hasElements(getMethodSelectors())) {481 xsb.push("method-selectors");482 for (XmlMethodSelector selector : getMethodSelectors()) {483 xsb.getStringBuffer().append(selector.toXml(" "));484 }485 xsb.pop("method-selectors");486 }487 }488 List<String> suiteFiles = getSuiteFiles();489 if (suiteFiles.size() > 0) {490 xsb.push("suite-files");491 for (String sf : suiteFiles) {492 Properties prop = new Properties();493 prop.setProperty("path", sf);494 xsb.addEmptyElement("suite-file", prop);495 }496 xsb.pop("suite-files");497 }498 List<String> included = getIncludedGroups();499 List<String> excluded = getExcludedGroups();500 if (hasElements(included) || hasElements(excluded)) {501 xsb.push("groups");502 xsb.push("run");503 for (String g : included) {504 xsb.addEmptyElement("include", "name", g);505 }506 for (String g : excluded) {507 xsb.addEmptyElement("exclude", "name", g);508 }509 xsb.pop("run");510 xsb.pop("groups");511 }512 if (m_xmlGroups != null) {513 xsb.getStringBuffer().append(m_xmlGroups.toXml(" "));514 }515 for (XmlTest test : getTests()) {516 xsb.getStringBuffer().append(test.toXml(" "));517 }518 xsb.pop("suite");519 return xsb.toXML();520 }521 @Tag(name = "method-selectors")522 public void setXmlMethodSelectors(XmlMethodSelectors xms) {523 m_xmlMethodSelectors = xms;524 }525 private XmlMethodSelectors getXmlMethodSelectors() {526 return m_xmlMethodSelectors;527 }528 /**529 * {@inheritDoc}530 */531 @Override532 public String toString() {533 StringBuilder result = new StringBuilder("[Suite: \"").append( m_name).append( "\" ");534 for (XmlTest t : m_tests) {535 result.append(" ").append( t.toString()).append(' ');536 }537 for (XmlMethodSelector ms : m_methodSelectors) {538 result.append(" methodSelector:").append(ms);539 }540 result.append(']');541 return result.toString();542 }543 /**544 * {@inheritDoc}545 * Note that this is not a full clone: XmlTest children are not cloned by this546 * method.547 */548 @Override549 public Object clone() {550 XmlSuite result = shallowCopy();551 result.setExcludedGroups(getExcludedGroups());552 result.setIncludedGroups(getIncludedGroups());553 result.setGroupByInstances(getGroupByInstances());554 result.setGroups(getGroups());555 result.setMethodSelectors(getXmlMethodSelectors());556 result.setPackages(getPackages());557 result.setParentSuite(getParentSuite());558 result.setPreserveOrder(getPreserveOrder());559 result.setSuiteFiles(getSuiteFiles());560 result.setTests(getTests());561 result.setXmlMethodSelectors(getXmlMethodSelectors());562 return result;563 }564 /**565 * This method returns a shallow cloned version. {@link XmlTest} are not copied by this method.566 * @return - A Shallow copied version of {@link XmlSuite}.567 */568 public XmlSuite shallowCopy() {569 XmlSuite result = new XmlSuite();570 result.setName(getName());571 result.setFileName(getFileName());572 result.setListeners(getListeners());573 result.setParallel(getParallel());574 result.setParentModule(getParentModule());575 result.setGuiceStage(getGuiceStage());576 result.setConfigFailurePolicy(getConfigFailurePolicy());577 result.setThreadCount(getThreadCount());578 result.setDataProviderThreadCount(getDataProviderThreadCount());579 result.setParameters(getParameters());580 result.setVerbose(getVerbose());581 result.setXmlPackages(getXmlPackages());582// result.setBeanShellExpression(getExpression());583 result.setMethodSelectors(getMethodSelectors());584 result.setJUnit(isJUnit()); // TESTNG-141585 result.setSkipFailedInvocationCounts(skipFailedInvocationCounts());586 result.setObjectFactory(getObjectFactory());587 result.setAllowReturnValues(getAllowReturnValues());588 result.setTimeOut(getTimeOut());589 return result;590 }591 /**592 * Sets the timeout.593 *594 * @param timeOut the timeout.595 */596 public void setTimeOut(String timeOut) {597 m_timeOut = timeOut;...

Full Screen

Full Screen

Source:XmlTest.java Github

copy

Full Screen

...76 // For YAML77 public void setPackages(List<XmlPackage> p) {78 setXmlPackages(p);79 }80 public List<XmlMethodSelector> getMethodSelectors() {81 return m_methodSelectors;82 }83 public void setMethodSelectors(List<XmlMethodSelector> methodSelectors) {84 m_methodSelectors = Lists.newArrayList(methodSelectors);85 }86 /**87 * Returns the suite this test is part of.88 * @return the suite this test is part of.89 */90 public XmlSuite getSuite() {91 return m_suite;92 }93 /**94 * @return the includedGroups.95 */96 public List<String> getIncludedGroups() {97 List<String> result = Lists.newArrayList();98 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {99 result.addAll(m_xmlGroups.getRun().getIncludes());100 }101 result.addAll(m_suite.getIncludedGroups());102 return Collections.unmodifiableList(result);103 }104 /**105 * Sets the XML Classes.106 * @param classes The classes to set.107 * @deprecated use setXmlClasses108 */109 @Deprecated110 public void setClassNames(List<XmlClass> classes) {111 m_xmlClasses = classes;112 }113 /**114 * @return Returns the classes.115 */116 public List<XmlClass> getXmlClasses() {117 return m_xmlClasses;118 }119 // For YAML120 public List<XmlClass> getClasses() {121 return getXmlClasses();122 }123 // For YAML124 public void setClasses(List<XmlClass> c) {125 setXmlClasses(c);126 }127 /**128 * Sets the XML Classes.129 * @param classes The classes to set.130 */131 public void setXmlClasses(List<XmlClass> classes) {132 m_xmlClasses = classes;133 }134 /**135 * @return Returns the name.136 */137 public String getName() {138 return m_name;139 }140 /**141 * @param name The name to set.142 */143 public void setName(String name) {144 m_name = name;145 }146 /**147 * @param v148 */149 public void setVerbose(int v) {150 m_verbose = v;151 }152 public int getThreadCount() {153 return m_threadCount > 0 ? m_threadCount : getSuite().getThreadCount();154 }155 public void setThreadCount(int threadCount) {156 m_threadCount = threadCount;157 }158 public void setIncludedGroups(List<String> g) {159 if (m_xmlGroups == null) {160 m_xmlGroups = new XmlGroups();161 }162 if (m_xmlGroups.getRun() == null) {163 m_xmlGroups.setRun(new XmlRun());164 }165 List<String> includes = m_xmlGroups.getRun().getIncludes();166 includes.clear();167 includes.addAll(g);168 }169 public void setExcludedGroups(List<String> g) {170 if (m_xmlGroups == null) {171 m_xmlGroups = new XmlGroups();172 }173 if (m_xmlGroups.getRun() == null) {174 m_xmlGroups.setRun(new XmlRun());175 }176 List<String> excludes = m_xmlGroups.getRun().getExcludes();177 excludes.clear();178 excludes.addAll(g);179 }180 public List<String> getExcludedGroups() {181 List<String> result = new ArrayList<>();182 if (m_xmlGroups != null && m_xmlGroups.getRun() != null) {183 result.addAll(m_xmlGroups.getRun().getExcludes());184 }185 result.addAll(m_suite.getExcludedGroups());186 return Collections.unmodifiableList(result);187 }188 public void addIncludedGroup(String g) {189 if (m_xmlGroups == null) {190 m_xmlGroups = new XmlGroups();191 m_xmlGroups.setRun(new XmlRun());192 }193 m_xmlGroups.getRun().getIncludes().add(g);194 }195 public void addExcludedGroup(String g) {196 if (m_xmlGroups == null) {197 m_xmlGroups = new XmlGroups();198 }199 if (m_xmlGroups.getRun() == null) {200 m_xmlGroups.setRun(new XmlRun());201 }202 m_xmlGroups.getRun().getExcludes().add(g);203 }204 /**205 * @return Returns the verbose.206 */207 public int getVerbose() {208 Integer result = m_verbose;209 if (null == result || XmlSuite.DEFAULT_VERBOSE.equals(m_verbose)) {210 result = m_suite.getVerbose();211 }212 if (null != result) {213 return result;214 } else {215 return 1;216 }217 }218 public boolean getGroupByInstances() {219 Boolean result = m_groupByInstances;220 if (result == null || XmlSuite.DEFAULT_GROUP_BY_INSTANCES.equals(m_groupByInstances)) {221 result = m_suite.getGroupByInstances();222 }223 if (result != null) {224 return result;225 } else {226 return XmlSuite.DEFAULT_GROUP_BY_INSTANCES;227 }228 }229 public void setGroupByInstances(boolean f) {230 m_groupByInstances = f;231 }232 /**233 * @return Returns the isJUnit.234 */235 public boolean isJUnit() {236 Boolean result = m_isJUnit;237 if (null == result || XmlSuite.DEFAULT_JUNIT.equals(result)) {238 result = m_suite.isJUnit();239 }240 return result;241 }242 /**243 * @param isJUnit The isJUnit to set.244 */245 public void setJUnit(boolean isJUnit) {246 m_isJUnit = isJUnit;247 }248 // For YAML249 public void setJunit(boolean isJUnit) {250 setJUnit(isJUnit);251 }252 public void setSkipFailedInvocationCounts(boolean skip) {253 m_skipFailedInvocationCounts = skip;254 }255 /**256 * @return Returns the isJUnit.257 */258 public boolean skipFailedInvocationCounts() {259 Boolean result = m_skipFailedInvocationCounts;260 if (null == result) {261 result = m_suite.skipFailedInvocationCounts();262 }263 return result;264 }265 public void addMetaGroup(String name, List<String> metaGroup) {266 if (m_xmlGroups == null) {267 m_xmlGroups = new XmlGroups();268 }269 XmlDefine define = new XmlDefine();270 define.setName(name);271 define.getIncludes().addAll(metaGroup);272 m_xmlGroups.getDefines().add(define);273 }274 public void addMetaGroup(String name, String... metaGroup) {275 addMetaGroup(name, Arrays.asList(metaGroup));276 }277 // For YAML278 public void setMetaGroups(Map<String, List<String>> metaGroups) {279 for (Map.Entry<String, List<String>> entry : metaGroups.entrySet()) {280 addMetaGroup(entry.getKey(), entry.getValue());281 }282 }283 /**284 * @return Returns the metaGroups.285 */286 public Map<String, List<String>> getMetaGroups() {287 if (m_xmlGroups == null) {288 return Collections.emptyMap();289 }290 Map<String, List<String>> result = Maps.newHashMap();291 List<XmlDefine> defines = m_xmlGroups.getDefines();292 for (XmlDefine xd : defines) {293 result.put(xd.getName(), xd.getIncludes());294 }295 return result;296 }297 /**298 * @param parameters299 */300 public void setParameters(Map<String, String> parameters) {301 m_parameters = parameters;302 }303 public void addParameter(String key, String value) {304 m_parameters.put(key, value);305 }306 public String getParameter(String name) {307 String result = m_parameters.get(name);308 if (null == result) {309 result = m_suite.getParameter(name);310 }311 return result;312 }313 /**314 * @return the parameters defined in this test tag and the tags above it.315 */316 public Map<String, String> getAllParameters() {317 Map<String, String> result = Maps.newHashMap();318 result.putAll(getSuite().getParameters());319 result.putAll(m_parameters);320 return result;321 }322 /**323 * @return the parameters defined in this tag, and only this test tag. To retrieve324 * the inherited parameters as well, call {@code getAllParameters()}.325 */326 public Map<String, String> getLocalParameters() {327 return m_parameters;328 }329 /**330 * @deprecated Use {@code getLocalParameters()} or {@code getAllParameters()}331 */332 @Deprecated333 public Map<String, String> getParameters() {334 return getAllParameters();335 }336 /**337 * @deprecated Use {@code getLocalParameters()} instead338 *339 * @return the parameters defined on this <test> tag only340 */341 @Deprecated342 public Map<String, String> getTestParameters() {343 return getLocalParameters();344 }345 public void setParallel(XmlSuite.ParallelMode parallel) {346 m_parallel = skipDeprecatedValues(parallel);347 }348 public XmlSuite.ParallelMode getParallel() {349 XmlSuite.ParallelMode result;350 if (null != m_parallel || XmlSuite.DEFAULT_PARALLEL.equals(m_parallel)) {351 result = m_parallel;352 }353 else {354 result = m_suite.getParallel();355 }356 return result;357 }358 public String getTimeOut() {359 String result = null;360 if (null != m_timeOut) {361 result = m_timeOut;362 }363 else {364 result = m_suite.getTimeOut();365 }366 return result;367 }368 public long getTimeOut(long def) {369 long result = def;370 if (getTimeOut() != null) {371 result = Long.parseLong(getTimeOut());372 }373 return result;374 }375 public void setTimeOut(long timeOut) {376 m_timeOut = Long.toString(timeOut);377 }378 private void setTimeOut(String timeOut) {379 m_timeOut = timeOut;380 }381 public void setExpression(String expression) {382 setBeanShellExpression(expression);383 }384 public void setBeanShellExpression(String expression) {385 List<XmlMethodSelector> selectors = getMethodSelectors();386 if (selectors.size() > 0) {387 selectors.get(0).setExpression(expression);388 } else if (expression != null) {389 XmlMethodSelector xms = new XmlMethodSelector();390 xms.setExpression(expression);391 xms.setLanguage("BeanShell");392 getMethodSelectors().add(xms);393 }394 }395 public String getExpression() {396 List<XmlMethodSelector> selectors = getMethodSelectors();397 if (selectors.size() > 0) {398 return selectors.get(0).getExpression();399 } else {400 return null;401 }402 }403 public String toXml(String indent) {404 XMLStringBuffer xsb = new XMLStringBuffer(indent);405 Properties p = new Properties();406 p.setProperty("name", getName());407 if (m_isJUnit != null) {408 XmlUtils.setProperty(p, "junit", m_isJUnit.toString(), XmlSuite.DEFAULT_JUNIT.toString());409 }410 if (m_parallel != null) {411 XmlUtils.setProperty(p, "parallel", m_parallel.toString(), XmlSuite.DEFAULT_PARALLEL.toString());412 }413 if (m_verbose != null) {414 XmlUtils.setProperty(p, "verbose", m_verbose.toString(), XmlSuite.DEFAULT_VERBOSE.toString());415 }416 if (null != m_timeOut) {417 p.setProperty("time-out", m_timeOut.toString());418 }419 if (m_preserveOrder != null && ! XmlSuite.DEFAULT_PRESERVE_ORDER.equals(m_preserveOrder)) {420 p.setProperty("preserve-order", m_preserveOrder.toString());421 }422 if (m_threadCount != -1) {423 p.setProperty("thread-count", Integer.toString(m_threadCount));424 }425 if (m_groupByInstances != null) {426 XmlUtils.setProperty(p, "group-by-instances", String.valueOf(getGroupByInstances()),427 XmlSuite.DEFAULT_GROUP_BY_INSTANCES.toString());428 }429 xsb.push("test", p);430 if (null != getMethodSelectors() && !getMethodSelectors().isEmpty()) {431 xsb.push("method-selectors");432 for (XmlMethodSelector selector: getMethodSelectors()) {433 xsb.getStringBuffer().append(selector.toXml(indent + " "));434 }435 xsb.pop("method-selectors");436 }437 XmlUtils.dumpParameters(xsb, m_parameters);438 // groups439 if ((m_xmlGroups != null &&440 (!m_xmlGroups.getDefines().isEmpty() ||441 (m_xmlGroups.getRun() != null && (!m_xmlGroups.getRun().getIncludes().isEmpty() || !m_xmlGroups.getRun().getExcludes().isEmpty()))442 )443 ) || !m_xmlDependencyGroups.isEmpty()) {444 xsb.push("groups");445 // define446 if (m_xmlGroups != null) {...

Full Screen

Full Screen

Source:DefaultXmlWeaver.java Github

copy

Full Screen

...101 if (xmlSuite.getXmlMethodSelectors() != null) {102 xsb.getStringBuffer().append(xmlSuite.getXmlMethodSelectors().toXml(" "));103 } else {104 // deprecated105 if (hasElements(xmlSuite.getMethodSelectors())) {106 xsb.push("method-selectors");107 for (XmlMethodSelector selector : xmlSuite.getMethodSelectors()) {108 xsb.getStringBuffer().append(selector.toXml(" "));109 }110 xsb.pop("method-selectors");111 }112 }113 List<String> suiteFiles = xmlSuite.getSuiteFiles();114 if (!suiteFiles.isEmpty()) {115 xsb.push("suite-files");116 for (String sf : suiteFiles) {117 Properties prop = new Properties();118 prop.setProperty("path", sf);119 xsb.addEmptyElement("suite-file", prop);120 }121 xsb.pop("suite-files");122 }123 List<String> included = xmlSuite.getIncludedGroups();124 List<String> excluded = xmlSuite.getExcludedGroups();125 if (hasElements(included) || hasElements(excluded)) {126 xsb.push("groups");127 xsb.push("run");128 for (String g : included) {129 xsb.addEmptyElement("include", "name", g);130 }131 for (String g : excluded) {132 xsb.addEmptyElement("exclude", "name", g);133 }134 xsb.pop("run");135 xsb.pop("groups");136 }137 if (xmlSuite.getGroups() != null) {138 xsb.getStringBuffer().append(xmlSuite.getGroups().toXml(" "));139 }140 for (XmlTest test : xmlSuite.getTests()) {141 xsb.getStringBuffer().append(test.toXml(" "));142 }143 xsb.pop("suite");144 return xsb.toXML();145 }146 @Override147 public String asXml(XmlTest xmlTest, String indent) {148 XMLStringBuffer xsb = new XMLStringBuffer(indent);149 xsb.setDefaultComment(defaultComment);150 Properties p = new Properties();151 p.setProperty("name", xmlTest.getName());152 XmlUtils.setProperty(153 p, "junit", Boolean.toString(xmlTest.isJUnit()), XmlSuite.DEFAULT_JUNIT.toString());154 XmlUtils.setProperty(155 p, "parallel", xmlTest.getParallel().toString(), XmlSuite.DEFAULT_PARALLEL.toString());156 XmlUtils.setProperty(157 p, "verbose", Integer.toString(xmlTest.getVerbose()), XmlSuite.DEFAULT_VERBOSE.toString());158 if (null != xmlTest.getTimeOut()) {159 p.setProperty("time-out", xmlTest.getTimeOut());160 }161 if (xmlTest.getPreserveOrder() != null162 && !XmlSuite.DEFAULT_PRESERVE_ORDER.equals(xmlTest.getPreserveOrder())) {163 p.setProperty("preserve-order", xmlTest.getPreserveOrder().toString());164 }165 if (xmlTest.getThreadCount() != -1) {166 p.setProperty("thread-count", Integer.toString(xmlTest.getThreadCount()));167 }168 XmlUtils.setProperty(169 p,170 "group-by-instances",171 String.valueOf(xmlTest.getGroupByInstances()),172 XmlSuite.DEFAULT_GROUP_BY_INSTANCES.toString());173 xsb.push("test", p);174 if (null != xmlTest.getMethodSelectors() && !xmlTest.getMethodSelectors().isEmpty()) {175 xsb.push("method-selectors");176 for (XmlMethodSelector selector : xmlTest.getMethodSelectors()) {177 xsb.getStringBuffer().append(selector.toXml(indent + " "));178 }179 xsb.pop("method-selectors");180 }181 XmlUtils.dumpParameters(xsb, xmlTest.getLocalParameters());182 // groups183 if ((xmlTest.getXmlGroups() != null184 && (!xmlTest.getXmlGroups().getDefines().isEmpty()185 || (xmlTest.getXmlGroups().getRun() != null186 && (!xmlTest.getXmlGroups().getRun().getIncludes().isEmpty()187 || !xmlTest.getXmlGroups().getRun().getExcludes().isEmpty()))))188 || !xmlTest.getXmlDependencyGroups().isEmpty()) {189 xsb.push("groups");190 // define...

Full Screen

Full Screen

Source:MethodSelector.java Github

copy

Full Screen

...75 XmlTest eachTest = new XmlTest();76 tests.add(eachTest);77 eachTest.setName("My test");78 eachTest.setParameters(allParameters.get(0));79 //eachTest.setMethodSelectors(getMethodSelectors(methodS));80 eachTest.setXmlClasses(getXmlClasses(eachTest, getMethodsfromClass));81 eachTest.setSuite(suite);82 XmlTest eachTest1 = new XmlTest();83 tests.add(eachTest1);84 eachTest1.setName("ChromeTest");85 eachTest1.setParameters(allParameters.get(1));86 //eachTest.setMethodSelectors(getMethodSelectors(methodS));87 eachTest1.setXmlClasses(getXmlClasses(eachTest, getMethodsfromClass));88 eachTest1.setSuite(suite); 89 return tests;90 }9192 public List<XmlClass> getXmlClasses(XmlTest test,Map<String, String> getMethodsfromClass, List<String> ls) {93 List<XmlClass> classes = new ArrayList<XmlClass>();94 ArrayList<XmlInclude> methodsToRun = new ArrayList<XmlInclude>(); 95 if(getMethodsfromClass.isEmpty()==true)96 {97 try98 {99 File folder = new File(100 "D:\\Vbrick_TeamCity__Aug26\\vBricksTest-1\\src\\test\\java\\com\\vbrick\\avenger\\test");101 File[] listOfFiles = folder.listFiles();102 for (int i = 0; i < listOfFiles.length; i++) {103 if (listOfFiles[i].isFile()) {104 // System.out.println("File " +105 // listOfFiles[i].getName().replace(".java",""));106 String name = listOfFiles[i].getName().replace(".java", "");107 String path = "com.vbrick.avenger.test." + name;108 System.out.println("path is" +path);109 Class c =Class.forName(path);110 System.out.println("value of c is" +c.getSimpleName());111 XmlClass eachClass = new XmlClass(path);112 classes.add(eachClass);113 eachClass.setExcludedMethods(ls);114 eachClass.setXmlTest(test);115 116 }117 }118 }119 catch(Exception e)120 {121 122 }123 }124 125 else126 {127 try128 {129 int counter=0;130 for (Map.Entry<String, String> entry : getMethodsfromClass.entrySet()) {131 System.out.println("value of entry key is" +entry.getKey() +"value is" +entry.getValue() );132 String[] splits = entry.getValue().split(":");133 System.out.println("splits.size: " + splits.length);134 System.out.println("value 1 is" +splits[0]);135 System.out.println("value 1 is" +splits[1]);136 String path = "com.vbrick.avenger.test." + entry.getValue();137 XmlClass eachClass = new XmlClass(path);138 classes.add(eachClass);139 List<String> ls = new ArrayList<String>();140 ls.add("smokeTest1");141 eachClass.setExcludedMethods(ls); 142 methodsToRun.add(new XmlInclude(entry.getKey()));143 eachClass.setIncludedMethods(methodsToRun);144 // eachClass.setClass(AddUserTest.class);145 eachClass.setXmlTest(test);146 // System.out.println("value of entry key is" +entry.getKey());147 counter++;148 //System.out.println("Value of counter After increment"+counter);149 }150 151 }152 catch(Exception e)153 {154 155 }156 }157 return classes;158 159 160 // myClasses.add(new XmlClass("com.vbrick.avenger.test.AddUserTest"));161 XmlClass eachClass = new XmlClass("com.vbrick.avenger.test.AddUserTest");162 classes.add(eachClass1);163 classes.add(eachClass);164 List<String> ls = new ArrayList<String>();165 ls.add("verify_Creation_of_User_Sucessfull1");166 167 for (int i = 0; i < getMethodsfromClass.size(); i++) {168 methodsToRun.add(new XmlInclude(getMethodsfromClass.get(i)));169 System.out.println("values in method to run" +methodsToRun);170 }171 eachClass.setIncludedMethods(methodsToRun);172 //eachClass.setExcludedMethods(ls);173 eachClass1.setIncludedMethods(methodsToRun);174 //eachClass2.setIncludedMethods(methodsToRun);175 eachClass.setClass(AddUserTest.class);176 eachClass1.setClass(SampleTest1.class);177 //eachClass2.setClass(MyTestClass.class);178 179 eachClass.setXmlTest(test);180 eachClass1.setXmlTest(test);181 //eachClass2.setXmlTest(test);182 183 184 }185186 public List<XmlMethodSelector> getMethodSelectors(List<String> list) {187 List<XmlMethodSelector> methodSelectors = new ArrayList<XmlMethodSelector>();188 XmlMethodSelector selector = new XmlMethodSelector();189190 XmlScript script = new XmlScript();191 String s = "";192 selector.setScript(script);193 script.setLanguage("beanshell");194 for (int i = 0; i < list.size(); i++) {195 logger.info("list size is " + list.size());196 logger.info("value of list are" + list.get(i));197 int value = list.size();198199 if (i == value - 1 || value == 0) {200 s = s.concat("!testngMethod.getMethodName().equals(\"" ...

Full Screen

Full Screen

Source:XmlSuiteTest.java Github

copy

Full Screen

...73 System.setOut(new PrintStream(stream));74 Parser parser = new Parser("src/test/resources/xml/issue1674.xml");75 List<XmlSuite> suites = parser.parseToList();76 XmlSuite xmlsuite = suites.get(0);77 assertThat(xmlsuite.getTests().get(0).getMethodSelectors().size()).isEqualTo(0);78 TestNG testNG = create();79 testNG.setXmlSuites(suites);80 testNG.setUseDefaultListeners(false);81 testNG.run();82 assertThat(xmlsuite.getTests().get(0).getMethodSelectors().size()).isEqualTo(1);83 assertThat(stream.toString()).contains(Arrays.asList("rajni", "kamal", "mgr"));84 } finally {85 System.setOut(current);86 }87 }88 static class StringOutputStream extends OutputStream {89 private StringBuilder string = new StringBuilder();90 @Override91 public void write(int b) {92 this.string.append((char) b);93 }94 // Netbeans IDE automatically overrides this toString()95 public String toString() {96 return this.string.toString();...

Full Screen

Full Screen

getMethodSelectors

Using AI Code Generation

copy

Full Screen

1import org.testng.xml.XmlSuite;2import java.lang.reflect.Method;3import java.util.List;4import java.util.Arrays;5public class TestNGGetMethodSelectors {6 public static void main(String[] args) {7 XmlSuite xmlSuite = new XmlSuite();8 xmlSuite.setMethodSelectors(Arrays.asList("org.testng.internal.MethodSelector", "org.testng.internal.MethodSelector2"));9 List<String> methodSelectors = xmlSuite.getMethodSelectors();10 System.out.println("Method Selectors: " + methodSelectors);11 }12}

Full Screen

Full Screen

getMethodSelectors

Using AI Code Generation

copy

Full Screen

1package com.seleniumsimplified.testng;2import org.testng.Assert;3import org.testng.annotations.Test;4import org.testng.xml.XmlSuite;5public class GetMethodSelectorsTest {6 public void getMethodSelectorsTest(){7 XmlSuite xmlSuite = new XmlSuite();8 xmlSuite.setMethodSelectors("testng1");9 Assert.assertEquals(xmlSuite.getMethodSelectors(), "testng1");10 }11}12at org.testng.xml.XmlSuite.setMethodSelectors(XmlSuite.java:449)13at com.seleniumsimplified.testng.GetMethodSelectorsTest.getMethodSelectorsTest(GetMethodSelectorsTest.java:15)14at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)15at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)16at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)17at java.lang.reflect.Method.invoke(Method.java:498)18at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:132)19at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)20at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)21at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)22at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)23at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)24at org.testng.TestRunner.privateRun(TestRunner.java:648)25at org.testng.TestRunner.run(TestRunner.java:505)26at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)27at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)28at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)29at org.testng.SuiteRunner.run(SuiteRunner.java:364)30at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)31at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)32at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)33at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)34at org.testng.TestNG.runSuites(TestNG.java:1069)35at org.testng.TestNG.run(TestNG.java:1037)36at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)

Full Screen

Full Screen

getMethodSelectors

Using AI Code Generation

copy

Full Screen

1public void testGetMethods() throws Exception {2 XmlSuite suite = new XmlSuite();3 suite.setName("TestSuite");4 XmlTest test = new XmlTest(suite);5 test.setName("Test");6 test.setXmlClasses(Arrays.asList(new XmlClass("com.test.SampleTest")));7 suite.setTests(Arrays.asList(test));8 suite.setVerbose(1);9 suite.setParallel(XmlSuite.ParallelMode.NONE);10 TestNG tng = new TestNG();11 tng.setXmlSuites(Arrays.asList(suite));12 tng.run();13 List<String> methods = suite.getTests().get(0).getXmlClasses().get(0).getIncludedMethods().stream().map(XmlInclude::getName).collect(Collectors.toList());14 assertTrue(methods.contains("test1"));15 assertTrue(methods.contains("test2"));16 assertTrue(methods.contains("test3"));17 assertTrue(methods.contains("test4"));18}19package com.test;20public class SampleTest {21 public void test1() {22 }23 public void test2() {24 }25 public void test3() {26 }27 public void test4() {28 }29}30 <version>${testng.version}</version

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful