如何在java主方法中添加testng参数?

如何在java主方法中添加testng参数?,java,selenium,testng,appium,ui-automation,Java,Selenium,Testng,Appium,Ui Automation,我想从java主方法而不是testng.xml文件触发执行 我的疑问是如何将参数添加到Java主方法中以执行。我已找到.addListener和.setGroups分别添加listener和组,但无法找到添加参数的方法 请帮助我通过java main方法开始执行 样本: public class Execution { public static void main(String[] args) throws IOException { TestNG test = new

我想从java主方法而不是testng.xml文件触发执行

我的疑问是如何将参数添加到Java主方法中以执行。我已找到.addListener和.setGroups分别添加listener和组,但无法找到添加参数的方法

请帮助我通过java main方法开始执行

样本:

public class Execution {
    public static void main(String[] args) throws IOException {
        TestNG test = new TestNG();
        test.setTestClasses(new Class[] {AETVTests.class});
        test.addListener(new MyTestListenerAdapter());
        test.setGroups("");
        test.run();
    }
}

您可以通过arg[0]访问args,类似地,arg[1]也可以访问args。在cmd中运行您的jar文件>
java-jar classname.jar param1 param2

如果您想重新考虑使用xml,您还可以使用xml文件通过main方法触发执行。将testng.xml文件添加到您的项目路径中(在eclipse中,您可以右键单击project-new-file-testng.xml),这将起作用:

public static void main(String[] args) throws IOException
{
    TestNG testng = new TestNG();

    List<String> suites = Lists.newArrayList();
    suites.add("C:\\eclipse-2018\\Tests\\testng.xml");  //path to xml
    testng.setTestSuites(suites);

    testng.run(); //run TestNG   
}
publicstaticvoidmain(字符串[]args)引发IOException
{
TestNG TestNG=新的TestNG();
List suites=Lists.newArrayList();
suites.add(“C:\\eclipse-2018\\Tests\\testng.xml”);//指向xml的路径
testng.setTestSuites(套房);
testng.run();//运行testng
}

我没有在jar中运行。我正在尝试从java主类运行测试。您使用什么来运行该程序。管道将使用参数运行该程序。