0

I have to verify a list of strings to be present in a response to a soap request. I am using pylot testing tool. I know that if I use a string inside <verify>abcd</verify>element it works fine. I have to use regex though and I seem to face problems with the same since I am not good with regex.

I have to verify if <TestName>Abcd Hijk</TestName> is present in my response for the request sent.

Following is my attempt to write the regex inside testcases.xml

<verify>[.TestName.][\w][./TestName.]</verify>

Is this the correct way to write a regex in testcases.xml file? I want to exactly verify the tagnames and its values mentioned above.

When I run the tool, it gives me no errors. But If I change the the characters to <verify>[.TesttttName.][\w][./TestttttName.]</verify> and run the tool, it still run without giving errors. While this should be a failed run since no tags like the one mentioned is present in the response!

Could someone please tell me what I am doing wrong in the regex here?

Any help would be appreciated. Thanks!

Rashmi Nagaraja
  • 801
  • 11
  • 20
  • The regex is correct syntactically, but it doesn't mean what you think. – nhahtdh Jan 03 '13 at 06:00
  • @nhahtdh: Thanks for your reply. Could you please let me know what I have to do so that it means what I think? – Rashmi Nagaraja Jan 03 '13 at 06:03
  • What do you expect inside TestName element? Just `\w` will not match space. `\w` matches English alphabet `a-zA-Z`, digit `0-9` and underscore `_`. – nhahtdh Jan 03 '13 at 06:05
  • @@nhahtdh: Inside testname like you have said, I will modify, but I am more concerned about tags. The answer you have given below, I will try to run the code on it and see. I tried using hex replacement for the same and it didnt work yesterday. I will try what you have said. I think python interprets it in a different way. – Rashmi Nagaraja Jan 03 '13 at 06:24

2 Answers2

1

The regex used should be like the following.

<verify>&amp;lt;TestName&amp;gt;[\w\s]+&amp;lt;/TestName&amp;gt;</verify>

The reason being, Pylot has the response content in the form of a text i.e, [the above part in the response would be like the following]

.......&lt;TestName&gt;ABCd Hijk&lt;/TestName&gt;.....

What Pylot does is, when it parses element in the Testcases.xml, it takes the value of the element in TEXT format. Then it searches for the 'verify text' in the response which it got from the request.

Hence whenever we would want to verify anything in Pylot using regex we need to put the regex in the above format so that it gives the required results.

Note: One has to be careful of the response format received. To view the response got from the request, Enable the Log Messages on the tool or if you want to view the response on the console, edit the tools engine.py module and insert print statements.

Rashmi Nagaraja
  • 801
  • 11
  • 20
  • It is quite weird how the content of the response is entity escaped. Anyway, you should accept your own answer, since it solves your problem. – nhahtdh Jan 03 '13 at 12:16
0

The raw regular expression (no XML escape). I assume you want to accept English alphabet a-zA-Z, digits 0-9, underscore _ and space characters (space, new line, carriage return, and a few others - check documentation for details).

<TestName>[\w\s]+</TestName>

You need to escape the < and > to specify inside <verify> tag:

&lt;TestName&gt;[\w\s]+&lt;/TestName&gt;
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
  • I tried the above, but unfortunately pylot tool doesn't understand the < and > escape chars. I had earlier tried ` and b for the same and it failed. – Rashmi Nagaraja Jan 03 '13 at 06:31
  • The tool was working in a different way which I figured it out. I explained the same in my answer. Thanks to your inputs on regex. It did help me in writing my regex. – Rashmi Nagaraja Jan 03 '13 at 09:56