Skip to content

Instantly share code, notes, and snippets.

@ShamaUgale
Last active May 10, 2021 21:50
Show Gist options
  • Save ShamaUgale/0ae6bb92fc4ede7183621c7f9b22d8b9 to your computer and use it in GitHub Desktop.
Save ShamaUgale/0ae6bb92fc4ede7183621c7f9b22d8b9 to your computer and use it in GitHub Desktop.
package com.devtools;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.devtools.DevTools;
import org.openqa.selenium.devtools.log.Log;
public class CaptureConsoleLogs {
private static ChromeDriver driver;
private static DevTools chromeDevTools;
final static String PROJECT_PATH = System.getProperty("user.dir");
public static void main(String[] args){
System.setProperty("webdriver.chrome.driver", PROJECT_PATH + "/src/main/resources/chromedriver");
driver = new ChromeDriver();
chromeDevTools = driver.getDevTools();
chromeDevTools.createSession();
chromeDevTools.send(Log.enable());
chromeDevTools.addListener(Log.entryAdded(),
logEntry -> {
System.out.println("log: "+logEntry.getText());
System.out.println("level: "+logEntry.getLevel());
});
driver.get("https://testersplayground.herokuapp.com/console-5d63b2b2-3822-4a01-8197-acd8aa7e1343.php");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment