cancel
Showing results for 
Search instead for 
Did you mean: 

[RESOLVED] Property Expansion in RequestFilter.filterRequest script

Frequent Contributor

[RESOLVED] Property Expansion in RequestFilter.filterRequest script

I was wondering if the Groovy script written for these events in the Events tab support Property expansion?

For example:

def NTT_id_header = context.getProperty("PostMethod")
NTT_id_header.setRequestHeader("NTT_id", "${#TestSuite#subscriber.NTT}");


Reason I ask is, the Soap log is indicating compiler error, complaining about the '#' symbol.  I've tried escaping the characters, I've tried it without quotes, still getting compiler errors.

Any advice?

Thanks,
Mason

UPDATE:  09-25-2009 - 4:22 PM (EST) - I have since figured out that I need to use the getProperty method from the CONTEXT scope but I found another issue.  (New post)
8 REPLIES 8

Re: [RESOLVED] Property Expansion in RequestFilter.filterRequest script

Hi!

you need to use single quotes, otherwise groovy will try to expand the property reference itself.. ie

NTT_id_header.setRequestHeader("NTT_id", '${#TestSuite#subscriber.NTT}');

regards!

/Ole
eviware.com


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Frequent Contributor

Re: [RESOLVED] Property Expansion in RequestFilter.filterRequest script

This doesn't work either.  The property does not get expanded (the string ${#TestSuite#subscriber.NTT} is inserted into the header.  The reason for this, we suspect, is because a TestSuite variable will not work in the Event handler area of SoapUI since the scope is at the context level (the TestSuite script hasn't run yet, it runs after the script in the Event handler area).  We used the following code to populate the header:

def subscriber_c = context.getProperty("subscriber.c");
log.info ("subscriber_c = " + subscriber_c);
def c_id_header = context.getProperty("postMethod")
c_id_header.setRequestHeader("c_id", subscriber_c);

We populate the property of subscriber.c in the setup script of the project so that it is available to the context scope.

This has caused a problem however, because we need to be able to modify headers at the TestSuite and/or TestCase level as well.  Having the headers populated at the Project level does not allow us to send two requests with different values for the headers.  For instance if we wanted to send one request with a c_id header with a value of "123" and in the same project, later in the test sequence, send a request with a c_id header and a value of "321".

Is there any way to dynamically insert headers at the TestSuite and/or TestCase level?

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

Hi!

I'm sorry, I though you wanted the actual property-expansion to be in the header.. have you tried

NTT_id_header.setRequestHeader("NTT_id", context.expand( '${#TestSuite#subscriber.NTT}') );

?

regards,

/Ole
eviware.com


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Frequent Contributor

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

I'm not in a position to try the extra set of parenthesis at the moment.  But will a TestSuite property work within the scope of the Event handlers?
Frequent Contributor

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

eviware support wrote:

Hi!

I'm sorry, I though you wanted the actual property-expansion to be in the header.. have you tried

NTT_id_header.setRequestHeader("NTT_id", context.expand( '${#TestSuite#subscriber.NTT}') );

?

regards,

/Ole
eviware.com


As I suspected, this didn't work.  I get the following error:

Mon Sep 28 11:34:32 EDT 2009:ERROR:groovy.lang.MissingPropertyException: No such property: NTT_id_header for class: Script4


The reason, again, we suspect is the scope is wrong.  Event handlers run at the CONTEXT level, the variable/property we are trying to expand is at the TestSuite level.  Is there anyway to get a TestSuite property to expand in the CONTEXT level.  Is there a way to run the Event handlers at the TestSuite level?

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

Hi,

The error you're getting points to a problem with the NTT_id_header variable, not with the property expansion. There shouldn't be a problem with the scope, since the filter is running after a request, which does belong to a TestSuite. I have verified this myself by setting a TestSuite Property var = hello and adding the following Event handler:

RequestFilter.filterRequest

log.info context.expand('${#TestSuite#var}')


When running the Test (by running the Request itself, the TestCase, TestSuite or even the whole Project) "hello" is being logged once for each request that is run. You may want to try just logging the result of the Property Expansion to the log to verify that it is being expanded as it should with:


log.info context.expand('${#TestSuite#subscriber.NTT}')


Hope this helps!

Regards,
Dain
eviware.com


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Frequent Contributor

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

When you say "run the test", at which level are you running it?  Project, TestSuite, TestCase?

Re: [RE-OPENED] Property Expansion in RequestFilter.filterRequest script

Hello,

I've tried running it using all of the above (Project, TestSuite, TestCase and TestStep), it shouldn't make a difference. When the TestStep gets executed, the RequestFilter kicks in and the TestSuite property should be accessible.

Regards,
Dain
eviware.com


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors