我试图在测试用例中执行安装脚本并准备一些数据。 我在全局属性中定义了连接,用户和密码,请参阅:
现在我想代替硬编码连接,用户名和密码来引用全局属性,这可能吗?
import groovy.sql.Sql def jdbcDriver = "net.sourceforge.jtds.jdbc.Driver" com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(jdbcDriver) def jdbcConnection = "jdbc:jtds:sqlserver://localhost/mydb" def jdbcConnectionUser="dbuser" def jdbcConnectionPassword="dbpswrd" log.info jdbcConnection //log.info ${#Global#JDBC_CONNECTION_STRING} <-- this doesn't work ?? //${#Global#JDBC_CONNECTION_STRING}, ${#Global#DBUSER}, ${#Global#DBPASS} def db = [url:jdbcConnection,user:jdbcConnectionUser,password:jdbcConnectionPassword,driver:jdbcDriver] 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 log.info "executing setup script" sql.execute "update table_a set column_b = 'S' where column_c = 'something'" sql.close() }我已经尝试使用以下语法引用全局属性,但无济于事
${#Global#JDBC_CONNECTION_STRING}I'm trying to execute setup script in a test case and prepare some data. I've defined connection, user & password in global properties, see:
Now I'd like to instead of hard coding connection, user and password to reference global property, is that possible?
import groovy.sql.Sql def jdbcDriver = "net.sourceforge.jtds.jdbc.Driver" com.eviware.soapui.support.GroovyUtils.registerJdbcDriver(jdbcDriver) def jdbcConnection = "jdbc:jtds:sqlserver://localhost/mydb" def jdbcConnectionUser="dbuser" def jdbcConnectionPassword="dbpswrd" log.info jdbcConnection //log.info ${#Global#JDBC_CONNECTION_STRING} <-- this doesn't work ?? //${#Global#JDBC_CONNECTION_STRING}, ${#Global#DBUSER}, ${#Global#DBPASS} def db = [url:jdbcConnection,user:jdbcConnectionUser,password:jdbcConnectionPassword,driver:jdbcDriver] 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 log.info "executing setup script" sql.execute "update table_a set column_b = 'S' where column_c = 'something'" sql.close() }I've tried referencing global property using following syntax but to no avail
${#Global#JDBC_CONNECTION_STRING}最满意答案
我发现这是工作,应该在提问之前阅读文档。
def jdbcConnection = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "JDBC_CONNECTION_STRING" ) def jdbcConnectionUser= com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBUSER") def jdbcConnectionPassword= com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBPASS")这里是我找到答案和相关摘录的链接:
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "MyProp" )https://www.soapui.org/scripting-properties/tips-tricks.html#1-2-Get-and-Set-Settings
I found this to be working, should have read documentation before asking the question.
def jdbcConnection = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "JDBC_CONNECTION_STRING" ) def jdbcConnectionUser= com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBUSER") def jdbcConnectionPassword= com.eviware.soapui.SoapUI.globalProperties.getPropertyValue("DBPASS")And here is a link where I found the answer and relevant excerpt :
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "MyProp" )https://www.soapui.org/scripting-properties/tips-tricks.html#1-2-Get-and-Set-Settings
更多推荐
发布评论