如何将连接设置应用于 SoapUI 中的所有 JDBC 个测试步骤?
How to apply connection settings to all JDBC test steps in SoapUI?
tl;博士
(手动)更新单个 SoapUI 测试步骤的 JDBC 连接属性后,
- 如何将它们复制到项目中的其他测试步骤(不求助于
${property}
扩展)?
- 我想 Groovy 是关键?
背景
我有一个 SoapUI 项目,其中包含许多 JDBC 指向我的开发数据库的测试步骤:
The Open source version of JDBC TestStep has fields for setting the
connection properties and the SQL query manually.
Getting Started | JDBC (SoapUI.org)
限制条件: 我目前在没有 Smartbear 专业版的 Connections 功能的情况下工作。
目标
在部署之前,我想 运行 在我们的暂存环境中进行相同的测试,即我必须 更改 JDBC 整个测试套件的连接设置。
初步考虑:
为了将所有 JDBC 步骤重定向到暂存数据库,我可以根据 属性 扩展将测试编辑到连接字符串和驱动程序字段,如 .
中所述
具体做法:
然而,在这种情况下,我需要 直接在测试步骤中查看连接字符串和驱动程序 (与仅查看 ${expansion}
变量相反)– 理由: 它提供了更有用的真实值截图...
可以使用以下 Groovy 脚本将连接属性从一个测试步骤复制到项目中的其他 JDBC 个测试步骤:
// Select "correctly configured" JDBC TestStep/Case/Suite to be used as reference
def s = testRunner.testCase
.testSuite
.project
.testSuites["Reference TestSuite"]
.testCases["Reference TestCase"].getTestStepAt(1)
log.info "${s.getConnectionString()}, ${s.getDriver()}"
// Use s to configure all JDBC TestSteps in current TestSuite
testRunner.testCase
.testSuite
.testCases
.each{iTC, testCase ->
//log.debug "${iTC}: ${testCase}"
testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep)
.each{testStep ->
testStep.setConnectionString(s.getConnectionString())
testStep.setDriver(s.getDriver())
log.info "${testStep.getConnectionString()}, ${testStep.getDriver()}"
}
}
为了运行这个,我分别引入了额外的测试套件internal TS
和测试用例internal TC
。我已经添加了一个 Groovy TestStep copyJdbcSettings
和上面的脚本到 internal TC
并执行了一次。
然后我禁用了 internal TS
直到有一天我再次需要它。
tl;博士
(手动)更新单个 SoapUI 测试步骤的 JDBC 连接属性后,
- 如何将它们复制到项目中的其他测试步骤(不求助于
${property}
扩展)? - 我想 Groovy 是关键?
背景
我有一个 SoapUI 项目,其中包含许多 JDBC 指向我的开发数据库的测试步骤:
The Open source version of JDBC TestStep has fields for setting the connection properties and the SQL query manually. Getting Started | JDBC (SoapUI.org)
限制条件: 我目前在没有 Smartbear 专业版的 Connections 功能的情况下工作。
目标
在部署之前,我想 运行 在我们的暂存环境中进行相同的测试,即我必须 更改 JDBC 整个测试套件的连接设置。
初步考虑:
为了将所有 JDBC 步骤重定向到暂存数据库,我可以根据 属性 扩展将测试编辑到连接字符串和驱动程序字段,如
具体做法:
然而,在这种情况下,我需要 直接在测试步骤中查看连接字符串和驱动程序 (与仅查看 ${expansion}
变量相反)– 理由: 它提供了更有用的真实值截图...
可以使用以下 Groovy 脚本将连接属性从一个测试步骤复制到项目中的其他 JDBC 个测试步骤:
// Select "correctly configured" JDBC TestStep/Case/Suite to be used as reference
def s = testRunner.testCase
.testSuite
.project
.testSuites["Reference TestSuite"]
.testCases["Reference TestCase"].getTestStepAt(1)
log.info "${s.getConnectionString()}, ${s.getDriver()}"
// Use s to configure all JDBC TestSteps in current TestSuite
testRunner.testCase
.testSuite
.testCases
.each{iTC, testCase ->
//log.debug "${iTC}: ${testCase}"
testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.JdbcRequestTestStep)
.each{testStep ->
testStep.setConnectionString(s.getConnectionString())
testStep.setDriver(s.getDriver())
log.info "${testStep.getConnectionString()}, ${testStep.getDriver()}"
}
}
为了运行这个,我分别引入了额外的测试套件internal TS
和测试用例internal TC
。我已经添加了一个 Groovy TestStep copyJdbcSettings
和上面的脚本到 internal TC
并执行了一次。
然后我禁用了 internal TS
直到有一天我再次需要它。