Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Needs to log Console Log At Info Level #2519

Closed
TalatiShirish opened this issue Jul 27, 2021 · 2 comments
Closed

Needs to log Console Log At Info Level #2519

TalatiShirish opened this issue Jul 27, 2021 · 2 comments

Comments

@TalatiShirish
Copy link

Hi Team,

I would like to log browser console log at info level.
So far I have used
List logs=getDriver().manage.logs().get(LogType.BROWSER).getAll();

But this only gets the log at WARNING and SEVER level logs.

Any document link or demo of the project or tips please.

I can see in the browser console logs ,,
image
but not able to captrue by the above steps.

@globalworming
Copy link
Collaborator

i some time ago had something like

private void waitAssertAndPrintErrorLogs() {
    new CurrentPage().waitFor(5).seconds();
    List<LogEntry> logEntries = new SevereConsoleLogs().answeredBy(newUser);
    then(newUser).should("there should be no error logs in the console" ,
        eventually(seeThat(actor -> logEntries, List::isEmpty)).orComplainWith(
            AssertionError.class, "severe logs:\n" + logEntries.stream()
            .map(entry -> entry.toString() + "\n")
            .collect(Collectors.joining())
    ));
  }

with

public class SevereConsoleLogs extends QuestionWithDefaultSubject<List<LogEntry>> {
  @Override
  public List<LogEntry> answeredBy(Actor actor) {
    if (BrowseTheWeb.as(actor).getDriver().manage().logs().getAvailableLogTypes() == null) {
      // means a previous step by the actor already failed
      return Collections.emptyList();
    }

    return BrowseTheWeb.as(actor).getDriver().manage().logs().get(LogType.BROWSER).getAll().stream()
            .filter(e -> e.getLevel().equals(Level.SEVERE)).collect(Collectors.toList());
  }
}

changing that Level.SEVERE to Level.INFO should work. Maybe check https://stackoverflow.com/a/25431419/1359903 regarding setting up the driver

@TalatiShirish
Copy link
Author

Hi, Thanks for reply. I did try that but still I am only getting the SEVERE and WARNING LEVEL logs only.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants