使用属性转移时如何删除括号?

时间:2019-08-17 21:19:43

标签: soapui jsonpath

我是soapUI的初学者。从昨天开始,我正在研究将属性从响应传递到另一个API的参数。

我正在尝试使用OpenStreetMap API将地址转换为坐标。但是,当传输该属性时,它会在我的其他API上留下导致404错误的括号。

例如,对于艾菲尔铁塔地址,OSM API答案的开头是:

[
    {
        "place_id": "64537015",
        "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright",
        "osm_type": "way",
        "osm_id": "5013364",
        "boundingbox": [
            "48.8574753",
            "48.8590465",
            "2.2933084",
            "2.2956897"
        ],
        "lat": "48.8582602",
        "lon": "2.29449905431968",
        "display_name": "Tour Eiffel, 5, Avenue Anatole France, Gros-Caillou, 7e, Paris, Île-de-France, France métropolitaine, 75007, France",
        //etc
    }
]

我用于传递属性值的代码是:

$..boundingbox[1,2] 

这是传输的值:

[[48.8590465, 2.2933084]]

我想要没有括号...

1 个答案:

答案 0 :(得分:0)

在属性传递中,您将从JSONPath处理器,方括号及所有内容中获取原始响应,因此您需要对值进行一些预处理或后处理。

一种选择是使用Groovy测试步骤对传输的值进行后处理。假设您的财产转移到了测试套件级别的财产latlong

// Assuming the transferred-to property is at the test suite level
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue( "latlong" )
log.info testSuiteProperty

def strippedProperty = testSuiteProperty.replaceAll("\\[", "").replaceAll("\\]","");
log.info strippedProperty

这将产生:

48.8574753, 2.2933084