Login | Register
My pages Projects Community openCollabNet

Discussions > dev > Re: [maxq-dev] Obese scripts

maxq
Discussion topic

Back to topic list

Re: [maxq-dev] Obese scripts

Author fcohen
Full name Frank Cohen
Date 2004-09-27 22:10:32 PDT
Message On Sep 27, 2004, at 8:54 PM, Oliver Bock wrote:

> On 28/09/2004, at 08:08, Frank Cohen wrote:
>> ...At this rate MaxQ is going to outgrow a one-size-fits-all format
>> for the recorded scripts. For example, I really want the logging to
>> stay. I propose adding a Preferences command that allows users to
>> choose recording options.
>
> MaxQ now supports multiple script generators. Hopefully the ability
> to easily create new generators will take some of the pressure off the
> original generator class. (Each installed generator appears in the
> File -> New menu so they are easy to use.)

I see your point. I was working on the assumption that some MaxQ users
aren't Java coders and won't know that the script generator classes
exist. No prob.


>
> Both you and Hari like the logging, but I think distinguish between
> two types of logging:
>
> 1. Logging from MaxQ. MaxQ Java code uses logging to provide
> information about what it is doing. These messages are useful while
> debugging MaxQ and sometimes for understanding strange behaviour in
> your scripts. This logging is now well supported by MaxQ and can be
> turned on or suppressed using the -d and -q command line flags.
>
> 2. Logging from a script. Users need this to see what is going
> between their script and the web site being tested. Currently scripts
> report their own activities using the Jython "print" statement, but I
> guess you and Hari would prefer it was done by some other mechanism?
> Whichever mechanism that is, its output should appear in the Run
> window, not on Java's stderr.

> Could you or Hari provide some examples of the sort of logging you
> want to do?
>

I think you have it right. I'm looking for helpers that don't require
me to use a debugger when I'm debugging a script. My assertion is that
a log level variable should be in the debugging information such that
at the lowest level there is no debugging information output to the
console and that as you move the level up you get more detail, with the
highest level of details being the HTTP response from the host.

Below is my latest work on upgrading the TestMaker recorder. This is
pretty close to what I'm going to propose as TestMaker's standard
recording output. (I'm sorry for the flood but here goes...)


'''
Agent name: mytest.py
Created by: TestMaker New Agent Wizard Recorder
Created on: September 27, 2004 at 7:49 p.m.

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.pushtotes​t.com/Services/slmso​lution.html

For details on TestMaker see http://www.pushtotest.com
'''

from com.pushtotest.tool.​protocolhandler import ProtocolHandler
from com.pushtotest.tool.response import Response
from com.pushtotest.tool.logger import simplelogger
from com.pushtotest.tool import TestCase
from java.util import Date
import sys
from java.lang import Exception

class mytest:
     '''
     Conducts a functional test of a Web-enabled HTTP application
     '''

     def __init__( self, debuglevel = 0, logto="console",
follow_redirects=1, \
     stopon="none", httperror="200x", logpath="log.txt" ):
         ''' Initialize the test class '''

         self.logto = logto # Log destination (console,
chart, file)
         self.loglevel = loglvl # How much debug information to
display
                                     # 0 = none, 1 = info, 2 = details,
3 = everything
         self.logger = None # Simplelogger object for logging
to files
         self.logpath = logpath # Log file name, if applicable
         self.log( 1, "mytest: Initialize" )

         self.follow_redirects = follow_redirects # Follow HTTP 302
responses
         self.steps = 0 # Counter of steps in transaction

         # RegEx list of HTTP response codes that are NOT errors
         self.codes = [ 20., 300, 301, 302, 303, 304, 307, 401, 403,
404, 408, 41. ]

         self.http = ProtocolHandler.getP​rotocol("http")

     def setUp( self ):
         ''' Add any needed set-up code here. '''
         self.log( 1, "mytest: setUp" )
         pass

     def runTest( self ):
         ''' Run the test '''
         self.log( 1, "mytest: runTest" )

         self.http.setUrl(
'''http://examples.push​totest.com/responder​/htmlresponder?
file=file1.html''' )
         self.http.setType( HTTPProtocol.GET )
         self.response = self.http.connect()
         self.log( 2, self.response )
         TestCase.assertEqualsRegex( self.errMessage(), self.codes,
self.response.getResponseCode() )
         self.steps = self.steps + 1
         self.log( 1, "Finished step " + str( self.steps ) )

         self.http.setUrl(
'''http://examples.push​totest.com/responder​/htmlresponder''' )
         self.http.setType( HTTPProtocol.POST )
         self.body = ProtocolHandler.getBody( 'http' )
         self.http.setBody( self.body )
         self.body.addParamet​er('''firstname''', '''frank''')
         self.body.addParamet​er('''lastname''', '''cohen''')
         self.body.addParamet​er('''phone''', '''''')
         self.body.addParamet​er('''account''', '''''')
         self.body.addParamet​er('''amount''', '''''')
         self.body.addParamet​er('''Transfer''', '''Transfer Funds''')
         self.response = self.http.connect()
         self.log( 2, self.response )
         TestCase.assertEqualsRegex( self.errMessage(), self.codes,
self.response.getResponseCode() )
         self.steps = self.steps + 1
         self.log( 1, "Finished step " + str( self.steps ) )

         self.http.setUrl(
'''http://examples.push​totest.com/responder​/htmlresponder?
file=file3.html''' )
         self.http.setType( HTTPProtocol.GET )
         self.response = self.http.connect()
         self.log( 2, self.response )
         TestCase.assertEqualsRegex( self.errMessage(), self.codes,
self.response.getResponseCode() )
         self.steps = self.steps + 1
         self.log( 1, "Finished step " + str( self.steps ) )

     def tearDown( self ):
         ''' Add any needed code to end the test here. '''
         self.log( 1, "mytest: setUp" )
         pass

     ''' Supporting methods for the test class '''

     def errMessage( self ):
         return "Step " + str( self.steps ) + \
         " got response " + str( self.response.getResponseCode() ) + \
         " when requesting: '" + self.http.getURL()

     def log( self, lvl, message ):
         ''' Log results and debug information '''

         if ( self.logger == None ) and ( self.logto.count("file") ):
             try:
                 self.logger = simplelogger.getInstance()
                 self.logger.setFileName( self.logpath )
             except java.lang.Exception, ex:
                 print "Could not start logging. Shutting down. ",ex
                 sys.exit(1)

         if self.loglevel >= lvl:

             if logto.count("console"): # Display the message on the
