accessing project context in external groovy script
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-04-2009
04:33 PM
08-04-2009
04:33 PM
accessing project context in external groovy script
i have an external script db_rec_count.groovy in the scripts dir: 'scripts\cws', in the snipped below if i call one of its methods:
def numbSqlRec = new cws.db_rec_count( sql_table_Transaction, "NumberOfRecordsReturned" )
numbSqlRec.getcount()
i get the following error:
ERROR:An error occured [No such property: context for class: cws.db_rec_count], see error log for details
can i not reference 'context' within the external script?
----db_rec_count.groovy--------
package cws
import com.eviware.soapui.impl.wsdl.testcase.*;
import com.eviware.soapui.support.GroovyUtils;
import groovy.sql.Sql;
import oracle.jdbc.driver.OracleDriver;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;
class db_rec_count{
def sqlRecordName
def propName_RecordsReturned
//Grab sql config from global project properties
def sql_instance = context.expand( '${#Project#SQL_ServerInstance}' )
def sql_user = context.expand( '${#Project#SQL_User}' )
def sql_password = context.expand( '${#Project#SQL_Password}' )
def sql_driver = context.expand( '${#Project#SQL_Driver}' )
def numbSqlRec = new cws.db_rec_count( sql_table_Transaction, "NumberOfRecordsReturned" )
numbSqlRec.getcount()
i get the following error:
ERROR:An error occured [No such property: context for class: cws.db_rec_count], see error log for details
can i not reference 'context' within the external script?
----db_rec_count.groovy--------
package cws
import com.eviware.soapui.impl.wsdl.testcase.*;
import com.eviware.soapui.support.GroovyUtils;
import groovy.sql.Sql;
import oracle.jdbc.driver.OracleDriver;
import com.eviware.soapui.SoapUI;
import com.eviware.soapui.model.testsuite.*;
class db_rec_count{
def sqlRecordName
def propName_RecordsReturned
//Grab sql config from global project properties
def sql_instance = context.expand( '${#Project#SQL_ServerInstance}' )
def sql_user = context.expand( '${#Project#SQL_User}' )
def sql_password = context.expand( '${#Project#SQL_Password}' )
def sql_driver = context.expand( '${#Project#SQL_Driver}' )
2 REPLIES 2
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2009
01:10 AM
08-05-2009
01:10 AM
Hi!
you need to pass the context as an argument to your class; try creating a constructor as follows:
def sql_instance
def sql_user
def sql_password
def sql_driver
public db_rec_count( context )
{
sql_instance = context.expand( '${#Project#SQL_ServerInstance}' )
sql_user = context.expand( '${#Project#SQL_User}' )
sql_password = context.expand( '${#Project#SQL_Password}' )
sql_driver = context.expand( '${#Project#SQL_Driver}' )
}
and then specify the context when creating;
def recCount = new cws.db_rec_count( context )
..
does that help?
regards!
/Ole
eviware.com
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
you need to pass the context as an argument to your class; try creating a constructor as follows:
def sql_instance
def sql_user
def sql_password
def sql_driver
public db_rec_count( context )
{
sql_instance = context.expand( '${#Project#SQL_ServerInstance}' )
sql_user = context.expand( '${#Project#SQL_User}' )
sql_password = context.expand( '${#Project#SQL_Password}' )
sql_driver = context.expand( '${#Project#SQL_Driver}' )
}
and then specify the context when creating;
def recCount = new cws.db_rec_count( context )
..
does that help?
regards!
/Ole
eviware.com
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2009
11:30 AM
08-05-2009
11:30 AM
thanks that worked!
i'm starting to move all my groovy scripts to classes in the external scripts folder.. very cool!!!
i'm starting to move all my groovy scripts to classes in the external scripts folder.. very cool!!!
