[ptt-users] Re: patch for agentbase.py

Lars Huttar lars_huttar at sil.org
Mon Oct 1 15:42:49 PDT 2007


On 10/1/2007 5:29 PM, Frank Cohen wrote:
> Dear Lars:
>
> Thank you for the patch. I opened a ticket to track the change:
> http://bugs.pushtotest.com/ticket/163
>
>>> Hello,
>>> I made a few small 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.
>
> Your patches look good and I will make sure they are incorporated into 
> the next TestMaker.
>
Great. Thank you.
>
>>> 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.
>
>
> These suggestions look like good and appropriate enhancements to 
> agentbase.py. Regex expressions are already in use in agentbase.py to 
> evaluate the HTTP response code (that a look at successcodes.) Adding 
> an XPath expression evaluator would be a good addition. TestMaker 
> already ships with Xerces for an XPath evaluator.
>
> What do you think?
>
Sounds perfect.

If I continue to have time tomorrow, I will work on it, unless I hear 
that somebody else will do it.

Regards,
Lars



More information about the Users mailing list