【发布时间】:2020-02-19 20:56:47
【问题描述】:
我正在尝试设置一个框架来运行 Graphql 调用并创建 E2E 环境。
到目前为止,我已经完成了以下设置,但我似乎无法让标题部分正常工作。我设法为每个请求设置了身份验证,并且一切正常,但是当它为每个请求登录时,它并没有真正按预期工作。
我想执行以下步骤:
- 运行登录测试(不同的用户名有效/无效)
- 运行注销测试(确保删除令牌)
- 然后使用正确的用户登录并提取“set-cookie”标头(全局用于所有未来的请求)
我正在尝试使用以下内容:
空手道配置.js
karate.callSingle('classpath:com/Auth/common-headers.feature', config);
headers.js
function fn() {
var headers = {}
headers["set-cookie"] = sessionAccessId
karate.log('Cookie Value: ', headers)
return headers
}
common-headers.feature
Feature: Login to Application and extract header
Background:
* url serverAuthenticateUri
* header Accept = 'application/json'
Scenario: 'Login to the system given credentials'
Given request { username: '#(username)', password: '#(password)'}
When method post
Then status 200
And match $.success == '#(result)'
And def myResult = response
* def sessionAccessId = responseHeaders['set-cookie'][0]
* configure headers = read('classpath:headers.js')
* print 'headers:', karate.prevRequest.headers
feature-file.feature
Feature: sample test script
Background:
* url serverBaseUri
* def caseResp = call read('classpath:com/E2E/POC/CommonFeatures/CreateCaseRequest.feature')
* def caseReqId = caseResp.response.data.createCaseAndRequest.siblings[0].id
* def caseId = caseResp.response.data.createCaseAndRequest.siblings[0].forensicCaseId
* def graphQlCallsPath = 'classpath:com/E2E/POC/GraphQl/intForensic/'
* def commmonFiles = 'classpath:E2E/CommonFiles/'
Scenario: TC1a - Request Server Details from Config DB (1st Run):
Should handle requesting Server Details Data from Config Database.
* def queryFile = graphQlCallsPath + '20-TC1a_req_req_valid_id.graphql'
* def responseFile = graphQlCallsPath + '20-TC1a_resp_req_valid_id.json'
Given def query = read(queryFile)
And replace query.reqId = caseReqId
And request { query: '#(query)' }
When method post
Then status 200
And json resp = read(responseFile)
And replace resp.reqId = caseReqId
And replace resp.caseID = caseId
And match resp == $
我可以正确登录并获得 set-cookie 令牌,但这并未在 feature-file.feature 上传递,并且我在响应中收到错误消息“未登录”。
任何帮助表示赞赏!我可能完全看错了,我试图尽可能多地遵循共享范围,但无法理解。
【问题讨论】:
标签: karate