[ptt-users] Logging

Kyle Bell kylebell at tango-networks.com
Thu Oct 26 17:11:23 PDT 2006


Paul,

You'll notice at the bottom of the file there is a line that reads:

  test = SunCom102556142( 1, 'console file ', 0,

This line is actually doing something like instantiating an object named
'test' with the definition of the class 'SunCom102556142' and passing in
parameters as part of this instantiation.  The first parameter is 1, the
second is 'console file ', the third is 0 and so on continued on the
next line of your file.

Toward the top of the file, you can find another line that reads:

  def __init__( self, debuglevel = 0, logto="console",

This function defines actions that occur during the instantiation and
also defines the parameters which may be passed in.  The very first
parameter in any definition is always a pointer to self (this object),
the second begins defining the 'visible' parameters which are passed in.
The first of these visible parameters is called 'debuglevel' and it has
a default value of 0 as defined above in the __init__ function.  When
you create the test object in the first line described above you are
passing in a value of 1 for the debuglevel value.  To get more detail in
your debug logs, you can specify a number up to 3. In this case the line
would look like this before you run your test case:

  test = SunCom102556142( 3, 'console file ', 0,

It appears as though you've managed to change the log level for this log
to be displayed at level 3 in your tearDown function:

  self.log( 3, "test: tearDown" )

What self.log() does (defined in agentbase.py module, class agentbase)
is hook off of your debuglevel parameter in the object and print for the
specified level and less.  Hence the previously mentioned line will only
be displayed in your console and file output at loglevel = 3 and the
text which will be displayed is:

  test: tearDown

While I have your attention, I'd like to mention that I find more
flexibility and more opportunity in providing verification in your test
cases by avoiding the recording tool and actually learning jython syntax
and writing your own test case code.  It is a very flexible and powerful
medium given that you can import any java API interface and use it at
whim and TestMaker provides a terrific interface to be able to develop
jython test scripts or programs if you will.  You can use your
imagination as to what might be accomplished with this interaction.  I
also appreciate the DBUtil functionality provided by the maxq portion of
TestMaker.  It is a very easy interface into databases such as mysql
which can allow you to verify the end result of potential application
interactions.

Hopefully this enhances your comprehension of how this test case works.

Happy Testing!

Kyle

On Thu, 2006-10-26 at 19:00 -0400, Paul Cuda wrote:
> I can't find where _init_ string lies
> 
> Here is the code:
> 
> '''
> Agent name: SunCom102556142
> Created on: October 26 2006 AD 12:44 PM
> Created by: TestMaker New Agent Wizard Recorder
> 
> Note:
> Turn this functional test into a scalability and load
> test using XSTest found in testmaker_home/XSTest
> 
> Turn this functional test into a Quality of Service monitor
> using PushToTest Service Monitor System (SMS) found at
> http://www.pushtotest.com/Services/slmsolution.html
> 
> For details on TestMaker see http://www.pushtotest.com
> '''
> 
> from com.pushtotest.tool.protocolhandler import ProtocolHandler,
> HTTPProtocol
> from com.pushtotest.tool.response import Response
> 
> import junit
> from java.util import Date
> import sys, re, time
> from java.lang import Exception
> from com.pushtotest.tool.util import URLCodec
> 
> # Base class of functions that support this test agent
> # find this in testmaker_home/lib/agentbase.py
> import agentbase
> reload(agentbase)
> 
> class SunCom102556142( agentbase.agentbase, junit.framework.TestCase ):
>     '''
>     Base class implements abstract methods need by recorded test agent
> script.
>     '''
> 
>     def __init__( self, debuglevel = 0, logto="console",
> follow_redirects=0, \
>     successcodes="20.|300|301|302|303|304|307|401|403|408|41.", \
>     logpath="log.txt", sleeptime_min=0, sleeptime_max=0,
> imagesleeptime=0, \
>     loadimgtags = "1", imagecache = "1", agentname="test", openlog=1 ):
>         ''' Initialize this test '''
> 
>         junit.framework.TestCase.__init__(self, agentname)
> 
>         # Call the agentbase superclass's init method
>         agentbase.agentbase.__init__( self, debuglevel, logto,
> follow_redirects, \
>         successcodes, logpath, sleeptime_min, sleeptime_max,
> imagesleeptime, \
>         loadimgtags, imagecache, agentname, openlog )
> 
>     def setUp( self ):
>         ''' Add any needed set-up code here. '''
>         self.log( 1, "test: setUp" )
>         self.config()
>         
>     def runTest( self ):
>         ''' Run the test '''
>         self.log( 1, "test: runTest" )
>         
>         self.get( '''http://10.25.56.142/login''')
>          
>         self.params = [ [ '''a''', '''default''' ],[ '''b''', '''user'''
> ],[ '''c''', '''Submit''' ],[ '''q''', '''AAAAAAAA''' ] ]
>         self.get( '''http://10.25.56.142/status.htm''', self.params)
>          
>         self.params = [ [ '''a''', '''BDA #1 (A PCS) Status''' ],[
> '''b''', '''Submit''' ],[ '''q''', '''ADNMLOBD''' ] ]
>         self.get( '''http://10.25.56.142/summout.htm''', self.params)
>          
>         self.params = [ [ '''a''', '''Refresh''' ],[ '''b''',
> '''Submit''' ],[ '''n''', '''1''' ],[ '''q''', '''ADNMLOBD''' ] ]
>         self.get( '''http://10.25.56.142/statout.htm''', self.params)
>          
>         self.params = [ [ '''a''', '''Home''' ],[ '''b''', '''Submit'''
> ],[ '''n''', '''1''' ],[ '''q''', '''ADNMLOBD''' ] ]
>         self.get( '''http://10.25.56.142/statout.htm''', self.params)
>          
>         self.params = [ [ '''a''', '''Logout''' ],[ '''b''',
> '''Submit''' ],[ '''q''', '''ADNMLOBD''' ] ]
>         self.get( '''http://10.25.56.142/summout.htm''', self.params)
>     # ^^^ Insert new recordings here.  (Do not remove this line.)
> 
> 
> 
>     def tearDown( self ):
>         ''' Add any needed code to end the test here. '''
>         self.log( 3, "test: tearDown" )
>                                   
> '''
> Convenience main method for running this test by itself
> otherwise, plug this into XSTest to turn it into a scalability
> and load test, and the Service Monitor System (SMS) for
> a Quality of Service (QOS) monitor.
> '''
> 
> if __name__ == 'main':
>     print '======================================================='
>     print 'SunCom102556142: Functional test of a Web application '
>     print '======================================================='
>     print 'Test created by TestMaker from http://www.pushtotest.com'
>     print
>     print
> 
>     '''
>     The test class takes the following parameters. See
> testmaker_home/lib/agentbase.py 
>     for implementations of these options.
> 
>     log level = 0- no logging, 1- informational messages, 2- detailed
> messages, 3- Everything
>     log destination = console - to the screen, file - to a file, 
>                       response - to the log file in xml form with the
> host response, 
>                       database - to a JDBC datasource
>     follow_redirects = 0 - do not follow HTTP 302 response codes, 1 -
> follow them automatically
>     successcodes = Regular Expression (regex) defining HTTP success
> response codes
>     logpath = path and file name to store log file
>     sleeptime_min = minimum amount of time in seconds to sleep between
> requests to the host
>     sleeptime_max = maximum amount of time to sleep between requests to
> the host
>     imagesleeptime = time in seconds to sleep between requests for <img>
> tag references
>     loadimgtags = 1 - load <img> tag references, 0 - skip them
>     imagecache = 1 - emulate a browser cache of <img> tag references, 0
> - load all <img> tags
>     logfirst = 1 - add <testmaker> element to head new log files, 0 -
> ignore
>     
>     The settings below were found in the Advanced Options panel of the
> Recorder.
>     '''
> 
> 
>     test = SunCom102556142( 1, 'console file ', 0,
> '20.|300|301|302|303|304|307|401|403|408|41.', 'log.xml', 5, 10, 2, 1,
> 1, 'SunCom102556142', 1 )
>     test.setUp()
>     test.runTest()
>     test.tearDown()
> 
>     test.closelog()
>     print "done"
> 
> Perhaps its not in the code as recorded?
> 
> 
> Paul Cuda
> _______________________________________________
> Users mailing list
> Users at lists.pushtotest.com
> http://lists.pushtotest.com/mailman/listinfo/users
> 



More information about the Users mailing list