是否将控制台日志添加到吸引力报告的每个步骤?(Java,Selenium,TestNG,Cucumber)

时间:2019-07-30 13:23:54

标签: java selenium cucumber allure

我需要在每个测试步骤之后将控制台日志添加到吸引力报告中。我用硒,睾丸,黄瓜,弹簧靴

我试图通过代码从驱动程序获取日志:

Allure.addAttachment("Console log: ", String.valueOf(webDriverActions.getDriver().manage().logs().get(LogType.BROWSER).getAll()));

但显示为空质量[]

1 个答案:

答案 0 :(得分:0)

关于您的代码,您需要阅读LogEntries

   LogEntries logEntries = webDriverActions.getDriver().manage().logs().get(LogType.BROWSER);

    StringBuilder logs = new StringBuilder();


    for (org.openqa.selenium.logging.LogEntry entry : logEntries) {
        logs.append(new Date(entry.getTimestamp()) + " "
                + entry.getLevel() + " " + entry.getMessage());
        logs.append(System.lineSeparator());

    }
    System.out.println(logs);
    Allure.addAttachment("Console log: ", logs);