Ticket #163 (closed enhancement: fixed)

Opened 11 months ago

Last modified 6 months ago

Agentbase.py improvements: verify response

Reported by: fcohen Owned by: fcohen@…
Priority: critical Milestone:
Version: 5.1 Keywords: agentbase response verify
Cc:

Description

Lars Huttar wrote:

Hello, I made a few modifications to agentbase.py to make it more amenable to unit and functional testing of web applications. As far as I can tell, currently the only kinds of verification supported are: - going to a URL (via click or goto) succeeded, that is, returned an HTTP success code - the title of a page is the expected string

Often, you want to check that data is correct, e.g. that the application returned the correct data value for a query. To do this, you want to check the content returned. I modified the get() and post() functions to return the content as a string, so that these checks could be performed more easily by jython scripts.

The proposed patch is attached.

It would also be useful to add utility functions for checking that the returned content contains (or doesn't contain) a specified string: def mustContain(self, content, requiredString, diagnostic):

Assert that content contains requiredString; else raise exception with diagnostic message.

def mustNotContain(self, content, requiredString, diagnostic):

Assert that content does not contain requiredString; else raise exception with diagnostic message.

And it would be nice to have built-in support for XPath expressions, so that this doesn't have to be done by hand each time: def evalXPath(self, content, xpathExpr):

Evaluate XPath expression with regard to content, and return result.

This could be used either for boolean tests:

not(/*/body//p[contains(., 'error')])

or retrieving values

/*/body//table[@class = 'accountDetails']/tr[td[1] = 'State']]/td[2]

Is there already support for these kinds of things, and I missed it? If not, I would be happy to work on this, although I'm sure there are others who are more familiar with the relevant Python libraries.

Regards, Lars

Attachments

agentbase.txt (2.4 kB) - added by fcohen 11 months ago.
Diff to TestMaker_home/lib/agentbase.py
agentbase2.txt (2.9 kB) - added by gary 10 months ago.

Change History

Changed 11 months ago by fcohen

Diff to TestMaker_home/lib/agentbase.py

Changed 11 months ago by fcohen

  • type changed from defect to enhancement

Changed 10 months ago by fcohen

  • priority changed from major to critical

Changed 10 months ago by gary

Here is a unified diff patch agentbase2.txt to CVS file rev 1.4 that includes the patch from Lars and also the routine he requested evalXPath. Since multiple nodes can be returned for a given XPath, I have each of them appended to the string that is returned to the caller. The function is called as follows :

        response = self.post( self.baseURI + "update_owner.asp", self.ownerparams)
        self.content = self.evalXPath( response, "//h:html/h:body" ) # h is required to specify the namespace
        if self.content[1:23] != "Owner has been updated":
            junit.framework.TestCase.fail(self.content)

I also added a setAuthentication function to handle web sites that require HTTP authentication instead of form authentication. I haven't tested these two functions using the latest CVS code, as I am using TestMaker 5.1 build here.

Gary Thorne
gthornejr@…

Changed 10 months ago by gary

Changed 7 months ago by fcohen

  • status changed from new to closed
  • resolution set to fixed

I applied Lars and Gary's patches. Thank you! -Frank

Changed 6 months ago by root

Milestone release deleted

Note: See TracTickets for help on using tickets.