ATS : Configure ATS Database Logging

Introduction

We have listed here needed steps for allowing test logging to Test Explorer Database

There are 2 actual steps:

  1. Configure the Log4j system - this way we know where to send the log messages
  2. Subscribe to TestNG so we will get informed when a test is starting or ending



Configure the Log4j system

ATS uses Log4j for its logging purpose.

Log4j is configured by a file called log4j.xml placed in the root of the classpath.

Here is an example of such file:

<!DOCTYPE log4j:configuration PUBLIC
  "-//APACHE//DTD LOG4J 1.2//EN" "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/doc-files/log4j.dtd">
 
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
 
    <!-- Console appender -->
    <appender name="console" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                value="%-5p %d{HH:mm:ss} %c{2}: %m%n" />
        </layout>
        <filter class="com.axway.ats.log.autodb.filters.NoSystemLevelEventsFilter"/>
    </appender>
 
    <!-- Test Explorer DB appender -->
    <appender name="db"
        class="com.axway.ats.log.appenders.ActiveDbAppender">
        <param name="host" value="___Test Explorer server IP or Host name___" />
        <param name="database" value="___My DB name___" />
        <param name="port" value="___My DB Port___" /> <!-- Optional. The DB port to be used, 1443 if -->
        <param name="user" value="___My DB user name___" />
        <param name="password" value="___My DB user password___" />
        <param name="driver" value="mssql|jtds" /> <!-- JDBC driver to use. Optional, default value is jTDS -->
        <param name="chunkSize" value="50000" /> <!-- Set the chunk size when in batch mode. Only applicable to SQL Server log DB. Optional, the default one is 10000 -->
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%c{2}: %m%n" />
        </layout>
    </appender>
 
    <!-- Root logger configuration -->
    <root>
        <priority value="info" />
 
        <!-- Enable logging into the console -->
        <appender-ref ref="console" />
 
        <!-- Enable logging into the dedicated logging database -->
        <appender-ref ref="db" />
    </root>
 
</log4j:configuration>

You need to understand the following:

  1. Console appender
    enables logging the test results in your console. It is useful while developing your tests as you can see right away what happens during the execution of this test.
  2. DB appender
    Enables logging of test execution status and messages into the Test Explorer database. This way you can review test results via Test Explorer UI.
    1. host - where your database is located
    2. database - the name of your database
    3. port - the database port. Optional. If no port is specified, the default one for Ms SQL Server will be used - 1433.
    4. user - the database username
    5. password - the database user password
    6. driver - the JDBC driver to use for SQL Server connection (mssql or jtds (default one)). Should not be used for PostgreSQL.
    7. chunkSize - the chunk size when in batch mode. Note that this is only applicable for SQL Server log DB
  3. <root> node 
    1. enable (attach) or disable the declared appenders.
    2. sets the priority level which defines how verbose the logging will be.
      The possible options are trace, debug, info, warn, error, fatal where trace is really verbose and each next is less.


If you want to connect to a PostgreSQL database, you must specify the database port in the log4j.xml file. The default port for PostgreSQL is 5432 .

The appropriate log verbose (priority) level

In most cases, the used level is between debug and error.

DEBUG is mainly used while developing your test scenarios. At that phase, you spend a significant amount of time working with just one test, so you want more info until tweak it.

When running many tests at once you usually prefer INFO level.

If running performance tests, you may find it OK to see only messages at the level of WARN or even ERROR.

Log level and Test Explorer UI

The log level defines which messages to get into the console and Test Explorer Database. Additionally, when reviewing the results on Test Explorer UI you can filter which levels to be displayed.

You can use Console and DB appenders together or just one of them at a time.

If you want you can also add even more (for example a FILE appender) - consult with the Log4j documentation on this.



Subscribe to TestNG test execution events

You need to attach our TestNG event listener to TestNG, so we get informed when some important event has happened.

These are events telling us when a test is starting or ending. We use this information to automatically start and end RUN, SUITE and TESTCASE in the Test Explorer DB.

There are a few ways to attach this listener. In most cases, the recommended one is to have one parent class of all your test classes. If we assume this class is called BaseTest, then here is all needed to do a subscription.

import com.axway.ats.harness.testng.AtsTestngListener;

@Listeners ( { AtsTestngListener.class } )
public class BaseTest {

}

Supported TestNG Version

ATS currently recommends using TestNG version 6.10. Some newer versions have known issue when logging from @Before/After Method/Suite/etc annotated methods. Due to changes in TestNG listeners behavior, currently 7.x versions are not supported and DB logging will not work at all.

Deprecated TestNG listeners

Older TestNG listeners ( com.axway.ats.harness.testng.AtsTestngSuiteListener and com.axway.ats.harness.testng.AtsTestngTestListener ) were deprecated and are removed in future versions after 4.0.6.

Now running your test, in the very beginning you will see in the console:

*** ATS ***  2019-12-21 12:34:56.789 INFO  [QueueLoggerThread-Thread-1] logqueue.DbEventRequestProcessor: Started a new RUN in Test Explorer's database with id: 12

This tells us ATS was able to attach to the TestNG listener system and then it also created a new RUN in the database.

Now you can go to the Test Explorer UI and see the test result.



Back to parent page

Go to Table of Contents