_ivanovich_
6 years agoFrequent 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 ?