McLover
McLover

Reputation: 31

Add console log to each step in allure report?(Java, Selenium, TestNG, Cucumber)

I need to add the console log after each test step to the allure report. I use selenium, testng, cucumber, spring boot

I tried to get logs from driver with code:

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

but it show empty mass []

Upvotes: 3

Views: 11425

Answers (1)

Rahul L
Rahul L

Reputation: 4349

With reference to your code you will need to read the 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);

Upvotes: 2

Related Questions