can i pass header value from datasource?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
can i pass header value from datasource?
Hi
I have a grid data source, where i pass the properties: usertype and user name
The usertype should be passed as a header value for my REST service.
I tried to write an event code for filtering based on teh datasource property. But it fails.
datasource: userDS
usertype Z Y X
condition true true false
event : filter.request
def TC= context.testCase.name.contains ("myTC")
def headers = new StringToStringMap()
if(myTC)
{
if((context.testCase.getTestStepAt (7).getLabel()).contains("myteststep"))
{
if('${#userDS#usertype}' == 'Z')
{
headers.put('id','${#Project#id}')
headers.put('usertype', '${#userDS#usertype}')
headers.put('valid', '${#userDS#condition}')
}
else if('${#userDS#usertype}' == 'Y')
{
headers.put('id','${#Project#id}')
headers.put('usertype', '${#userDS#usertype}')
headers.put('valid', '${#userDS#condition}')
}
else if('${#userDS#usertype}' == 'X')
{
headers.put('id','${#Project#id}')
headers.put('usertype', '${#userDS#usertype}')
headers.put('valid', '${#userDS#condition}')
}
}
}
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Header value is a list type. You are putting a string.
Here is an example code snippet, which adds the headers to the given request based on step name.
Issue #1:
${#userDS#usertype} -- this can't directly be used. Instead use context.expand('${#userDS#usertype}')
Similarly other instances in your script.
Also another improvemement in the code is you can use a list to check instead of repeating the code for three times.
def userTypesLookup = ['X', 'Y', 'Z'] if (userTypesLookup.contains(context.expand('${#userDS#usertype}'))) { //do the stuff }
Regards,
Rao.
