如何在安装脚本中引用全局属性?(How to reference global property in setup script?)

编程入门 行业动态 更新时间:2024-10-28 02:34:43
如何在安装脚本中引用全局属性?(How to reference global property in setup script?)

我试图在测试用例中执行安装脚本并准备一些数据。 我在全局属性中定义了连接,用户和密码,请参阅:

现在我想代替硬编码连接,用户名和密码来引用全局属性,这可能吗?

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

更多推荐

本文发布于:2023-04-27 12:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1327064.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:全局   脚本   属性   如何在   reference

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!