Testing / Selenium Interview questions
How do you generate test reports in Selenium (e.g., with ExtentReports)?
Selenium itself has no reporting layer, so reports typically come from a separate library like ExtentReports, hooked into the test framework's lifecycle listeners.
ExtentReports extent = new ExtentReports(); ExtentSparkReporter spark = new ExtentSparkReporter("report.html"); extent.attachReporter(spark); ExtentTest test = extent.createTest("Login Test"); test.pass("Login succeeded"); extent.flush();
A TestNG ITestListener or JUnit extension is commonly used to automatically log a pass/fail entry - and attach a screenshot on failure - for every test method, rather than sprinkling report calls manually throughout test bodies. extent.flush() must be called at the end of the run to actually write the accumulated results out to the HTML file; forgetting it produces an empty or incomplete report despite the tests having run correctly.
More Related questions...