Java Selenium-Chrome性能日志不工作
嗨,我有一个运行的selenium脚本,它应该给我性能日志。 我有一个方法“printLog”,它应该(显然)打印性能日志。我的代码将能够深入地解释我正试图做什么Java Selenium-Chrome性能日志不工作,java,selenium,selenium-chromedriver,Java,Selenium,Selenium Chromedriver,嗨,我有一个运行的selenium脚本,它应该给我性能日志。 我有一个方法“printLog”,它应该(显然)打印性能日志。我的代码将能够深入地解释我正试图做什么 static void printLog(String type, RemoteWebDriver driver, String inputURL) { ChromeOptions cap = new ChromeOptions(); LoggingPreferences logP = new LoggingPre
static void printLog(String type, RemoteWebDriver driver, String inputURL) {
ChromeOptions cap = new ChromeOptions();
LoggingPreferences logP = new LoggingPreferences();
logP.enable(LogType.PERFORMANCE, Level.ALL);
cap.setCapability(CapabilityType.LOGGING_PREFS, logP);
List<LogEntry> entries = driver.manage().logs().get(type).getAll();
System.out.println("\"Input URL\"," + "\"" + inputURL + "\"");
for (LogEntry entry : entries) {
// Checks whether this is a webtrends tag and whether it was accepted by the
// server
if (entry.getMessage().contains("statse") && entry.getMessage().contains("Network.responseReceived")) {
String statseString = entry.getMessage();
// regex for finding all wt tags: WT\..+?(?=&)
// List<String> allMatches = new ArrayList<String>();
// Matcher m = Pattern.compile("WT\\..+?(?=&)")
// .matcher(statseString);
// while (m.find()) {
// allMatches.add(m.group());
// }
int statseBegin = statseString.indexOf("\"url\":\"") + 1;
int statseEnd = statseString.indexOf("\"},\"", statseBegin);
statseString = statseString.substring(statseBegin, statseEnd);
String[] allMatches = statseString.split("&");
for (String tags : allMatches) {
tags = tags.replaceFirst("=", "ReallyLongUniqueStringWithNoChanceOfOverlap");
String tagParts[] = tags.split("ReallyLongUniqueStringWithNoChanceOfOverlap");
if (tagParts.length > 1) {
System.out.println("\"" + tagParts[0] + "\",\"" + tagParts[1] + "\"");
} else {
System.out.println("\"" + tagParts[0] + ",\"\"");
}
}
}
}
}
我可以根据请求提供更多细节,但基本上我只是想弄清楚为什么这个方法会返回这个错误。谢谢。从中,这似乎只有在使用RemoteWebDriver时才会发生。使用纯ChromeDriver对象将起作用。对于最近来此的任何人,在最新的Selenium和ChromeDriver版本(如3.14.159,chrome driver 76.x)中,使用ChromeDriver设置LoggingPref似乎不起作用,使用本地ChromeDriver-无论您做什么,您似乎都未找到
日志类型“performance”
错误
原因是在Selenium和ChromeDriver代码中对w3c规范的遵从性越来越严格
您需要像这样使用goog:loggingpresfs
功能,而不是loggingpresfs/CapabilityType.LOGGING\u PREFS
功能
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable( LogType.PERFORMANCE, Level.ALL );
options.setCapability( "goog:loggingPrefs", logPrefs );
我想Selenium方面迟早会注意到这一点,并更改CapabilityType.LOGGING\u PREFS常量或添加一个新的,但该项目似乎不太友好,无法向我记录问题。检查此讨论:是的,这是真的!非常感谢。在做出上述更改后,它对我有效。但是,我只能看到记录的是请求,而不是响应。我尝试了所有其他可用选项[浏览器、服务器、驱动程序、客户端],但仍然没有看到响应被记录下来。我是不是遗漏了什么?。感谢您的帮助。@BinnuJesudasanGudapati with
this.driver.manage().logs().get(LogType.BROWSER).getAll()
您应该会收到在浏览器控制台中可以看到的所有日志。如果这不起作用,您应该针对这一问题单独提出一个问题。看起来您目前需要选择退出w3c合规性。这只在添加了:options.setExperimentalOption(“w3c”,false)之后对我有效;他们确实通过以下提交修复了对“loggingPrefs”的支持:
ChromeOptions options = new ChromeOptions();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable( LogType.PERFORMANCE, Level.ALL );
options.setCapability( "goog:loggingPrefs", logPrefs );