如何在TestNG(Selenium with Java)中运行测试套件后收集所有System.out.print(“”)结果

问题描述 投票:1回答:1

我正在运行一个测试套件,其中包含用Java编写的TestNG测试用例。我正在使用xml文件在eclipse IDE中运行该套件。每个测试用例都有几个System.out.print(“”)命令来在屏幕上打印一些东西。有没有办法从控制台收集所有这些结果并在测试套件完成后创建文件?

例如:来自2个独立TC的部分:

    //Go to Pricing -->  Scenarios --> Quick Price Scenario 
    driver.get(variables.portalURL + "Portal/Pricing/QuickPrice"); 

    String QP = driver.findElement(By.cssSelector("div.widget-header > h3")).getText();
     if ((QP.equals("Quick Price Scenario"))==true)
     {System.out.println("\nQuick Price Scenario page loaded");
    }
     else  System.out.println("\nQuick Price Scenario page did not load"); 

     //Custom, QP, and Pipeline Go to Pricing -->  Scenarios --> Custom Scenario 
      driver.get(variables.portalURL + "Portal/Pricing/CustomScenario");   
      String CS = driver.findElement(By.cssSelector("div.widget-header > h3")).getText();
      if ((CS.equals("Custom Scenario"))==true)
      {System.out.println("\nCustom Scenario page loaded");    
 }
     else  System.out.println("\nCustom Scenario page did not load"); 

输出将加载Quick Price Scenario页面。并加载了自定义方案页面(假设两者都是真的)。还会有更多。有没有办法在执行完成后在一个文件中收集所有这些?

java selenium testng
1个回答
1
投票

不,没有办法收集传递给System.out.println(...)的参数 - 该方法会将您的参数转发给stdout,而不会将它们保存在任何地方。

你有没有想过使用TestNG Reporter?这将包括TestNG创建的HML报告中的所有输出。

另一种可能性是使用像log4j这样的日志框架 - 然后你必须用System.out.println("...")或你想要的任何其他日志级别替换每次调用log.info(...)

© www.soinside.com 2019 - 2024. All rights reserved.