SoapUI JSON Path断言用于两个不使用JsonSlurper的不同字符串

时间:2015-11-19 11:28:09

标签: json soapui assertion jsonpath

我使用SoapUI JSONPath Mach功能来断言JSON响应。根据一种语言,我可以有两种不同的反应:

using System.Drawing.Printing; using System.Windows.Forms; private void Main() { PrintDocument pd = new PrintDocument(); pd.PrintPage += new PrintPageEventHandler(pd_PrintPage); PrintDialog pdi = new PrintDialog(); pdi.Document = pd; // -> preventing PrintDialog from changing the default printer // -> BUT changing the PrintDocuments-Printer to the selected?? if (pdi.ShowDialog() == DialogResult.OK) { pd.Print(); // -> OR reset default Printer? } } private void pd_PrintPage(object sender, PrintPageEventArgs ev) { //- do the printing ev.HasMorePages = false; } Factura no encontrada en el lote.

我知道我可以使用JsonSlurper来做到这一点:

Invoice not found in open batch.

但是,我正在寻找的是在SoapUI断言功能中使用它,请参见屏幕截图: enter image description here

具体来说,我该如何改变底部:

assert jsonSlurper.header.rspMsg in ["Factura no encontrada en el lote.","Invoice not found in open batch."]

由于

1 个答案:

答案 0 :(得分:2)

不幸的是,使用JSONPath match assert是不可能的(至少对于现有版本,可能在将来......)。对于预期结果中的断言,只允许使用字符串(或扩展将被计算为字符串的表达式),因此无法使用OR运算符设置期望值。

另一种方法是将OR运算符放在jsonpath表达式中,使用true作为预期结果。

例如,根据您的情况,您可以使用以下内容:

$.header.[?(@.['rspMsg'] == 'Factura no encontrada en el lote.' || ?(@.['rspMsg'] == 'Invoice not found in open batch.']

在预期结果中使用true

但是已经存在另一个问题,SOAPUI 5.2.1使用com.jayway.jsonpath版本0.9.1并且此版本不支持||运算符,因此这不起作用。< / p>

因此,最后一次尝试可能是使用JSONPath Regex match assert来计算针对提供的正则表达式的JSONPath表达式,并期望true或false。使用此方法,您可以使用:

JSONPath表达式: $.header.rspMsg

正则表达式: (Factura no encontrada en el lote\.)|(Invoice not found in open batch\.)

预期结果: true

enter image description here

此时我认为更好的方法是使用jsonSlurper来执行断言。

希望这有帮助,