Skip to content

Rough Book

random musings

Menu
  • About Me
  • Contact
  • Projects
    • bAdkOde
    • CherryBlossom
    • FXCalendar
    • Sulekha
Menu

Writing Performance Tests in Grinder using a Framework

Posted on September 16, 2009June 10, 2012 by vivin

Page methods

Similar to a typical recorded test-script, the page methods of the LoginTask class correspond to each unique page that was recorded during the task. The code in these methods is very similar to the one in a recorded test-script. However, in the original script, parameter values within a querystring (for GETs) were pulled out into "tokens" and were turned into instance variables of the TestRunner class. For example, the querystring parameter msg would become self.token_msg. In our framework, however, the querystring parameters and their default values are stored in the parameters dictionary and accessed the same way that POST parameters and values are.

run() method

The run() method is similar to the __call()__ method in a recorded test-script. The only difference is that call the callParameterizingMethodFor method before we actually call the page method. You should now be able to see how we can easily parameterize the values used by requests in a page method. The parameterizing method will modify the values in the parameters hash, and these values will be used by the requests in the corresponding page method.

Hopefully you now have a clearer picture of the framework. You should now be able to see how we can design tasks to be discrete units that we can reuse, customize, and parameterize to our wishes. Even better: you don't have to write the code for these tasks from scratch. I've written a translator script in Perl that converts the XML data recorded by TCPProxy and converts it into a class like the one above (I'll talk about that later). Now that you've seen how a task is designed, let's go up one level and take a look at the Scenario class.

The Scenario class

The Scenario class (as the name suggests) describes a particular scenario. It contains a list of tasks that it will execute sequentially. It looks like this:

Scenario.py
[sourcecode language="python"]
import warnings

class Scenario:
def __init__(self, description, urlDict):
if(len(urlDict.keys()) == 0):
raise Exception("Cannot set " + self.__class__.__name__ + ".urlDict to an empty dictionary.")
else:
self.description = description
self.urlDict = urlDict
self.tasks = []

def addTask(self, task):
if(hasattr(task, "setUrlDict")):
task.setUrlDict(self.urlDict)
else:
raise Exception(task.__class__.__name__ + " does not implement setUrlDict()!")

if(hasattr(task, "initializeTask")):
task.initializeTask()
else:
raise Exception(task.__class__.__name__ + " does not implement initializeTask()!")

if(hasattr(task, "run")):
self.tasks.append(task)
else:
raise Exception(task.__class__.__name__ + " does not implement run()!")

def setUrlDict(self, url):
warnings.warn("Scenario.urlDict is a read-only property that can only be initialized in the constructor.")

def getUrlDict(self):
return self.urlDict

def setUrl(self, key, value):
warnings.warn("Cannot modify Scenario.urlDict because it is a read-only property")

def getUrl(self, key):
return self.urlDict[key]

urlDict = property(getUrlDict, setUrlDict)

def run(self):
for task in self.tasks:
if(hasattr(task, "run")):
grinder.logger.output("Running " + task.__class__.__name__ + " now!", grinder.logger.TERMINAL)
task.run()
else:
raise Exception(task.__class__.__name__ + " does not implement run()!")
[/sourcecode]

Pages: 1 2 3 4 5 6 7 8 9 10

52 thoughts on “Writing Performance Tests in Grinder using a Framework”

Comments navigation

Older comments
  1. Chandu says:
    August 25, 2014 at 7:12 am

    I configured, Grinderstone, PyDev and Jython on Eclipse Mars (version 4.5) with java 1.7, will can I be able to start recording scripts from Eclipse directly ? to do that should I include the startTCPProxy.sh from Eclipse or is there any other way ? Please adivise, which approach will be more productive , appreciate your response.

    Reply
  2. Chandu says:
    September 9, 2014 at 12:45 pm

    how to parameter values in quotes in jython, this is my method :
    BaseSTSSchedulerTask.__init__(self, Test(testId, “Get Service Group by ID”), hostPort, ‘/SchServices/api/servicegroup/9999’, HEADERS)

    I want to replace the value 9999 with a variable which is returned from a method., like id= Data.getID(). I tried doing this ‘/SchServices/api/servicegroup/’+id, it does not help . Any idea how to handle this ?

    Reply

Comments navigation

Older comments

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • February 2023
  • April 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • September 2019
  • August 2019
  • July 2019
  • June 2019
  • May 2019
  • March 2019
  • February 2019
  • January 2019
  • December 2018
  • November 2018
  • September 2018
  • August 2018
  • July 2018
  • June 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • June 2017
  • March 2017
  • November 2016
  • August 2016
  • July 2016
  • June 2016
  • February 2016
  • August 2015
  • July 2014
  • June 2014
  • March 2014
  • December 2013
  • November 2013
  • September 2013
  • July 2013
  • June 2013
  • March 2013
  • February 2013
  • January 2013
  • October 2012
  • July 2012
  • June 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • July 2011
  • June 2011
  • May 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • August 2008
  • March 2008
  • February 2008
  • November 2007
  • July 2007
  • June 2007
  • May 2007
  • March 2007
  • December 2006
  • October 2006
  • September 2006
  • August 2006
  • June 2006
  • April 2006
  • March 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • February 2005
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • July 2003
  • June 2003
  • May 2003
  • March 2003
  • February 2003
  • January 2003
  • December 2002
  • November 2002
  • October 2002
  • September 2002
  • August 2002
  • July 2002
  • June 2002
  • May 2002
  • April 2002
  • February 2002
  • September 2001
  • August 2001
  • April 2001
  • March 2001
  • February 2001
  • January 2001
  • December 2000
  • November 2000
  • October 2000
  • August 2000
  • July 2000
  • June 2000
  • May 2000
  • March 2000
  • January 2000
  • December 1999
  • November 1999
  • October 1999
  • September 1999
©2023 Rough Book | Built using WordPress and Responsive Blogily theme by Superb
All original content on these pages is fingerprinted and certified by Digiprove