Tommie
5 years agoNew Contributor
Groovy script - regex - conditional step (not working)
In a testcase I want to check the XML result. If the regex (6 digits '- ' 7digits) is met then the script needs to jump to a different step then when the condition is not met. I've tried this: d...
- 5 years agoHey Tommie,
I'm not a whizzy scripter like the other people on here like Rao, msiadak, avidCoder, etc. So i could be wrong, but i have a couple of thoughts that might help.
1. Have you looked at the conditional goto step? For a simple decision (like the one you specify this may work without having to rely on groovy)
2. You say your script only ever executes stepA (on the if statement). Have you tried swapping stepA with stepB (on the else) to prove that the else is never executed?
3. If the else is never executed (your groovy syntax on your if/else appears correct) this leads me to believe the issue is earlier in your script....have you tried adding some logging statements (log.info(pattern) and log.info(input) to ensure the variables are being assigned correctly?
4. Youre assigning the regex pattern to the 'pattern' variable. Have you tried removing this and just specifying the regex pattern against the input variable? (e.g. if(input ==~ /[0-9]{6}-{1}[0-9]{7}/) )
5. On the line
If(input=~pattern) youre using a single = symbol for assignment. Shouldnt this be equalsto instead? E.g. if(input==~pattern)
UPDATE TO POST. Regarding using =~ or ==~, check out the following link....this makes me think you should use equalsto, not the assignment operator (if i understand it correctly! https://www.quora.com/Whats-the-difference-between-a-and-in-Java )
I cant stand xmas day with my family;), so i'll have a go at playing with this later to see if i can get this to work.
Nice one,
Rich