console
                 print message

             if logto.count("file"): # Save the message to a file
                 self.log.log( entry )

             if logto.count("sql"): # Insert the message into a
database table
                 '''
                 Add the JDBC commands to insert the message into a
database
                 table. These commands often look like this:

                 from java.sql import *
                  
Class.forName("COM.i​bm.db2.jdbc.app.DB2D​river").newInstance(​)
                 con = DriverManager.getConnection( 'jdbc:db2:sample',
'frank','loveslorette');
                 stmt = con.createStatement()
                 sql = "INSERT into logtable( message ) values " +
message + " )"
                 rs = stmt.executeQuery(sql)
                 rs.close()
                 stmt.close()
                 con.close()
                 '''

'''
Convenience amin 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 " myTest.py: Functional test of a Web application "
     print "===================​====================​================"
     print "Test created by TestMaker from http://www.pushtotest.com"
     print

     test = mytest()
     test.runTest()


>> 2) Add a regex way to validate http response codes.
>
> If anyone wants to match response codes with a regular expressions
> then they can just change:
>
> self.assertEquals("Assert number 2 failed", 200,
> self.getMethod().get​StatusCode())
>
> to (say)
>
> self.assert(re.match​(r'20[012]', self.getMethod().get​StatusCode()))
>
> Is this sufficient? How would you see that the code would look?
>

Nice! Works for me.


>
> Oliver
>
>
> --------------------​--------------------​--------------------​---------
> To unsubscribe, e-mail: dev-unsubscribe at maxq dot tigris dot org
> For additional commands, e-mail: dev-help at maxq dot tigris dot org
>
>
---
Frank Cohen, PushToTest, http://www.PushToTest.com, phone: 408 374 7426
Author of "Java Testing and Design: From Unit Tests to Automated Web
Tests"
from Prentice Hall, details at http://thebook.pushtotest.com


--------------------​--------------------​--------------------​---------
To unsubscribe, e-mail: dev-unsubscribe at maxq dot tigris dot org
For additional commands, e-mail: dev-help at maxq dot tigris dot org

« Previous message in topic | 18 of 24 | Next message in topic »

Messages

Show all messages in topic

[maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-27 14:51:38 PDT
     Re: [maxq-dev] Obese scripts fcohen Frank Cohen 2004-09-27 15:08:32 PDT
         Re: [maxq-dev] Obese scripts fcohen Frank Cohen 2004-09-27 15:21:33 PDT
             Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-27 20:59:38 PDT
                 Re: [maxq-dev] Obese scripts fcohen Frank Cohen 2004-09-27 22:14:42 PDT
                 Re: [maxq-dev] Obese scripts bitter lee 2004-09-27 23:37:48 PDT
                     Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-29 14:32:39 PDT
                         Re: [maxq-dev] Obese scripts bitter lee 2004-09-29 18:49:38 PDT
                 Re: [maxq-dev] Obese scripts bitter lee 2004-09-27 23:38:33 PDT
                     Re: [maxq-dev] Obese scripts hdara at primavera dot com hdara at primavera dot com 2004-09-28 10:29:04 PDT
                         Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-28 14:11:22 PDT
                             Re: [maxq-dev] Obese scripts hdara at primavera dot com hdara at primavera dot com 2004-09-28 14:29:05 PDT
                                 Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-28 16:10:32 PDT
                                 Re: [maxq-dev] Obese scripts avery1701 Matt Avery 2004-09-29 07:07:51 PDT
                                     Re: [maxq-dev] Obese scripts avery1701 Matt Avery 2004-09-29 07:49:04 PDT
                                         Re: [maxq-dev] Obese scripts hdara at primavera dot com hdara at primavera dot com 2004-09-29 10:16:43 PDT
         Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-27 20:54:23 PDT
             Re: [maxq-dev] Obese scripts fcohen Frank Cohen 2004-09-27 22:10:32 PDT
                 [maxq-dev] Regular expressions in Jython? fcohen Frank Cohen 2004-09-27 22:40:49 PDT
                     Re: [maxq-dev] Regular expressions in Jython? oliverbock Oliver Bock 2004-09-28 14:08:27 PDT
                         Re: [maxq-dev] Regular expressions in Jython? fcohen Frank Cohen 2004-09-28 14:13:34 PDT
     Re: [maxq-dev] Obese scripts hdara at primavera dot com hdara at primavera dot com 2004-09-27 15:26:32 PDT
         Re: [maxq-dev] Obese scripts oliverbock Oliver Bock 2004-09-27 21:00:49 PDT
             Re: [maxq-dev] Obese scripts hdara at primavera dot com hdara at primavera dot com 2004-09-27 22:47:15 PDT
Messages per page: