Capturing browser logs with Selenium WebDriver using Java

后端 未结 9 1991
闹比i
闹比i 2020-11-28 03:01

Is there a way to capture browser logs while running automated test cases with Selenium? I found an article on how to capture JavaScript errors in Selenium. But that is just

9条回答
  •  清酒与你
    2020-11-28 03:50

    Adding LoggingPreferences to "goog:loggingPrefs" properties with the Chrome Driver options can help to fetch the Browser console logs for all Log levels.

    ChromeOptions options = new ChromeOptions();    
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    options.setCapability("goog:loggingPrefs", logPrefs);
    WebDriver driver = new ChromeDriver(options);
    

提交回复
热议问题