问题

我的karate项目中有一个具有以下场景的功能.对于我提出的请求,我得到预期的响应,但有第二个不是打算的相同请求.

我注意到第二个请求包含一个额外的头字段’Cookie:’

 Feature: Get the authorization
 Scenario: Retrieve Login page url     
      Given url 'http://someUri:port'
      And path '/secure/author'
      And param response_type = 'code'
      And param client_id = 'valid_clientID'
      And param scope = 'link_submit'
      And param redirect_uri = 'https://someotherUri'
      When method get
      Then status 302
 

下面是我的控制台

 20:19:26.955 [main] INFO  com.intuit.karate - karate.env system property was: null 
20:19:27.998 [main] DEBUG com.intuit.karate - request:
1 > GET http://uri:port/security/authorize?correct-Parameters-are-here
1 > Accept-Encoding: gzip,deflate
1 > Connection: Keep-Alive
1 > Host: the host
1 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_221)

20:19:31.377 [main] DEBUG com.intuit.karate - response time in milliseconds: 3374.29
1 < 302
1 < Connection: Keep-Alive
1 < Date: Mon, 09 Sep 2019 21:40:38 GMT
1 < Location: http:wantedurl.com
1 < Set-Cookie: linkCookie="/V455555555555rhuaUFYc3pkwQ="; Version=1; Path=/
1 < Transfer-Encoding: chunked
1 < X-Content-Type-Options: nosniff
1 < X-Frame-Options: DENY
1 < X-XSS-Protection: 1; mode=block
1 < activityID: 222222222444424

20:19:31.398 [main] DEBUG com.intuit.karate - request:
2 > GET http://uri:port/security/authorize?correct-Parameters-are-here
2 > Accept-Encoding: gzip,deflate
2 > Connection: Keep-Alive
2 > Cookie: $Version=1; linkCookie="/VvfdfdlV3ZRawnoIY83QrhuaUFYc3pkwQ="; $Path="/"
2 > Host: the host
2 > User-Agent: Apache-HttpClient/4.5.5 (Java/1.8.0_221)

20:19:31.755 [main] DEBUG com.intuit.karate - response time in milliseconds: 352.96
2 < 200
2 < Accept-Ranges: bytes
2 < Access-Control-Allow-Headers: Content-Type,x-openui
2 < Access-Control-Allow-Methods: GET
2 < Access-Control-Allow-Origin: *
2 < Cache-control: private
2 < Connection: Keep-Alive
2 < Content-Type: text/html
2 < Date: Mon, 09 Sep 2019 21:40:38 GMT
2 < ETag: "288-59152f593c040"
2 < Last-Modified: Fri, 30 Aug 2019 10:19:37 GMT
2 < Set-Cookie: 34c188e0698035e66376b276a0a05cd4=f2a878936046ce053dcdc55f78d1e7ca; path=/; HttpOnly; Secure
2 < Transfer-Encoding: chunked
2 < activityID: 31910620180969978101601944
<!doctype html><html lang="en"><head><meta charset="utf-8"><title>some titile</title><base href="."><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.ea03e93ac5f3a194d43b.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><div id="test"></div><script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script><script type="text/javascript" src="polyfills.9e6fb2e22bb7bf8ba831.bundle.js"></script><script type="text/javascript" src="main.7aff2d014e2a36462a25.bundle.js"></script></body></html>

[Fatal Error] :1:3: The markup in the document preceding the root element must be well-formed.
20:19:31.820 [main] WARN  com.intuit.karate - xml parsing failed, response data type set to string: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 3; The markup in the document preceding the root element must be well-formed.
20:19:31.823 [main] ERROR com.intuit.karate - status code was: 200, expected: 302, response time: 353, url: http://uri:port/security/authorize?correct-Parameters-are-here, response: <!doctype html><html lang="en"><head><meta charset="utf-8"><title>title goes here</title><base href="."><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"><link href="styles.ea03e93ac5f3a194d43b.bundle.css" rel="stylesheet"/></head><body><app-root></app-root><div id="test"></div><script type="text/javascript" src="inline.318b50c57b4eba3d437b.bundle.js"></script><script type="text/javascript" src="polyfills.9e6fb2e22bb7bf8ba831.bundle.js"></script><script type="text/javascript" src="main.7aff2d014e2a36462a25.bundle.js"></script></body></html>
 

  最佳答案

是的,这是正确的行为 – 注意第一个请求的 HTTP响应代码是302 .在这种情况下,响应给你一个名为linkCookie的cookie.

看起来应该没问题,因为您的请求是GET.在一些罕见的情况下,您需要处理POST自己.

还请在文档中查找followRedirects.

  相同标签的其他问题

karateweb-api-testing