[ptt-users] Re: patch for agentbase.py
Frank Cohen
fcohen at pushtotest.com
Mon Oct 1 15:29:51 PDT 2007
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.
>> 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?
-Frank
>
> *** agentbase.py.orig Mon Aug 13 13:59:18 2007
> --- agentbase.py Fri Sep 28 14:08:59 2007
> ***************
> *** 140,145 ****
> --- 140,146 ----
> self.steps = 0 # Counter of
> steps in transaction
>
> def get( self, url, paramsin=None ):
> + '''Make GET request to URL with params, and return
> response'''
> self.params = paramsin
> self.curl = url
>
> ***************
> *** 167,175 ****
> self.paramval = "?" + self.paramval
>
> # Form request and connect
> ! self.connect( self.curl + self.paramval )
>
> def post( self, url, params=None ):
> self.params = params
> self.curl = url
>
> --- 168,177 ----
> self.paramval = "?" + self.paramval
>
> # Form request and connect
> ! return self.connect( self.curl + self.paramval )
>
> def post( self, url, params=None ):
> + '''Make POST request to URL with params, and return
> response'''
> self.params = params
> self.curl = url
>
> ***************
> *** 186,195 ****
> for self.param in self.params:
> self.body.addParameter( self.param[0], self.param
> [1] )
>
> ! self.connect( self.curl )
>
> def connect( self, url ):
> ! ''' Checks the response for an error and logs the results
> '''
>
> self.url = url
>
> --- 188,197 ----
> for self.param in self.params:
> self.body.addParameter( self.param[0], self.param
> [1] )
>
> ! return self.connect( self.curl )
>
> def connect( self, url ):
> ! '''Connect to URL, check the response for an error, log
> the results, and return the response'''
>
> self.url = url
>
> ***************
> *** 228,234 ****
> return self.response
>
> def errMsg( self ):
> ! ''' Returns the error message showing the cause of a
> problem '''
> return "Step " + str( self.steps ) + \
> " got response " + str( self.response.getResponseCode() )
> + \
> " when requesting: '" + self.http.getURL("http")
> --- 230,236 ----
> return self.response
>
> def errMsg( self ):
> ! ''' Return the error message showing the cause of a
> problem '''
> return "Step " + str( self.steps ) + \
> " got response " + str( self.response.getResponseCode() )
> + \
> " when requesting: '" + self.http.getURL("http")
> _______________________________________________
> Users mailing list
> Users at lists.pushtotest.com
> http://lists.pushtotest.com/mailman/listinfo/users
--
Frank Cohen, PushToTest, http://www.PushToTest.com, phone 408 374 7426
TestMaker: The open-source SOA test automation tool
More information about the Users
mailing list