Forum Discussion

HHaynes's avatar
HHaynes
Contributor
15 years ago

getting log.info out of scripts in loadUI during runtime?

So - as part of my scripts I've been logging info out in order to see where things were going with conditional logic in my Groovy scripts. I would like (actually, I need) to see this logging while the tests are running. How do I do that?

Example of a conditional script with logging below:
import com.eviware.soapui.model.testsuite.TestRunner
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context );
def threadId = Thread.currentThread().getId() as String

def holder = groovyUtils.getXmlHolder( "AddTicketsNewCart#ResponseAsXml" );
def ticketsExist = holder["exists(//response/cart)"];
def getTicketsFault = holder["exists(//response/error)"];

def request = testRunner.testCase.getTestStepByName( "Properties" );

def ticketCount = request.getProperty( "ticketCount" );
def standingTicketPollingCount = request.getProperty( "ticketPollingCount" );
def ticketCountMax = request.getProperty( "totalSpotlightEvents" );

if (Integer.parseInt(ticketCount.value) > Integer.parseInt(ticketCountMax.value))
{
testRunner.fail("Add ticket loop reached max count. Test fail.")
}
else
{
if (ticketsExist == 'true')
{
def ticketPrice = holder.getNodeValue("//response/cart/totals/grand")
groovyUtils.setPropertyValue( "Properties", "ticketPrice", ticketPrice )
log.info("[${threadId}] Ticket price ${ticketPrice}. Going to GetCart1.")
log.info("[${threadId}] Ticket added. Going to GetCart1 to verify.")
testRunner.gotoStepByName( "GetCart1" )
}
else
{
def ticketPollingURL = holder.getNodeValue("//response/polling_url")
groovyUtils.setPropertyValue( "Properties", "ticketPollingURL", ticketPollingURL )
def newTicketPollingCount = Integer.parseInt(standingTicketPollingCount.value) +1 as String;
groovyUtils.setPropertyValue( "Properties", "ticketPollingCount", newTicketPollingCount );
log.info("[${threadId}] AddTicket polled [count = ${newTicketPollingCount}]. Cycling to HTTP polling request.")
testRunner.gotoStepByName( "delayForTicketPollingInterval" )
}
}

4 Replies

  • Hello,

    There is a quick and dirty way to get access to the groovy log in loadUI, but it definately needs improving.

    First you have to edit the soapui-log4j.xml file in the loadUI installation directory and add the following in the logger section:


    <logger name="groovy.log">
    <level value="DEBUG"/>
    <appender-ref ref="CONSOLE"/>
    </logger>


    You can change CONSOLE to FILE if you prefer logging to a file.

    Then you have to enable the Java console. For Windows: Open the Control Panel and find and open the Java control panel. Under "Advanced" there is a setting to show the Java-console, which needs to be enabled. This is a global setting for Java, and will cause the Java console to open alongside any Java program, and it's currently the only way to view the soapUI groovy log in real-time.

    Regards,
    Dain
    eviware.com
  • That will certainly get the job done for now. Thanks for the word.
  • HHaynes wrote:
    That will certainly get the job done for now. Thanks for the word.


    If you'd like a recommendation - you could change the "Error" node on the testRunner panel(s) to "Log" and provide the users a setting for "Error", "Debug", etc...