【问题标题】:Gatling extract xpath values error "Namespace prefix 'soap' has not been declared"Gatling 提取 xpath 值错误“尚未声明命名空间前缀 'soap'”
【发布时间】:2019-09-26 22:59:58
【问题描述】:

以下场景为我引入了正确的 SOAP 主体,但我无法使用 xpath expression 提取它的值

路径表达式/*/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text()我用这个网站形成的 https://codebeautify.org/Xpath-Tester

  val httpConf = http.baseUrl("https://www.dataaccess.com")
  val headerXml = Map("Keep-Alive" -> "115", "Content-Type" -> "application/soap+xml; charset=utf-8")

 val soapXmlScn = scenario("make First Soap Call")
                 .exec(
                   http("Soap API Call With XML")
                   .post("/webservicesserver/numberconversion.wso")
                   .headers(headerXml)
                   .body(StringBody("""<?xml version="1.0" encoding="utf-8"?>
                    <soap20:Envelope xmlns:soap20="http://www.w3.org/2003/05/soap-envelope">
                      <soap20:Body>
                        <NumberToDollars xmlns="http://www.dataaccess.com/webservicesserver/">
                          <dNum>45</dNum>
                        </NumberToDollars>
                      </soap20:Body>
                    </soap20:Envelope>"""))
                   .check(status.is(200))
                   .check(xpath("""//*/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text()""").saveAs("doller_value" ))
                 )
                 .exec {
                      session =>
                        println("doller value >>>> " + session("doller_value").as[String].toString)
                        session
                    }

响应正文是

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
  <soap:Body>
    <m:NumberToDollarsResponse xmlns:m="http://www.dataaccess.com/webservicesserver/">
      <m:NumberToDollarsResult>forty five dollars</m:NumberToDollarsResult>
    </m:NumberToDollarsResponse>
  </soap:Body>
</soap:Envelope>

控制台上显示的错误是

12:22:16.880 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - 'hook-1' crashed with 'j.u.NoSuchElementException: No attribute named 'doller_value' is defined', forwarding to the next one

【问题讨论】:

    标签: scala xpath soap gatling


    【解决方案1】:

    命名空间List 需要提供给您的xpath 检查如下,我的请求工作正常。 这些命名空间 URL 仅在您的 SOAP 响应 xml 中提及

    .check(xpath("""//soap:Envelope/soap:Body/m:NumberToDollarsResponse/m:NumberToDollarsResult/text()""", List("soap" -> "http://www.w3.org/2003/05/soap-envelope", "m" -> "http://www.dataaccess.com/webservicesserver/")).findAll.saveAs("doller_value" ))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 2014-03-21
      • 1970-01-01
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多