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 15:08:32 PDT
Message Nice summary of the problem and solution. I urge you to consider two
changes to your proposal.

1) It's nice to see how many ideas are being passed around the MaxQ
project. 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.

2) Add a regex way to validate http response codes.

-Frank


On Sep 27, 2004, at 2:51 PM, Oliver Bock wrote:

> I'm concerned that the scripts being generated by MaxQ are complex and
> too large. While I mainly use my new "compact" scripts, I do think
> that the old style is still useful for new users because they can see
> what is happening. Its simplicity is also useful for people who are
> only generating a few scripts and don't mind hand editing them. Here
> is a script that submits a single form with four parameters:
>
> # Generated by MaxQ
> [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
> from sys import *
>
> from com.bitmechanic.maxq import Config
> global driverPkg, validatorPkg, logger
> if __name__ == 'main':
> driverPkg = Config.getDriverPkgName()
> validatorPkg = Config.getValidatorPkgName()
>
> # Determine the driver for this testcase.
> exec 'from '+driverPkg+' import HttpTestCase'
>
> # Determine the validator for this testcase.
> exec 'from '+validatorPkg+' import Validator'
>
> # imports
> from junit.textui import TestRunner
> from java.lang import *
> from java.io import *
> from java.util import *
> from org.apache.commons.httpclient import NameValuePair
>
>
> # definition of test class
> [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
> class MaxQTest(HttpTestCase):
> def __init__(self, testName):
> HttpTestCase.__init__(self, testName)
>
> # Add setup code here. See Junit javadoc.
> def setUp(self):
> pass
>
> # Add tearDown code here. See Junit javadoc.
> def tearDown(self):
> pass
>
> # Runs the test
> def runTest(self):
> self.doTest()
>
> # Test script
> def doTest(self):
> self.currentParams = ArrayList()
> self.currentParams.a​dd(NameValuePair('''​scope''',
> '''projectAndSubs'''))
> self.currentParams.a​dd(NameValuePair('''​resultsPerPage''',
> '''40'''))
> self.currentParams.a​dd(NameValuePair('''​query''',
> '''ghjghj'''))
> self.currentParams.a​dd(NameValuePair('''​Button''', '''Go'''))
> print "Testing URL: %s" %
> self.replaceURL('''http://maxq.tigris.o​rg/servlets/Search?
> scope=projectAndSubs​&resultsPerPage=​40&query=ghjghj​&Button=Go''')
> self.currentUrl = "http://maxq.tigris.o​rg/servlets/Search"
> list = self.currentParams
> Validator.validateRequest(self, self.getMethod(), "get",
> self.currentUrl, self.currentParams)
> self.get(self.currentUrl, list)
> print "Response code: %s" % self.getMethod().get​StatusCode()
> self.assertEquals("Assert number 2 failed", 200,
> self.getMethod().get​StatusCode())
> Validator.validateRe​sponse(self, self.getMethod(),
> self.currentUrl, self.currentParams)
>
> # ^^^ Insert new recordings here. (Do not remove this line.)
>
>
> ####################​####################​##
>
> # Code to load and run the test
> if __name__ == 'main':
> logger = Config.getTestLogger()
> test = MaxQTest("MaxQTest")
> test.Run()
>
> SIXTY SIX LINES!!! When it's simple, Jython/Python is a language that
> inexperienced programmers can understand and get started on quickly.
> Presumably this is why it was chosen for MaxQ. But this? Can you
> imagine the reaction of most people when they download MaxQ and it
> produces this stuff? They go elsewhere.
>
> I propose these changes:
>
> - We switch from encoding parameters in an ArrayList of NameValuePairs
> to a Jython array of tuples. This will make the scripts more concise
> and will stop them being tied to HttpClient. e.g.
> self.currentParams = [('''scope''', '''projectAndSubs'''),
> ('''resultsPerPage''', '''40'''),
> ('''query''', '''ghjghj'''),
> ('''Button''', '''Go''')]
>
> - We remove the empty setUp() and tearDown() functions. They are
> documented and so need not be included in every script. We can also
> include some sample scripts showing how to use them.
>
> - We get rid of doTest() and put recorded code in runTest(). It is
> trivial for the user to break the code into multiple functions if this
> is what she desires. Again, examples will assist.
>
> - We stop using esoteric syntax to allow Config to override the class
> for HttpTestCase and Validator. No new MaxQ user will want to do
> this, rather they will wonder: "What they hell is this? This doesn't
> appear in the Python tutorial!" Now that the JythonGenerator code is
> much simpler, it would be easy to derive a new class from
> JythonGenerator to change these base classes for whichever
> sophisticated users wish it.
>
> - We stop loading a logger. We do not want people to use a logger
> because it will stop output going to stdout/stderr and therefore it
> will not appear in MaxQ's run window. "print" is obviously easier for
> a user to understand, and that's what the script uses anyway.
>
> We would end up with a script like this:
>
> # Generated by MaxQ
> [com.bitmechanic.max​q.generator.JythonCo​deGenerator]
> from com.bitmechanic.maxq import Validator
>
> class MaxQTest(HttpTestCase):
> def runTest(self):
> self.currentParams = [('''scope''', '''projectAndSubs'''),
> ('''resultsPerPage''', '''40'''),
> ('''query''', '''ghjghj'''),
> ('''Button''', '''Go''')]
> print "Testing URL: %s" %
> self.replaceURL('''http://maxq.tigris.o​rg/servlets/Search?
> scope=projectAndSubs​&resultsPerPage=​40&query=ghjghj​&Button=Go''')
> self.currentUrl = "http://maxq.tigris.o​rg/servlets/Search"
> Validator.validateRequest(self, self.getMethod(), "get",
> self.currentUrl, self.currentParams)
> self.get(self.currentUrl, self.currentParams)
> print "Response code: %s" % self.getMethod().get​StatusCode()
> self.assertEquals("Assert number 2 failed", 200,
> self.getMethod().get​StatusCode())
> Validator.validateRe​sponse(self, self.getMethod(),
> self.currentUrl, self.currentParams)
>
> # ^^^ Insert new recordings here. (Do not remove this line.)
>
>
> # Code to load and run the test
> if __name__ == 'main':
> test = MaxQTest("MaxQTest")
> test.Run()
>
>
> 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 | 2 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: