how to use properties wthin regular expressions for assertions?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
how to use properties wthin regular expressions for assertions?
I would like to parameterize a test-case because a date that has to be supplied as part of the reuest has to be within a valid range and thus can not be constant. So I defined it as project property (which hopefully one day will be assigned automatically once I am more familiar with soapUI's scripting...)
The response thus needs to be tested not against a constant string but against a regular expression (because I also want to ignore certain parts of the response) part of which should be the content of the same property that is used as argument of the request.
How can I have a property be inserted into a regular expression? If I just add the usual ${#Project#date} into the regular expression this obviosly does not work because $, #, etc. have special meanings inside a regexp. If I escape those characters, however, they are considered as literals. So, how can I have the property's value injected BEFORE the strin is used as regexp?
Hope I could make myself clear...
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Not sure if this will help you with creating a your date within a given range using a script, but just incase I solved a problem like this previously in the following post:
http://community.smartbear.com/t5/SoapUI-Open-Source/Random-Date-Project-Property/td-p/99993
In order to test that your response contains a date within a given range using a regex, I would try a Script Assertion:
1) Get the date from the response and hold it in a variable using a property expansion e.g. something like
def dateToTest = context.expand('${#Project#date}')
2) Next test the dateToTest variable against your regex using something like:
If (dateToTest=~searchStringRegex) { code if matched... }
For more on Groovy regex, go to http://groovy.codehaus.org/Regular+Expressions.
Is this on the right track to what you're after?
Cheers,
Rupert
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It didn't directly answer my question but gave me some indications, where to search on. So it helped. Thanks!
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, no problem 🙂
Cheers,
Rupert
