Forum Discussion
harmans
11 years agoOccasional Contributor
Hi,
My question is SOAPUI specific and not about groovy. I can configure database under JDBC Connections but i will still need to create a separate instance for each test case (i want to create database connection only one time in the setup script). Please correct me if i am wrong.
The syntax for setProperty is setProperty(String name, Object value), so i can store an Object.
Please refer http://www.soapui.org/apidocs/com/eviwa ... .Object%29
If i put complete code in setup script, it works ( put the complete code below in setup script and it will print the value of contact_name ). Its just that the i cannot retrieve the context of the testsuite (in the setup script at testsuite level) in the Groovy Teststep.
import groovy.sql.Sql
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver")
def db = [url:'jdbc:sqlserver://127.0.0.1:1433;databaseName=Test123',user:'user',password:'password',driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver']
try{
def connection = Sql.newInstance(db.url, db.user, db.password, db.driver)
context.setProperty("dbconn",connection)
log.info "connected to the database"
}catch(Exception e){
log.error "Could not connect to the database"
}
if(context.dbconn){
def sql = context.dbconn
sql.eachRow("select ua.[contact_name], ua.[contact_last_name] from [dbo].[USER_ACCOUNT] where [user_id] = 'abc' ")
{row ->
log.info("$row.contact_name")
}
}
My question is SOAPUI specific and not about groovy. I can configure database under JDBC Connections but i will still need to create a separate instance for each test case (i want to create database connection only one time in the setup script). Please correct me if i am wrong.
The syntax for setProperty is setProperty(String name, Object value), so i can store an Object.
Please refer http://www.soapui.org/apidocs/com/eviwa ... .Object%29
If i put complete code in setup script, it works ( put the complete code below in setup script and it will print the value of contact_name ). Its just that the i cannot retrieve the context of the testsuite (in the setup script at testsuite level) in the Groovy Teststep.
import groovy.sql.Sql
com.eviware.soapui.support.GroovyUtils.registerJdbcDriver("com.microsoft.sqlserver.jdbc.SQLServerDriver")
def db = [url:'jdbc:sqlserver://127.0.0.1:1433;databaseName=Test123',user:'user',password:'password',driver:'com.microsoft.sqlserver.jdbc.SQLServerDriver']
try{
def connection = Sql.newInstance(db.url, db.user, db.password, db.driver)
context.setProperty("dbconn",connection)
log.info "connected to the database"
}catch(Exception e){
log.error "Could not connect to the database"
}
if(context.dbconn){
def sql = context.dbconn
sql.eachRow("select ua.[contact_name], ua.[contact_last_name] from [dbo].[USER_ACCOUNT] where [user_id] = 'abc' ")
{row ->
log.info("$row.contact_name")
}
}
Related Content
- 4 years agoPUM-Prodat-SQL
- 7 years agoGaleG