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
Add cast RemoteWebDriver to driver initialize and you will have the .setLogLevel method:
import java.util.logging.Level;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
public class PrintLogTest {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "/Users/.../chromedriver");
WebDriver driver = new ChromeDriver();
//here
((RemoteWebDriver) driver).setLogLevel(Level.INFO);
driver.get("https://google.com/");
driver.findElement(By.name("q")).sendKeys("automation test");
driver.quit();
}
}
Example output:
Jun 15, 2020 4:27:04 PM org.openqa.selenium.remote.RemoteWebDriver log
INFO: Executing: get [430aec21a9beb6340a4185c4ea6a693d, get {url=https://google.com/}]
Jun 15, 2020 4:27:06 PM org.openqa.selenium.remote.RemoteWebDriver log
INFO: Executed: [430aec21a9beb6340a4185c4ea6a693d, get {url=https://google.com/}]
Jun 15, 2020 4:27:06 PM org.openqa.selenium.remote.RemoteWebDriver log
INFO: Executing: findElement [430aec21a9beb6340a4185c4ea6a693d, findElement {using=name, value=q}]
Jun 15, 2020 4:27:06 PM org.openqa.selenium.remote.RemoteWebDriver log
INFO: Executed: [430aec21a9beb6340a4185c4ea6a693d, findElement {using=name, value=q}]
...
...
At least I've tried it on ChromeDriver() and FirefoxDriver() and it working fine.