A high-level view of the framework
To understand the framework, first let's figure out what it is that we want to do exactly. To create a scenario, our framework should let us do the following things:
- Define a scenario
- Add tasks to the scenario
- Execute the scenario
How about looking at what we want to do from a programming perspective?
- Create a scenario object
- Add the tasks we want to the scenario object
- Execute the scenario
Of course, this is still a rather simple view. We actually want to do a bit more than that. We also want to parameterize our tasks. So, the list of things we want to do actually looks like this:
- Create a scenario object
- Create an instance of a task we want
- Parameterize the task
- Add the task to the scenario object
- Repeat steps 2-4 as many times as necessary
- Execute the scenario
Now that we know what we want to do, let's take a look at the actual code behind the framework.
The Task class
All tasks that you record and create will extend the Task class. The Task class by itself is pretty simple, and not very useful. It looks like this:
Task.py:
# Base class for all Tasks. class Task: numberOfTasks = 0; def __init__(self): """Initialize properties of class""" self.urlDict = {} self.parameterizingMethods = {} Task.numberOfTasks += 1 def setUrlDict(self, urlDict): """Setter for urlDict property""" self.urlDict = urlDict def getUrlDict(self, urlDict): """Getter for urlDict property""" return self.urlDict def setUrl(self, key, value): """Sets value to 'value' of particular url in URL dict identified by key 'key'""" self.urlDict[key] = value def getUrl(self, key): """Returns value of particular url in URL dict identified by key 'key'""" return self.urlDict[key] def callParameterizingMethodFor(self, key): """Calls parameterizing method associated with page identified by key 'key'""" if(self.parameterizingMethods.has_key(key)): self.parameterizingMethods[key]() def setParameterizingMethodFor(self, key, value): """Sets parameterizing method associated with page identified by key 'key' to method in 'value'""" self.parameterizingMethods[key] = value def getParameterizingMethodFor(self, key): """Returns the parameterizing method associated with page identified by key 'key'""" return self.parameterizingMethods[key] def instrumentMethod(self, test, method_name): """Instrument a method with the given Test.""" unadorned = getattr(self.__class__, method_name) import new method = new.instancemethod(test.wrap(unadorned), None, self.__class__) setattr(self.__class__, method_name, method)
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.
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 ?