use*_*891 2 groovy soap soapui
我正在使用 SOAP UI Pro。我有一个请求,这是摘录:
<ns2:OfficeType>
<ns2:OfficeTypeCode>M</ns2:OfficeTypeCode>
<ns2:EffectiveDate>2000-01-01</ns2:EffectiveDate>
<ns2:TerminationDate>9999-12-31</ns2:TerminationDate>
<ns2:IsPrimary>true</ns2:IsPrimary>
</ns2:OfficeType>
Run Code Online (Sandbox Code Playgroud)
例如,我想使用今天而不是 2000-01-01(所以我写这篇文章的那一天是 2015-03-10。你可能在 3 月 12 日阅读,在这种情况下它将是 2015-03 -12 等)。理论上,我每次发送 SOAP 请求时都可以编辑它并用当前日期替换字段,但这应该是自动的。我想说一句,而不是 2010-01-01 使用类似 $(Today'YYYY-MM-DD') 的东西(这只是一个例子,可能与实际语法无关)。
有没有办法将当前日期放入 SOAP UI Pro 的 SOAP UI 消息中?
在 SOAPUI 中,您可以使用以下符号直接在 SOAP 请求中使用 groovy 代码${=groovy expression},因此在您的情况下,您可以使用格式${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())}获取今天的日期yyyy-MM-dd。
您可以直接在您的测试请求中使用:
<ns2:OfficeType>
<ns2:OfficeTypeCode>M</ns2:OfficeTypeCode>
<ns2:EffectiveDate>${=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new java.util.Date())}</ns2:EffectiveDate>
<ns2:TerminationDate>9999-12-31</ns2:TerminationDate>
<ns2:IsPrimary>true</ns2:IsPrimary>
</ns2:OfficeType>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助,
| 归档时间: |
|
| 查看次数: |
8100 次 |
| 最近记录: |