更好的方法可能是从Java代码中获取return a Map back to Karate,并提供记录所需的所有信息 . 然后,您需要做的就是使用print关键字 . 我实际上会推荐这种方法,它应该不那么复杂,并且它不假设您使用的是Cucumber HTML报告 . 您甚至可以使用JSON上的 match 关键字执行Karate断言,请参阅此示例:dogs.feature .
public void myTestMethod() {
logger.info("Starting Test");
logger.info("Setting path of chrome driver");
System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); //driver doesnt exist in this path
logger.info("invoking chrome"); // we would expect the exception to be thrown after this line
driver = new ChromeDriver();
logger.info("perform search in google");
driver.get("http://www.google.com");
driver.findElement(By.id("lst-ib")).sendKeys("Selenium");
driver.findElement(By.id("lst-ib")).submit();
driver.quit();
}
2 回答
如果你使用空手道parallel runner它被设计为收集记录到包com.intuit.karate的任何东西,然后它将出现在cucumber-html-report中 .
所以你可以尝试using the same slf4j Logger - 它可能会起作用 .
更好的方法可能是从Java代码中获取return a Map back to Karate,并提供记录所需的所有信息 . 然后,您需要做的就是使用print关键字 . 我实际上会推荐这种方法,它应该不那么复杂,并且它不假设您使用的是Cucumber HTML报告 . 您甚至可以使用JSON上的
match
关键字执行Karate断言,请参阅此示例:dogs.feature .我们确实尝试回溯到“com.intuit.karate”,如下所示,并记录到'overview-features.html'报告
Java类中的 Logger :
private static final Logger logger = LoggerFactory.getLogger(“com.intuit.karate”);
但是我们观察到,如果从java类抛出异常,则首先出现异常,然后记录所有记录的信息,两者看起来都作为报表中的不同部分存在 .
例如
这是我在java类中使用logger的示例方法,我从功能文件中调用它
但是在报告中首先出现异常,然后出现从java类中记录的所有信息 . 两者在报告中看起来都是两个不同的部分,请在此处查看报告https://www.screencast.com/t/bBhAIj7WKj
在上面的情况下,可以在我们记录“调用Chrome”的行之后抛出异常,我认为这样可以更容易地从报告中识别测试失败 . 如果可能的话,请告诉我们