QA
Mid-level QAFrameworks & Design PatternsFree question

How do you implement reporting and logging in your framework?

60-second answer

For reporting I use Allure or Extent Reports, integrated through TestNG listeners, so every test automatically gets its status, steps, duration, a screenshot on failure, and environment details, without code in each test. Allure also shows history and trends across CI runs. For logging I use Log4j2 or SLF4J with Logback, writing step-level logs to the console and to a file per run, and attaching logs to the report. Good reports let anyone, including developers and managers, understand a failure without rerunning the test.

Explanation

What a useful report contains:

  • Test name, description, story/Jira ID, group/tags.
  • Steps (Allure @Step on page methods).
  • Screenshot, page source, browser console logs and network HAR on failure.
  • API request/response for API tests.
  • Environment, browser, build number.
  • Trends: pass rate, flaky tests, duration.

Logging levels: DEBUG for detailed steps, INFO for test flow, WARN for retries, ERROR for failures.

Example

After adding Allure with screenshots and API logs, developers stopped asking QA to reproduce CI failures; they opened the report link posted in Slack.

Sample code

public class CartPage extends BasePage {
    private static final Logger log = LogManager.getLogger(CartPage.class);

    @Step("Apply coupon {code}")
    public CartPage applyCoupon(String code) {
        log.info("Applying coupon {}", code);
        type(couponInput, code);
        click(applyBtn);
        return this;
    }
}

// In a listener on failure:
Allure.addAttachment("Screenshot", new ByteArrayInputStream(
    ((TakesScreenshot) DriverManager.get()).getScreenshotAs(OutputType.BYTES)));