cancel
Showing results for 
Search instead for 
Did you mean: 

How to call function from another groovy code?

Contributor

How to call function from another groovy code?

Hi,

i have a project structure in soapui open source like this:

Projects

   -createperson(wsdl)

   -TestSuite1

        -TestCase-1

             -TestDB.groovy

    -TestSuite-2

         -TestCase-2

              -tests.groovy

 

TestDB.groovy

import com.eviware.soapui.model.testsuite.TestStepResult.TestStepStatus
import groovy.sql.Sql
import java.sql.ResultSet;

Properties props = new Properties()
File propsFile = new File('c://test//db.properties')
props.load(propsFile.newDataInputStream())

def url = props.getProperty("db_url")
def user = props.getProperty("db_user")
def password = props.getProperty("db_password")
def driver = props.getProperty("db_driver")

// Register the MySQL JDBC driver 
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver( driver ) 

//Connect to the SQL instance.
def sql = Sql.newInstance(url, user, password, driver)


Class test{

def testFirstName() {

StringBuilder builder1 = new StringBuilder()
def value = sql.eachRow("select * from PERSON where ID = '123' ") { row -> 
   builder1.append( "${row.firsName}" )
}
//Set properties
String myvalue = builder1.toString()
def expected = "JOHN"
assert myvalue == expected
testRunner.testCase.setPropertyValue( "value",myvalue)

sql.close()
}
}

tests.groovy

import test
t = new testFirstname()
t.testFirstName()

Questions:

1- In tests.groovy, the line with import return error:

2- is it correct the way i'm importing function in tests.groovy ?

 

 

 

2 REPLIES 2
Community Hero

Re: How to call function from another groovy code?

It is possible to reuse the code in different groovy scripts across the tests / suites

But you need to change the approach.
Please refer below article explaining the approach with sample code:
http://rupertanderson.com/blog/1-how-to-develop-add-and-use-a-custom-groovy-library-in-soapui/


Regards,
Rao.
Contributor

Re: How to call function from another groovy code?

Hi,

thank you for the link.

for generating jar file, i can do it in cmd line within java folder.

Then i can place the jar file in ext folder of soapui.

And call the medthod from the second code

Is it correct to do this way?

New Here?
Join us and watch the welcome video:
Join the exciting event
SeptemberHubBub
Top Kudoed Authors
Join the September Hub-bub to show off, learn and win