Qytera-Gmbh / QTAF

QTAF is a Java test framework based on TestNG and offers easy setup of Selenium and fast extensibility.
https://qytera-gmbh.github.io
MIT License
10 stars 0 forks source link

Add log message enhancing #291

Closed csvtuda closed 6 months ago

csvtuda commented 6 months ago

Adds log message customization to the TestNG event listener. It is now possible to add arbitrary information to log messages, such as Xray annotation keys:

// Old
[Test] [some.package.SomeTest.login] success
// New
[Test] [QTAF-123] [some.package.SomeTest.login] success

The logging subscriber provides a method for registering enhancers:

    /**
     * Registers a log message enhancer which will be called whenever this subscriber prints a log message.
     *
     * @param enhancer the enhancing function
     */
    public void addLogMessageEnhancer(Function<ITestResult, Optional<String>> enhancer) {
        this.logMessageEnhancers.add(enhancer);
    }

The enhancing function receives the test result object and can decide whether to add more log output:

subscriber.addLogMessageEnhancer(testResult -> {
    Method method = testResult.getMethod();
    XrayTest xrayAnnotation = method.getAnnotation(XrayTest.class);
    if (xrayAnnotation != null) {
        return Optional.of(xrayAnnotation.key());
    }
    return Optional.empty();
});