cancel
Showing results for 
Search instead for 
Did you mean: 

can i pass header value from datasource?

SOLVED
Asubbiah
Contributor

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}')

}

}

}

 

1 ACCEPTED SOLUTION

Accepted Solutions
nmrao
Community Hero

Re: can i pass header value from datasource?

 

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.

View solution in original post

1 REPLY 1
nmrao
Community Hero

Re: can i pass header value from datasource?

 

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.

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors