<bdo id='EcM7g'></bdo><ul id='EcM7g'></ul>
    1. <i id='EcM7g'><tr id='EcM7g'><dt id='EcM7g'><q id='EcM7g'><span id='EcM7g'><b id='EcM7g'><form id='EcM7g'><ins id='EcM7g'></ins><ul id='EcM7g'></ul><sub id='EcM7g'></sub></form><legend id='EcM7g'></legend><bdo id='EcM7g'><pre id='EcM7g'><center id='EcM7g'></center></pre></bdo></b><th id='EcM7g'></th></span></q></dt></tr></i><div id='EcM7g'><tfoot id='EcM7g'></tfoot><dl id='EcM7g'><fieldset id='EcM7g'></fieldset></dl></div>

        <legend id='EcM7g'><style id='EcM7g'><dir id='EcM7g'><q id='EcM7g'></q></dir></style></legend>
      1. <tfoot id='EcM7g'></tfoot>

      2. <small id='EcM7g'></small><noframes id='EcM7g'>

        动态 TestNG XML 创建.获取错误的 XML.我错在哪里

        Dynamic TestNG XML Creation. Getting wrong XML. Where I am wrong(动态 TestNG XML 创建.获取错误的 XML.我错在哪里)

        <small id='370ZK'></small><noframes id='370ZK'>

            <tfoot id='370ZK'></tfoot>
              <bdo id='370ZK'></bdo><ul id='370ZK'></ul>

              <legend id='370ZK'><style id='370ZK'><dir id='370ZK'><q id='370ZK'></q></dir></style></legend>
                <tbody id='370ZK'></tbody>

                • <i id='370ZK'><tr id='370ZK'><dt id='370ZK'><q id='370ZK'><span id='370ZK'><b id='370ZK'><form id='370ZK'><ins id='370ZK'></ins><ul id='370ZK'></ul><sub id='370ZK'></sub></form><legend id='370ZK'></legend><bdo id='370ZK'><pre id='370ZK'><center id='370ZK'></center></pre></bdo></b><th id='370ZK'></th></span></q></dt></tr></i><div id='370ZK'><tfoot id='370ZK'></tfoot><dl id='370ZK'><fieldset id='370ZK'></fieldset></dl></div>
                  本文介绍了动态 TestNG XML 创建.获取错误的 XML.我错在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  动态 TestNG XML 创建.获取错误的 XML.我哪里错了.

                  Dynamic TestNG XML Creation. Getting wrong XML. Where I am wrong.

                  我希望按如下所示打印我的 testNG xml.

                  I want my testNG xml to be print as shown below.

                  <?xml version="1.0" encoding="UTF-8"?>
                  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
                  <suite name="App Automation Testing">
                    <parameter name="BrowserName" value="chrome"/>
                    <test name="MyTest1">
                      <classes>
                        <class name="etaf.tests.LaunchApp"/>
                        <class name="etaf.tests.LoginTests"/>
                      </classes>
                    </test> <!-- MyTest1 -->
                    <test name="MyTest2">
                      <classes>
                        <class name="etaf.tests.LaunchApp"/>
                      </classes>
                    </test> <!-- MyTest2 -->
                  </suite> <!-- App Automation Testing -->
                  

                  但是使用下面的 Java 代码;这段代码有一个类似于下面显示的数组

                  But with the below Java Code; this code is having a array similar to what shown below

                  |testclass|testname|
                  |class1   |TC_LOGIN|
                  |class2   |TC_LOGIN|
                  |class1   |TC_WORK |
                  

                  public void sample(String[][] dbArr, Map<String,String> parameters ) {
                  
                          //Create an instance on TestNG
                          TestNG myTestNG = new TestNG();
                  
                          //Create an instance of XML Suite and assign a name for it.
                          XmlSuite suite = new XmlSuite();
                          suite.setName("App Automation Testing");
                          suite.setParameters(parameters);
                  
                          String dummyName = "";
                          List<XmlClass> classes1 = null;
                          List<XmlTest> tests = new ArrayList<XmlTest>();
                          XmlTest test1 = null;
                  
                  
                          for(int i=0;i<dbArr.length;i++) {
                              if(!dummyName.equalsIgnoreCase(dbArr[i][1])) {
                                  test1 = new XmlTest(suite);
                                  test1.setName(dbArr[i][1]);
                                  classes1 = new ArrayList<XmlClass> ();
                                  classes1.add(new XmlClass(dbArr[i][0]));
                                  dummyName = dbArr[i][1];
                  
                              } else if(dummyName.equalsIgnoreCase(dbArr[i][1])) {
                                  classes1.add(new XmlClass(dbArr[i][0]));
                                  dummyName = dbArr[i][1];
                              }
                              test1.setXmlClasses(classes1);
                              tests.add(test1);
                          }
                  
                          //add the list of tests to your Suite.
                          suite.setTests(tests);
                  
                          //Add the suite to the list of suites.
                          List<XmlSuite> suites = new ArrayList<XmlSuite>();
                          suites.add(suite);
                  
                          System.out.println(suite.toXml());
                  
                          //Set the list of Suites to the testNG object you created earlier.
                          myTestNG.setXmlSuites(suites);
                  
                          //invoke run() - this will run your class.
                          myTestNG.run();
                      }
                  

                  它是这样打印的.我哪里错了.?请帮忙.

                  <?xml version="1.0" encoding="UTF-8"?>
                  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
                  <suite name="App Automation Testing">
                    <parameter name="BrowserName" value="chrome"/>
                    <test name="TC_LOGIN">
                      <classes>
                        <class name="etaf.tests.LaunchApp"/>
                        <class name="etaf.tests.LoginTests"/>
                      </classes>
                    </test> <!-- TC_LOGIN -->
                    <test name="TC_LOGIN">
                      <classes>
                        <class name="etaf.tests.LaunchApp"/>
                        <class name="etaf.tests.LoginTests"/>
                      </classes>
                    </test> <!-- TC_LOGIN -->
                    <test name="TC_WORK">
                      <classes>
                        <class name="etaf.tests.LaunchApp"/>
                      </classes>
                    </test> <!-- TC_WORK -->
                  </suite> <!-- App Automation Testing -->
                  

                  推荐答案

                  我认为问题出在您遍历 2D 数组的方式上.

                  I believe the problem lies in the way in which you are iterating through the 2D array.

                  这里更容易完成.

                  import org.testng.TestNG;
                  import org.testng.xml.XmlClass;
                  import org.testng.xml.XmlSuite;
                  import org.testng.xml.XmlTest;
                  
                  import java.util.*;
                  
                  public class TestClassExample {
                      public static void main(String[] args) {
                          String[][] data = new String[][]{
                                  {"class1", "TC_LOGIN"},
                                  {"class2", "TC_LOGIN"},
                                  {"class1", "TC_WORK"}
                          };
                          sample(transformToMap(data), Collections.emptyMap());
                      }
                  
                      private static Map<String, List<String>> transformToMap(String[][] data) {
                          Map<String, List<String>> map = new HashMap<>();
                          for (String[] aData : data) {
                              String key = aData[1];
                              List<String> classes = map.computeIfAbsent(key, k -> new ArrayList<>());
                              classes.add(aData[0]);
                          }
                          return map;
                      }
                  
                      private static void sample(Map<String, List<String>> dbArr, Map<String, String> parameters) {
                  
                          //Create an instance on TestNG
                          TestNG myTestNG = new TestNG();
                  
                          //Create an instance of XML Suite and assign a name for it.
                          XmlSuite suite = new XmlSuite();
                          suite.setName("App Automation Testing");
                          suite.setParameters(parameters);
                          dbArr.forEach((key, value) -> {
                              XmlTest xmlTest = new XmlTest(suite);
                              xmlTest.setName(key);
                              value.forEach(eachValue -> {
                                  XmlClass xmlClass = new XmlClass(eachValue, false);
                                  xmlTest.getClasses().add(xmlClass);
                              });
                          });
                  
                          //Add the suite to the list of suites.
                          List<XmlSuite> suites = new ArrayList<>();
                          suites.add(suite);
                  
                          System.out.println(suite.toXml());
                  
                          //Set the list of Suites to the testNG object you created earlier.
                          myTestNG.setXmlSuites(suites);
                      }
                  }
                  

                  输出如下:

                  objc[59296]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java (0x102a554c0) and /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/jre/lib/libinstrument.dylib (0x102ae14e0). One of the two will be used. Which one is undefined.
                  <?xml version="1.0" encoding="UTF-8"?>
                  <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
                  <suite name="App Automation Testing">
                    <test thread-count="5" name="TC_WORK">
                      <classes>
                        <class name="class1"/>
                      </classes>
                    </test> <!-- TC_WORK -->
                    <test thread-count="5" name="TC_LOGIN">
                      <classes>
                        <class name="class1"/>
                        <class name="class2"/>
                      </classes>
                    </test> <!-- TC_LOGIN -->
                  </suite> <!-- App Automation Testing -->
                  
                  
                  Process finished with exit code 0
                  

                  这篇关于动态 TestNG XML 创建.获取错误的 XML.我错在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How can I detect integer overflow on 32 bits int?(如何检测 32 位 int 上的整数溢出?)
                  Local variables before return statements, does it matter?(return 语句之前的局部变量,这有关系吗?)
                  How to convert Integer to int?(如何将整数转换为整数?)
                  How do I create an int array with randomly shuffled numbers in a given range(如何在给定范围内创建一个随机打乱数字的 int 数组)
                  Inconsistent behavior on java#39;s ==(java的行为不一致==)
                  Why is Java able to store 0xff000000 as an int?(为什么 Java 能够将 0xff000000 存储为 int?)

                      <tbody id='V7RRb'></tbody>

                    <small id='V7RRb'></small><noframes id='V7RRb'>

                        <bdo id='V7RRb'></bdo><ul id='V7RRb'></ul>

                            <legend id='V7RRb'><style id='V7RRb'><dir id='V7RRb'><q id='V7RRb'></q></dir></style></legend>

                          1. <i id='V7RRb'><tr id='V7RRb'><dt id='V7RRb'><q id='V7RRb'><span id='V7RRb'><b id='V7RRb'><form id='V7RRb'><ins id='V7RRb'></ins><ul id='V7RRb'></ul><sub id='V7RRb'></sub></form><legend id='V7RRb'></legend><bdo id='V7RRb'><pre id='V7RRb'><center id='V7RRb'></center></pre></bdo></b><th id='V7RRb'></th></span></q></dt></tr></i><div id='V7RRb'><tfoot id='V7RRb'></tfoot><dl id='V7RRb'><fieldset id='V7RRb'></fieldset></dl></div>
                          2. <tfoot id='V7RRb'></tfoot>