Capturing browser logs with Selenium WebDriver using Java

后端 未结 9 2021
闹比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:46

    A less elegant solution is taking the log 'manually' from the user data dir:

    1. Set the user data dir to a fixed place:

      options = new ChromeOptions();
      capabilities = DesiredCapabilities.chrome();
      options.addArguments("user-data-dir=/your_path/");
      capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      
    2. Get the text from the log file chrome_debug.log located in the path you've entered above.

    I use this method since RemoteWebDriver had problems getting the console logs remotely. If you run your test locally that can be easy to retrieve.

提交回复
热议问题