XmlTest中含有group, package, classes
创新互联专注于三亚企业网站建设,响应式网站开发,商城系统网站开发。三亚网站建设公司,为三亚等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务初始化XmlClass,包含method, include, exclude
public class RunWithTestNgXml {
public static void main(String[] args) {
//Receive the arguments from command including groups, classes, package and so on
MapnodeValues = parseArgs(args);
ListxmlSuites = new ArrayList();
try {
//Could execute multiple suites
xmlSuites.add(getXmlSuite(nodeValues));
//Execute testng suites
TestNG testNG = new TestNG();
testNG.setXmlSuites(xmlSuites);
testNG.run();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
//Generate XmlSuite
private static XmlSuite getXmlSuite() throws ClassNotFoundException {
XmlSuite suite = new XmlSuite();
suite.setName("Suites");
suite.setConfigFailurePolicy(XmlSuite.FailurePolicy.CONTINUE);
//Set parallel as class
suite.setParallel(XmlSuite.ParallelMode.CLASSES);
//Set thread as 1
suite.setThreadCount(1);
//Set suite parameters
MapsuiteParams = generateSuiteMap();
suite.setParameters(suiteParams);
//Set test
ListxmlTests = getXmlTests(suite);
suite.setTests(xmlTests);
//if needed, also can write as testng.xml file
writeTestNgXml(suite);
return suite;
}
//Generate XmlTests
private static ListgetXmlTests(XmlSuite suite) {
ListxmlTestsList = new ArrayList();
XmlTest xmlTest = new XmlTest();
xmlTest.setName("Test");
xmlTest.setXmlSuite(xmlSuite);
//Set groups
Listgroups;
xmlTest.setIncludeGroups(groups);
//Set Packages
ListxmlPackages = new ArrayList();
xmlTest.setXmlPackages(xmlPackages);
//Set Classes
ListxmlClassList = new ArrayList();
xmlTest.setXmlClasses(xmlClassList);
xmlTestsList.add(xmlTest);
return xmlTestsList;
}
//Write testng.xml to disk
private static void writeTestNgXml(XmlSuite suite) {
String xmlStr = suite.toXml();
FileWriter writer = null;
try {
writer = new FileWriter( new File(C:/testng.xml"), false);
writer.write(xmlStr);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
writer.flush();
writer.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
四、执行使用command 执行main方法
cd {workspace}/build/libs/
java -cp {project}.jar com...RunWithTestNgXml groups=smoke,P0,test classes=${CLASSES} packages=${PACKAGES}
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
文章名称:使用TestNG的XmlSuite类动态生成testng.xml文件-创新互联
文章URL:https://www.cdcxhl.com/article10/dhijdo.html
成都网站建设公司_创新互联,为您提供网站排名、网站制作、Google、静态网站、自适应网站、软件开发
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联