Geb: Writing report file for test failure - maven

Geb is taking screen shots as .png file and DOM elements as a html file in the configured report directory while executing test cases.
I need also to write the test failure details like below in a file because I have to submit the failure result:
title == "SomeTitleHere"
| |
| false
SomeAnotherTitleHere
How can I achieve this or what is the best way to do it?

At last I found a good solution on writing test failure details in an HTML format.
As I created the project as a Maven project in Eclipse[Mars], adding the following dependency in pom.xml will create the .html report files in the build directory.
<dependency>
<groupId>com.athaydes</groupId>
<artifactId>spock-reports</artifactId>
<version>1.2.12</version>
<scope>test</scope>
<!-- this avoids affecting your version of Groovy/Spock -->
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- // if you don't already have slf4j-api and an implementation of it in the classpath, add this! -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.13</version>
<scope>test</scope>
</dependency>

Related

How to fix "No suitable Log implementation" in Quarkus

I have a Quarkus application using native compilation, and when I try to log anything I get the error:
Exception message: org.apache.commons.logging.LogConfigurationException: No suitable Log implementation
How can I fix this?
You could alternatively use:
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-apache-httpclient</artifactId>
</dependency>
It causes it to package httpclient with logging that works with Quarkus.
Based on the discussion here I used the dependency tree generated by ./mvnw dependency:tree | grep -B 4 "commons-logging" to find the classes that imported the Apache logging libraries. It turns out for me it was the HTTP client, so I needed to exclude those with this in the pom.xml file:
<dependency>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents</groupId>
<version>4.5.13</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.30</version>
</dependency>
This config was provided by this answer.

TinyLog v2 with multimodule maven project spring-boot

Hi I have a multimodule springboot based project and I would like to keep logging separate for each module.
I am using tiny log 2, but the issue I am facing is that, when there is a stack trace thrown, it is not getting captured in my rolling log file.
Here is the tinyLog configuration:
exception = strip: jdk.internal
writer = file
writer.format = {date} [{class}] {level}: {message}
writer.file = log.txt
In this way, when there is no error, I see proper logging. But purposefully I gave wrong mysql connection properties, and then I see whole bunch of error logs on console but on the log file I see only debug, info logs.
This is likely due to one of the following two causes:
1) The Maven Configuration is Incomplete
For using tinylog instead of Logback, which is the default logging back-end of Spring Boot, you have to exclude Spring Boot's logging dependencies and replace them with the corresponding tinylog artifacts:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>tinylog-impl</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>slf4j-tinylog</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>jcl-tinylog</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.tinylog</groupId>
<artifactId>log4j1.2-api</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
(Copied from https://github.com/pmwmedia/tinylog-spring-boot-example/blob/v2/pom.xml)
2) Exception is not Output via a Logger
Have you checked that the exception is logged via a logger (e.g. Logger.error(ex)) and not printed via ex.printStackTrace() directly to the console? tinylog (and any other logging framework) can only write log entries into files, if these log entries are issued via logging API.
If none of both suggestions fix the issue, it would be helpful to know which logging API is being used to log the missing exception.

I can't import logging dependancy into my project

The import statements aren't working
I am new to Maven so I'm not sure what to do (if I'm missing a dependancy or something)
Add this in the dependency section of your pom :
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
There are other logging libraries available ,refer :
https://www.baeldung.com/java-logging-intro
If you are using Spring, I'm not sure if need to add it. When I add the line
Log log = LogFactory.getLog(MYCLASS.class);
to a class & I choose "Import class" in IntelliJ, I can see that it refers to org.springframework:spring-jcl:5.0.5.RELEASE, so it seems to already be available through the Spring.jar .
If you want to try adding it you can add the following to your dependencies list in the pom:
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
I would also point you to Log4j which is very popular & efficient. If you want to use that you need to do two things:
Add the dependencies to the pom:
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.3</version>
</dependency>
Add a log4j.properties or log4j.xml file with configurations to the classpath (mine is in sr/main/resources).

Why isn't maven including a needed transitive dependency?

I am converting our Jenkins Freestyle build to Declarative Pipeline mode. I am using the same POM files.
But whenever i run the pipeline build, i see that the desired war is missing a transitive dependency. The Freestyle build includes that missing dependency however.
The Main parent POM includes:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
The second parent includes section below, :
<dependencies>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
</dependency>
</dependencies>
For both build processes, the dozer artifact is contained in the war file. But dozer contains a dependency of its own:
<dependencies>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.1</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
It is this commons-beanutils that I am missing from my final war when i do the Pipeline build. Since I am using the same POM files for both build processes, how can this be possible?
Please help

dependency mechanism ( overriding transitive version )

I am trying to explicitly override a transitive dependencies version, but doesn't seem to work.
I have this in my projects pom
<!-- use no-commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>99.0-does-not-exist</version>
</dependency>
<!-- no-commons-logging-api, if you need it -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>99.0-does-not-exist</version>
</dependency>
But, the first one doesn't seem to override the transitive dependencies version. I am not sure why ?
Here is the full POM
http://pastebin.com/TBP0YTZs
Here is the dependency tree
http://pastebin.com/VBdjiVcL
PS:
a) This is what I am trying to do
http://day-to-day-stuff.blogspot.com/2007/10/announcement-version-99-does-not-exist.html
Actually, there is much cleaner method to get rid of commons-logging once and for all:
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.6.1</version>
</dependency>
Based on: http://www.slf4j.org/faq.html#excludingJCL

Resources