Forum Discussion

zxsoap's avatar
zxsoap
Occasional Contributor
16 years ago

Create Groovy library?

Hi All,

I want to create a Groovy library. Anyone tried it yet? Please, let me know.  I'm able to create a Java class, not Groogy scripts?

Thanks,
Tim

9 Replies

  • zxsoap's avatar
    zxsoap
    Occasional Contributor
    All,

    Here's my groovy scrip look like and I want to share it by all my testcases. Is it possible to create a library to hold it. I want to use it like a function library. I tried to create a java class but got the issue with import eviware....

    groovyUtils = new com.eviware.soapui.support.GroovyUtils(context )
    holder = groovyUtils.getXmlHolder ("searchTempT#Response")
    def nname= holder.getNodeValues ("//name") 

    for (n in nname)
    {
    println n
    }

    Thanks,
    zx
  • zxsoap's avatar
    zxsoap
    Occasional Contributor
    Hi Ole,

    Thank for you helps. Yes, I want to build groovy library class ( I used 2.0.2 Pro). I have an issue how to use "testRunner.testCase.name". I did include "import com.eviware.soapui.model.testsuite.TestRunner". But it could get a test case name (null value) at run time.

    Here's what I want to do. I want to build a class which's going to get the test case name and write to text file at run time. I'm using  "testRunner.testCase.name". But have issue with it. Here's the I tried to build (not 100% complete yet)



    package soapui.Report

    import com.eviware.soapui.SoapUI
    import com.eviware.soapui.model.testsuite.TestRunner

    public class Rwrite
    {
     
       
    public void  fw ()
      {
        TestRunner testRunner
     
        println "TestCase: " + testRunner.testCase.name

    }

    Did I do something wrong? why testRunner.testCase.name's always return  NULL.

    Thanks,
    zx
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    you'll need to pass the testRunner as an argument to your fw method.. ie

    ..
    public void fw( Object testRunner )
    {
    ...
    }

    ...


    hope this helps!

    regards,

    /Ole
    eviware.com
  • zxsoap's avatar
    zxsoap
    Occasional Contributor
    Hi Ole,

    It's still return Null as I used the following code.

    public class Rwrite
    {
     
       
    public void  fw (TestRunner testRunner)
      {
         
        println "TestCase: " + testRunner.testCase.name
      }

    }

    Thanks,
    zx
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    how are you using the Rwrite class from your scripts? Can you show the code?

    regards!

    /Ole
    eviware.com
  • zxsoap's avatar
    zxsoap
    Occasional Contributor
    Ole,

    Here's my code used under Grooyy script. (If I remove the "testRunner.testCase.name" under println. It's working ok.)


    def wReports = new soapui.Report.Rwrite()
    wReports.fw ()

    Here's class with .groovy

    package soapui.Report
    public class Rwrite
    {
      import com.eviware.soapui.model.testsuite.TestRunner
       
    public void  fw (TestRunner testRunner)
      {
         
        println "TestCase: " + testRunner.testCase.name
      }

    }


    Thanks,
    zx
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    I think you need to pass the testRunner as an argument.. ie

    def wReports = new soapui.Report.Rwrite()
    wReports.fw ( testRunner )

    regards!

    /Ole
    eviware.com