private static synchronized void setKlovReport ( ) { if ( extentReports == null ) { //Extent reports object not found. call setExtentReport() first return ; } ExtentProperties extentProperties = ExtentProperties . INSTANCE ; //if reporter is not null that means it is already attached if ( klovReporter != null ) { //Already attached, attaching it again will create a new build/klov report return ; } if ( extentProperties . getKlovServerUrl ( ) != null ) { String hostname = extentProperties . getMongodbHost ( ) ; int port = extentProperties . getMongodbPort ( ) ; String database = extentProperties . getMongodbDatabase ( ) ; String username = extentProperties . getMongodbUsername ( ) ; String password = extentProperties . getMongodbPassword ( ) ; try { //Create a new KlovReporter object klovReporter = new KlovReporter ( ) ; if ( username != null && password != null ) { MongoClientURI uri = new MongoClientURI ( "mongodb://" + username + ":" + password + "@" + hostname + ":" + port + "/?authSource=" + database ) ; klovReporter . initMongoDbConnection ( uri ) ; } else { klovReporter . initMongoDbConnection ( hostname , port ) ; } klovReporter . setProjectName ( extentProperties . getKlovProjectName ( ) ) ; klovReporter . setReportName ( extentProperties . getKlovReportName ( ) ) ; klovReporter . setKlovUrl ( extentProperties . getKlovServerUrl ( ) ) ; extentReports . attachReporter ( klovReporter ) ; } catch ( Exception ex ) { klovReporter = null ; throw new IllegalArgumentException ( "Error setting up Klov Reporter" , ex ) ; } } }
When running cucumber tests in parallel Klov reporter should be attached only once in order to avoid duplicate builds on klov server .