Bird
Raised Fist0
Selenium Javatesting~20 mins

Performance metrics via DevTools in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
DevTools Performance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Understanding DevTools Performance Metrics Retrieval
What will be the output of the following Java Selenium code snippet that uses Chrome DevTools Protocol to get the page load time metric?

Assume the page fully loads and metrics are available.
Selenium Java
DevTools devTools = driver.getDevTools();
devTools.createSession();

Map<String, Object> metrics = devTools.send(Page.getMetrics());
System.out.println(metrics.get("Timestamp"));
APrints a double value representing the timestamp in seconds since navigation start
BPrints a string with the page title
CThrows a NullPointerException because getMetrics() returns null
DPrints an integer representing the number of metrics collected
Attempts:
2 left
💡 Hint
Think about what the 'Timestamp' metric represents in DevTools metrics.
❓ assertion
intermediate
2:00remaining
Correct Assertion for Page Load Time Metric
Which assertion correctly verifies that the page load time metric 'DomContentLoaded' is less than 5 seconds using JUnit in Selenium with DevTools?
Selenium Java
DevTools devTools = driver.getDevTools();
devTools.createSession();
Map<String, Object> metrics = devTools.send(Page.getMetrics());
Double domContentLoaded = (Double) metrics.get("DomContentLoaded");
AassertFalse(domContentLoaded > 5);
BassertEquals(5, domContentLoaded, 0.1);
CassertTrue(domContentLoaded < 5, "DomContentLoaded should be less than 5 seconds");
DassertNotNull(domContentLoaded);
Attempts:
2 left
💡 Hint
You want to check if the value is less than 5 seconds.
🔧 Debug
advanced
2:00remaining
Debugging DevTools Session Creation Failure
You run the following Selenium Java code to start a DevTools session but get an IllegalStateException: "No active session found". What is the most likely cause?
Selenium Java
DevTools devTools = driver.getDevTools();
// Missing devTools.createSession();
Map<String, Object> metrics = devTools.send(Page.getMetrics());
AThe driver instance is null
BYou forgot to call devTools.createSession() before sending commands
CPage.getMetrics() is deprecated and cannot be used
DYou need to cast the driver to ChromeDriver first
Attempts:
2 left
💡 Hint
DevTools commands require an active session.
🧠 Conceptual
advanced
2:00remaining
Understanding Performance Metrics Collection Timing
When using Selenium with Chrome DevTools Protocol to collect performance metrics, at what point is it best to capture the metrics to get accurate page load performance data?
AAfter waiting for the 'load' event or a specific element to be visible
BBefore calling driver.get(url)
CImmediately after driver.get(url) returns
DAfter closing the browser
Attempts:
2 left
💡 Hint
Think about when the page is fully loaded and metrics are stable.
❓ framework
expert
2:00remaining
Integrating DevTools Performance Metrics in Test Framework
You want to integrate Chrome DevTools performance metrics collection into a JUnit 5 Selenium test framework. Which approach ensures metrics are collected for each test and reported properly?
ACollect metrics after driver.quit() in @AfterAll method
BCollect metrics once in a static block before all tests run
CCollect metrics only in the first test method and reuse for others
DCreate a @BeforeEach method to start DevTools session and a @AfterEach method to collect and log metrics
Attempts:
2 left
💡 Hint
Think about test isolation and per-test reporting.

Practice

(1/5)
1. What is the main purpose of using DevTools performance metrics in Selenium Java tests?
easy
A. To handle browser alerts automatically
B. To locate elements on the web page
C. To take screenshots during test execution
D. To measure page load speed and browser performance

Solution

  1. Step 1: Understand DevTools role in Selenium

    DevTools integration allows Selenium to collect browser performance data like load times.
  2. Step 2: Identify the purpose of performance metrics

    Performance metrics help measure page speed and resource usage to improve user experience.
  3. Final Answer:

    To measure page load speed and browser performance -> Option D
  4. Quick Check:

    Performance metrics = page speed measurement [OK]
Hint: Performance metrics measure speed, not element location [OK]
Common Mistakes:
  • Confusing performance metrics with element locators
  • Thinking DevTools handles alerts
  • Assuming screenshots are related to performance
