Forum Discussion
def jsonResponse <SPAN class="token operator">=</SPAN> context<SPAN class="token punctuation">.</SPAN>testCase<SPAN class="token punctuation">.</SPAN>testSuite<SPAN class="token punctuation">.</SPAN><SPAN class="token function">getPropertyValue</SPAN><SPAN class="token punctuation">(</SPAN>'loginResponse'<SPAN class="token punctuation">)</SPAN>
def jsonSlurper <SPAN class="token operator">=</SPAN> <SPAN class="token keyword">new</SPAN> <SPAN class="token class-name"><SPAN class="token namespace">groovy<SPAN class="token punctuation">.</SPAN>json<SPAN class="token punctuation">.</SPAN></SPAN>JsonSlurper</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN>
def parsedJson <SPAN class="token operator">=</SPAN> jsonSlurper<SPAN class="token punctuation">.</SPAN><SPAN class="token function">parseText</SPAN><SPAN class="token punctuation">(</SPAN>jsonResponse<SPAN class="token punctuation">)</SPAN>
def accessToken <SPAN class="token operator">=</SPAN> parseJson<SPAN class="token punctuation">.</SPAN>access<SPAN class="token punctuation">.</SPAN><SPAN class="token function">toString</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN>
context<SPAN class="token punctuation">.</SPAN>testCase<SPAN class="token punctuation">.</SPAN>testSuite<SPAN class="token punctuation">.</SPAN><SPAN class="token function">setPropertyValue</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token char">'token'</SPAN><SPAN class="token punctuation">,</SPAN> accessToken<SPAN class="token punctuation">.</SPAN><SPAN class="token function">toStrin</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">)</SPAN>
and also i tried with Property transfer:
source = login Property= Response Path langaue JSONPath
Target TestSuite-login Property= test Path langauge JSONPath
Here i tansferred to TestSuite property called 'test'
With twos methods the token is saved in properties but not get retrieved in the second request where i configured the Authorization:
Authorization = Profile 1
Access Token = $(#TestSuite#test) or $(#TestSuite#token)
Not sure what you showed is complete script as it is not so comfortable for reading.
Can you please try adding below at the end and try to to use ${#Project#TOKEN}.
By the way, is it a bearer token? If so, is Bearer missing before ${#Project#TOKEN} in your Authorization header?
context.testCase.testSuite.project.setPropertyValue('TOKEN', accessToken)
Related Content
- 6 years ago
Recent Discussions
- 2 days ago