如何在从控制台输入后触发testng文件的执行

时间:2016-01-07 10:42:37

标签: java xml maven selenium testng

我在pom.xml文件中有不同的测试套件。

我希望在运行每个testng套件文件后从控制台提供用户输入,以触发pom.xml中下一个testng文件的执行。

例如:我的pom.xml文件包含3个testng文件,如下所示。 testng1.xml testng2.xml testng2.xml 在执行testng1.xml文件之后,testng2.xml的执行应该在我给出输入之后才开始(就像从键盘按任意键一样)。

如何在selenium webdriver(页面对象模型),java,testng,maven框架中实现这一点。

2 个答案:

答案 0 :(得分:1)

我得到了这个答案的解决方案。

我在testT.xml文件的@Test中使用了scanner对象,我希望“等到”用户从控制台提供输入。在这种情况下,测试的执行会一直等到用户将输入提供给控制台。

示例代码。

@Test(priority=20)
public void testInputFromConsoleToContinue_XX1(){
    System.out.println("Click any key and 'enter' key in Console to continue the tests..");
    Scanner scan = new Scanner(System.in);
    String line = scan.nextLine();
    System.out.println("continue the tests " + line);
}

答案 1 :(得分:0)

您可以使用以下内容:

<强>的pom.xml

<configuration>
    <suiteXmlFiles>
        <suiteXmlFile>${file.name}</suiteXmlFile>
    </suiteXmlFiles>
</configuration>

从命令行运行:

mvn test -Dfile.name=path of testng<i>.xml