Ask a Question

accessing project context in external groovy script

Frequent Contributor

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" )

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?

package cws

import com.eviware.soapui.impl.wsdl.testcase.*;
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}' )
SmartBear Alumni (Retired)


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?



Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Frequent Contributor

thanks that worked!

i'm starting to move all my groovy scripts to classes in the external scripts folder.. very cool!!!
Showing results for 
Search instead for 
Did you mean: