Complete the code to enable performance logging in Selenium WebDriver.
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, [1]);
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);Level.ALL enables capturing all performance logs, which is needed to collect detailed metrics.
Complete the code to retrieve performance logs from the WebDriver.
LogEntries performanceLogs = driver.manage().logs().get([1]);LogType.PERFORMANCE is used to get performance-related logs from the browser.
Fix the error in the code to parse performance log entries correctly.
for (LogEntry entry : performanceLogs) { String message = entry.getMessage(); JsonObject json = JsonParser.parseString(message).getAsJsonObject(); JsonObject [1] = json.getAsJsonObject("message"); // process jsonMessage }
The variable name jsonMessage matches the intended usage and is clear for the parsed message object.
Fill in the blank to filter performance logs for 'Network.responseReceived' events.
for (LogEntry entry : performanceLogs) { String message = entry.getMessage(); JsonObject json = JsonParser.parseString(message).getAsJsonObject(); JsonObject jsonMessage = json.getAsJsonObject("message"); if (jsonMessage.get("method").getAsString().[1]("Network.responseReceived")) { // process network response } }
We check if the 'method' exactly equals 'Network.responseReceived' to filter the correct events.
Fill all three blanks to extract the response URL and status code from performance logs.
JsonObject params = jsonMessage.getAsJsonObject([1]); JsonObject response = params.getAsJsonObject([2]); int status = response.get([3]).getAsInt();
The 'params' object contains 'response', which has the 'status' field for HTTP status code.