【发布时间】:2020-02-25 09:39:20
【问题描述】:
我是 testng + maven 的新手,我需要使用可运行的 jar 来运行脚本。该套件需要为多个区域执行。区域名称在执行 jar 时作为参数传递。 现在我的要求是根据提供的区域名称在多个 testng.xml 文件之间切换。 所有的 testng.xml 文件都放在资源文件夹 --> "resources/testngA.xml" 和 "resources/testngB.xml" 中。 当我从 eclipse 运行脚本时,它工作正常,但是当我尝试通过 runnable.jar 执行相同的脚本时,它显示 java.io.FileNotFoundException 异常。谁能帮我解决这个问题。
public class TestRunner {
static TestNG testng;
static List<String> suites;
public static void main(String[] args) {
String xmlFileName = "";
List<XmlSuite> suite;
String region = arg[0];
try
{
if(region.equals("A")){
xmlFileName = "resources/A_TestNG.xml";
}else if(region.equals("B")){
xmlFileName = "resources/B_TestNG.xml";
}else{
System.out.println("No matching region found")
}
suite = (List <XmlSuite>)(new Parser(xmlFileName).parse());
testng.setXmlSuites(suite);
testng.run();
}
catch (ParserConfigurationException e)
{
e.printStackTrace();
}
catch (SAXException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
【问题讨论】: