0
0
Selenium Javatesting~10 mins

Performance metrics via DevTools in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable performance logging in Selenium WebDriver.

Selenium Java
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.PERFORMANCE, [1]);
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
Drag options to blanks, or click blank then click option'
ALevel.SEVERE
BLevel.OFF
CLevel.ALL
DLevel.WARNING
Attempts:
3 left
💡 Hint
Common Mistakes
Using Level.OFF disables logging, so no performance data is captured.
Using Level.SEVERE or Level.WARNING captures only errors or warnings, missing detailed metrics.
2fill in blank
medium

Complete the code to retrieve performance logs from the WebDriver.

Selenium Java
LogEntries performanceLogs = driver.manage().logs().get([1]);
Drag options to blanks, or click blank then click option'
ALogType.PERFORMANCE
BLogType.DRIVER
CLogType.BROWSER
DLogType.CLIENT
Attempts:
3 left
💡 Hint
Common Mistakes
Using LogType.BROWSER returns console logs, not performance metrics.
Using LogType.DRIVER or LogType.CLIENT returns unrelated logs.
3fill in blank
hard

Fix the error in the code to parse performance log entries correctly.

Selenium Java
for (LogEntry entry : performanceLogs) {
    String message = entry.getMessage();
    JsonObject json = JsonParser.parseString(message).getAsJsonObject();
    JsonObject [1] = json.getAsJsonObject("message");
    // process jsonMessage
}
Drag options to blanks, or click blank then click option'
AjsonEntry
BjsonMessage
CjsonLog
DjsonData
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names that do not match the JSON structure can cause confusion.
Using undefined variable names leads to compilation errors.
4fill in blank
hard

Fill in the blank to filter performance logs for 'Network.responseReceived' events.

Selenium Java
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
    }
}
Drag options to blanks, or click blank then click option'
Aequals
Bcontains
CstartsWith
DendsWith
Attempts:
3 left
💡 Hint
Common Mistakes
Using contains or startsWith might match unintended events.
Using endsWith will not match the full event name.
5fill in blank
hard

Fill all three blanks to extract the response URL and status code from performance logs.

Selenium Java
JsonObject params = jsonMessage.getAsJsonObject([1]);
JsonObject response = params.getAsJsonObject([2]);
int status = response.get([3]).getAsInt();
Drag options to blanks, or click blank then click option'
A"params"
B"response"
C"status"
D"request"
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect keys like 'request' instead of 'response' causes errors.
Missing quotes around keys leads to syntax errors.