Search code examples
pythonregexpylot

Problems writing a regex in testcases.xml of pylot


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!


Solution

  • 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.