Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium 我没有通过编程TestNG获得所有已执行测试用例的报告_Selenium_Selenium Webdriver_Testng - Fatal编程技术网

Selenium 我没有通过编程TestNG获得所有已执行测试用例的报告

Selenium 我没有通过编程TestNG获得所有已执行测试用例的报告,selenium,selenium-webdriver,testng,Selenium,Selenium Webdriver,Testng,我已经创建了TestNG对象,并使用它来执行测试用例 if(parameters.getValue().ExecutionType.equalsIgnoreCase(“是”)){ //这是通过excel文件发送的,该文件被标记为testcase名称的标志 package ForNewFramework; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.

我已经创建了TestNG对象,并使用它来执行测试用例

if(parameters.getValue().ExecutionType.equalsIgnoreCase(“是”)){ //这是通过excel文件发送的,该文件被标记为testcase名称的标志

package ForNewFramework;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.testng.TestListenerAdapter;
import org.testng.TestNG;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

public class CustomizeSuitetorunTestNG {

    public static void main(String[] args) {

        XmlSuite suite = new XmlSuite();

        suite.setName("TmpSuite");
        XmlTest test = new XmlTest(suite);
         test.setName("TmpTest");

        GetExcelInMap object  = new GetExcelInMap();
        try {
            Map<String, SetterGetterOfExcelValue> SuitParameters = object.getExcel();


        for(Map.Entry<String, SetterGetterOfExcelValue> parameters: SuitParameters.entrySet())
        {


        String ClassName = "ForNewFramework."+parameters.getValue().getTestCaseName();


        if(parameters.getValue().ExecutionType.equalsIgnoreCase("Yes"))  
        {

          List<XmlClass> classes = new ArrayList<XmlClass>();
          classes.add(new XmlClass(ClassName));
          test.setXmlClasses(classes) ;

          List<XmlSuite> suites = new ArrayList<XmlSuite>();
          suites.add(suite);
          TestNG tng = new TestNG();
          tng.setXmlSuites(suites);
          tng.run();
        }

        }
        }
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
    }

This my class which is running testng.
I am creating the object of this class "GetExcelInMap" where i am getting the data from excel and saved to the variables by using setter and getter method.

In Class CustomizeSuiterun:
I am running three classes from the package name "ForNewFramework", where the names of the classes and in excel both are same so i am loading the names of the classes from excel.

My testng.xml created like this in index.html:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
    <suite name="TmpSuite">
      <test name="TmpTest">
        <classes>
          <class name="ForNewFramework.ThirdTestCase"/>
        </classes>
      </test> <!-- TmpTest -->
    </suite> <!-- TmpSuite -->
newframework包;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.Map;
导入org.testng.TestListenerAdapter;
导入org.testng.testng;
导入org.testng.xml.XmlClass;
导入org.testng.xml.XmlSuite;
导入org.testng.xml.XmlTest;
公共类CustomizeSuiteRunTestNG{
公共静态void main(字符串[]args){
XmlSuite=newxmlsuite();
套件名称(“TmpSuite”);
XmlTest=新的XmlTest(套件);
测试集名称(“TmpTest”);
GetExcelInMap对象=新建GetExcelInMap();
试一试{
Map SuitParameters=object.getExcel();
对于(Map.Entry参数:suiteParameters.entrySet())
{
String ClassName=“ForNewFramework。”+parameters.getValue().getTestCaseName();
if(parameters.getValue().ExecutionType.equalsIgnoreCase(“是”))
{
列表类=新的ArrayList();
add(新的XmlClass(ClassName));
test.setXmlClasses(类);
列表套件=新的ArrayList();
套房。添加(套房);
TestNG tng=新的TestNG();
tng.setXmlSuites(套房);
tng.run();
}
}
}
捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
}
}
这是我运行testng的类。
我正在创建这个类“GetExcelInMap”的对象,在这里我从excel中获取数据,并使用setter和getter方法保存到变量中。
类内定制套件:
我从包名“ForNewFramework”运行三个类,其中类的名称和excel中的名称都相同,因此我从excel加载类的名称。
在index.html中创建的My testng.xml如下所示:
这里,执行了我的第一个和第二个测试,但在报告中,只提到了最后执行的类。第二个类和第一个类的执行报告被第三个类的执行覆盖

它完美地执行脚本。 我使用的是TestNG的默认报告,在excel中将标记设为“是”时,我不会得到所有已执行测试用例的报告。 我只在index.hmtl文件中获取最后一个类文件的输出,该类文件通过编程TestNG在最后一个类文件中执行。 你能建议我怎样才能得到所有在标志中标记为是的测试用例的报告吗


请让我知道,我能够向您提供适当的代码或所需的信息,以便您能够帮助我。

我认为问题在于您在添加类后立即运行它。您需要添加所有类,然后在最后运行。因此,它正在执行3个单独的xml套件。您需要进行运行圈外

     if(parameters.getValue().ExecutionType.equalsIgnoreCase("Yes"))  
            {

              List<XmlClass> classes = new ArrayList<XmlClass>();
              classes.add(new XmlClass(ClassName));
              test.setXmlClasses(classes) ;

              List<XmlSuite> suites = new ArrayList<XmlSuite>();
              suites.add(suite);


            }

            }


       TestNG tng = new TestNG();
                  tng.setXmlSuites(suites); 
tng.run();      
 }
if(parameters.getValue().ExecutionType.equalsIgnoreCase(“是”))
{
列表类=新的ArrayList();
add(新的XmlClass(ClassName));
test.setXmlClasses(类);
列表套件=新的ArrayList();
套房。添加(套房);
}
}
TestNG tng=新的TestNG();
tng.setXmlSuites(套房);
tng.run();
}

进行必要的更改,因为您必须在循环外声明套件。

您能提供更多代码吗?例如,我希望看到包含所有“是”测试的循环:)是的,您完全正确。此外,我还从“If”条件和循环中删除了“Array list”。列表类=新的ArrayList();非常感谢(y):@Pratekshrivastava。NP