Logging Selenium Tests in ReadyAPI
I'm currently having the following problem:
I used ReadyAPI to make a testframework for testing backend. Now I made a Selenium Framework for testing the frontend.
I build a JAR from this Selenium framework so I could run these tests in the ReadyAPI framework.
I also put logging functionality in the Selenium framework (slf4j) that should generate a log file when the tests are run. This works when run seperately.
So far this doesn't happen when I'm running these tests from ReadyAPI.
Logging for the tests made in ReadyAPI is working fine.
So my question is:
The Selenium frontend tests run fine when run from the ReadyAPI framework, but there is no logging.
Does anyone have an idea how to solve this?
I have a solution! Smartbear apparently uses log4j for logging.
So you need to emplement this in your Selenium framework.
Something like this:
package com.testproject.tests; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public class TestClass{ private Logger LOG; public TestClass(Logger LOG) { this.LOG = LOG; } public TestClass() {this(LogManager.getLogger(TestClass.class)); } @Test public void testMethod() { LOG.info("DEBUG LOGGING"); LOG.debug("DEBUG LOGGING"); LOG.warn("DEBUG LOGGING"); } }
Then you have to put some groovy in you ReadyAPI test to maken the test run and to get the logging:
//Imports import com.testproject.tests.*; //make sure to insert "log" TestClass appt = new TestClass(log); //driver is your webdriver and I left out the code to instantiate it appt.setDriver(driver); appt.testMethod();
Then you can adjust loglevels by adjusting "groovy.log" level in soapui-log4j.xml (wich will be in the bin folder of your ReadyAPI programfiles). In my original file it was set to "INFO". Here is an code example where I changed it to "DEBUG".
<logger name="groovy.log" level="DEBUG" additivity="false"> <AppenderRef ref="CONSOLE"/> <AppenderRef ref="GLOBAL_GROOVY_LOG" level="DEBUG"/> </logger>
Hope someone else can use this information aswell :-)