2. Which Java code snippet correctly enables performance monitoring using DevTools in Selenium?
easy
A. devTools.send(Performance.enable());
B. driver.get("https://example.com");
C. driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10));
D. devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty()));

Solution

  1. Step 1: Identify the correct DevTools command for performance

    The Performance domain in DevTools is enabled by calling Performance.enable().
  2. Step 2: Check other options for correctness

    devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.empty())); enables Network, not Performance. driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(10)); sets timeout, and B loads a page.
  3. Final Answer:

    devTools.send(Performance.enable()); -> Option A
  4. Quick Check:

    Enable performance with Performance.enable() [OK]
Hint: Use Performance.enable() to start performance monitoring [OK]
Common Mistakes:
  • Using Network.enable() instead of Performance.enable()
  • Confusing timeout settings with performance enabling
  • Calling driver.get() instead of enabling metrics
3. Given the following code snippet, what will be the output type of metrics.getMetrics()?
DevTools devTools = driver.getDevTools();
devTools.createSession();
devTools.send(Performance.enable());
PerformanceMetrics metrics = devTools.send(Performance.getMetrics());
System.out.println(metrics.getMetrics().get(0).getName());
medium
A. A boolean indicating if metrics are enabled
B. An integer value of the first metric
C. A String representing the name of the first performance metric
D. A list of WebElement objects

Solution

  1. Step 1: Understand Performance.getMetrics() return type

    It returns a PerformanceMetrics object containing a list of Metric objects, each with a name and value.
  2. Step 2: Analyze metrics.getMetrics().get(0).getName()

    This accesses the first Metric's name, which is a String describing the metric.
  3. Final Answer:

    A String representing the name of the first performance metric -> Option C
  4. Quick Check:

    getName() returns String metric name [OK]
Hint: getName() returns metric name as String, not value [OK]
Common Mistakes:
  • Assuming getName() returns a number
  • Confusing metrics with WebElements
  • Expecting a boolean from getMetrics()
4. Identify the error in this Selenium Java code snippet that tries to enable performance metrics:
DevTools devTools = driver.getDevTools();
devTools.send(Performance.enable());
devTools.createSession();
medium
A. Performance.enable() requires parameters
B. createSession() must be called before sending commands
C. DevTools cannot be used with ChromeDriver
D. No error, code is correct

Solution

  1. Step 1: Check the order of DevTools commands

    Session must be created before sending any DevTools commands like Performance.enable().
  2. Step 2: Verify method usage

    Calling Performance.enable() before createSession() causes an error because no session exists yet.
  3. Final Answer:

    createSession() must be called before sending commands -> Option B
  4. Quick Check:

    Call createSession() first, then enable performance [OK]
Hint: Always createSession() before sending DevTools commands [OK]
Common Mistakes:
  • Calling enable() before createSession()
  • Thinking Performance.enable() needs parameters
  • Assuming DevTools is unsupported in ChromeDriver
5. You want to measure the page load time using Selenium Java and DevTools. Which approach correctly captures the 'DomContentLoaded' metric after page load?
hard
A. Enable performance, load page, then get metrics and filter for 'DomContentLoaded'
B. Load page first, then enable performance and get metrics immediately
C. Enable performance, get metrics before loading page, then load page
D. Only use driver.manage().timeouts().pageLoadTimeout() to measure load time

Solution

  1. Step 1: Enable performance monitoring before page load

    Performance must be enabled before loading the page to capture all metrics during load.
  2. Step 2: Load the page and then retrieve metrics filtering for 'DomContentLoaded'

    After page load, get metrics and select the 'DomContentLoaded' metric to measure load time.
  3. Final Answer:

    Enable performance, load page, then get metrics and filter for 'DomContentLoaded' -> Option A
  4. Quick Check:

    Enable first, load page, then get metrics [OK]
Hint: Enable before load, get metrics after load for accurate timing [OK]
Common Mistakes:
  • Enabling performance after page load misses metrics
  • Getting metrics before loading page
  • Relying only on timeout settings for load time
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard