Forum Discussion

TesterNo1's avatar
TesterNo1
Contributor
9 years ago
Solved

Access testRunner objects from external jar files

Hi all,

 

Has anyone tried accessing testrunner objects from external jar file?

 

I have same properties in all testcases.I want to see if i can access property based on run context from jar file.Also,I want to be able to access the test step from external file. I could only think of jar file but not sure how to go about it.

 

TIA.

 

 

  • Yes, you can use the api to call the external classes from groovy script. Only thing is that you need to pass the variables that are available in the groovy script such as log, context, testRunner to the user class, so that one would be able to access these variables in his classes

     

    Implement your class(es), compile and build the jar file, then put it under SOAPUI_HOME/bin/ext and restart the SoapUI / Ready!API.

     

    In your groovy script, just create the object of your class, like you do in java, then call the methods as you wish.

     

    Here is an example class:

     

     


    /** * below is a groovy class example demonstrates * how to access the soapui objects * inside user class **/ package demo.external.classes SoapUIDemoClass { def context def log def testRunner def greet(def name) { log.info "Hello, ${name}" } def showTestCaseName() { log.info "Name of the test case is : ${testRunner.testCase.name}" } def getTestCasePropertyValue(def name) { context.testCase.properties[name].value } }

     

    Here is how you can call the above class methods in groovy script:

     

    import demo.external.classes.SoapUIDemoClass
    
    //Instaniating your class object with constructor def demoClass = new SoapUIDemoClass(context: context, log: log, testRunner: testRunner) //Call the method of user class
    demoClass.greet("World!")
    //Getting the test case property value using a method defined in user class def value = demoClass.getTestCasePropertyValue('ANY_PROPERTY_THAT_YOU_HAVE') log.info "Property value is : ${value}"
    //logging the name of the test case from method of user defined class.
    demoClass.showTestCaseName()

3 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    Yes, you can use the api to call the external classes from groovy script. Only thing is that you need to pass the variables that are available in the groovy script such as log, context, testRunner to the user class, so that one would be able to access these variables in his classes

     

    Implement your class(es), compile and build the jar file, then put it under SOAPUI_HOME/bin/ext and restart the SoapUI / Ready!API.

     

    In your groovy script, just create the object of your class, like you do in java, then call the methods as you wish.

     

    Here is an example class:

     

     


    /** * below is a groovy class example demonstrates * how to access the soapui objects * inside user class **/ package demo.external.classes SoapUIDemoClass { def context def log def testRunner def greet(def name) { log.info "Hello, ${name}" } def showTestCaseName() { log.info "Name of the test case is : ${testRunner.testCase.name}" } def getTestCasePropertyValue(def name) { context.testCase.properties[name].value } }

     

    Here is how you can call the above class methods in groovy script:

     

    import demo.external.classes.SoapUIDemoClass
    
    //Instaniating your class object with constructor def demoClass = new SoapUIDemoClass(context: context, log: log, testRunner: testRunner) //Call the method of user class
    demoClass.greet("World!")
    //Getting the test case property value using a method defined in user class def value = demoClass.getTestCasePropertyValue('ANY_PROPERTY_THAT_YOU_HAVE') log.info "Property value is : ${value}"
    //logging the name of the test case from method of user defined class.
    demoClass.showTestCaseName()
    • TesterNo1's avatar
      TesterNo1
      Contributor

      Thank you Rao,But which IDE did you use to code and compile ?

      • nmrao's avatar
        nmrao
        Champion Level 3
        While writing above? Not used any. If your question is in general, you may use intellij/eclipse whatever you like.