In this challenge, implement Selenium automation for a 3-step verification flow. Your implementation must detect when a verification failure page is shown, emit log lines from the automation (recorded on the returned report), persist captured page source under failure-reports/ only for that case, and return a FailureCaptureReport. When the flow finishes on the success view without a verification failure page, the report must state that there was no failure and must not write page source files for that path. The system uses an HtmlUnit headless browser for testing, eliminating the need for actual browser installations.
src/test/*website/*src/main/java/com/hackerrank/failurepagesourcecapture/server/**src/main/java/com/hackerrank/failurepagesourcecapture/FailureCaptureReport.javasrc/main/java/com/hackerrank/failurepagesourcecapture/AppMain.javamvn clean package -DskipTests && ...mvn clean install -DskipTestsmvn clean testImplement FailurePageSourceCaptureAutomation.java:
FailureCaptureReport runVerificationFlow(WebDriver driver, String startUrl, String email, String password, String idNumber):
Validate input arguments — driver or startUrl: null, null startUrl, or whitespace-only startUrl must throw IllegalArgumentException.
Starting from startUrl, drive the full multi-step flow using these element IDs: step-1-view, email, password, step1-continue, step-2-view, id-number, step2-continue, step-3-view, terms-accept, step3-submit. The flow ends successfully when the page shows verification-success. Wait for navigation and each step's UI to be ready before interacting; avoid relying on fixed sleeps alone where the page can load asynchronously.
On success, the report's summary must be exactly No failure case. When a verification failure page is handled, the report's summary must be exactly Verification failed; page source captured.
Capture the browser's HTML markup only when handling a verification failure page, and persist that content to the disk. Do not capture page source on the successful path. The unit tests verify that no page-source capture runs on success and that exactly one capture runs when a failure page is saved. Note: The test harness monitors all _getPageSource()_ invocations using a WebDriverListener. On failure page detection, exactly one call to _driver.getPageSource()_ is expected; do not call it multiple times in the failure capture path.
When a verification failure page is encountered: write the captured content to a new file under failure-reports/(timestamped filename). The saved file must be non-empty and must contain at least Verification Failed, a line FAILED_STEP-<step>, an Error Code: line, and a VER- error token (matching the server's failure HTML). Add log lines on the report that satisfy all of the following substrings somewhere in the combined log output:
failure is sufficient)Captured page source savedFAILED_STEP from page source (include the parsed step number in that line)The returned report must record that a failure was detected and must include the path to the file that was written.
When the flow completes with no verification failure page, do not create any regular files anywhere under failure-reports/ for that run. Include at least one log line containing the substring completed successfully. The returned report must record that no failure was detected, must not include a saved file path, and must not include any log line containing the substring Captured page source saved.
The example website is provided in the website/ folder, where you can view the structure and UI. Your task is to complete the implementation of this method so that all unit tests pass successfully.
Boilerplate code
package com.hackerrank.failurepagesourcecapture;
import java.util.regex.Pattern;
import org.openqa.selenium.WebDriver;
/**
* Complete implementation: automate the 3-step verification flow and capture failure page source when
* the server returns a verification failure page.
*/
public final class FailurePageSourceCaptureAutomation {
private static final Pattern FAILED_STEP_PATTERN = Pattern.compile("FAILED_STEP-(\\d+)");
private FailurePageSourceCaptureAutomation() {}
/**
* Run the full verification flow starting at {startUrl}.
*
* <p>On a verification failure page, this method must log that a failure occurred, capture the page source exactly once
* for that failure handling, persist HTML under
* failure-reports/, and record paths and messages in the returned FailureCaptureReport.
*
* <p>When the flow completes on the success page without seeing a failure page, do not perform any capture; return a
* report whose summary indicates no failure case.
*/
public static FailureCaptureReport runVerificationFlow(
WebDriver driver, String startUrl, String email, String password, String idNumber) {
// Write your code here
throw new UnsupportedOperationException("Not implemented");
}
}
Arista • Pending
Arista • Pending
BlackRock • Pending
BlackRock • Pending