Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Structure of Test Script

     In this post,we will go over  structure of test script.

       structure of a recorded test-script looks like this:

import statements

header definitions

url definitions

request and test definitions

class TestRunner:
     method definitions - a method is defined for each recorded page

     def __call__(self):
     calls to defined methods, which actually runs the requests

     utility function (I'll go over this later)

     calls to utility function to wrap/instrument tests (I'll go over this later)

Import statements

you will import classes that make the tests work.By default,the following are indispensable.

from net.grinder.script import Test
from net.grinder.script.Grinder import grinder
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
from HTTPClient import NVPair
The first two import statements import the Test and grinder objects, which give you access to testing framework, and its environment.
next two import statements import some utility classes which perform HTTP Requests. The NVPair class lets you organize parameters and values for POST requests into name-value pairs.

Header definitions

These headers are used to create the request objects .The generated code looks like this:

connectionDefaults = HTTPPluginControl.getConnectionDefaults()
httpUtilities = HTTPPluginControl.getHTTPUtilities()

# To use a proxy server, uncomment the next line and set the host and port.
# connectionDefaults.setProxyServer("localhost", 8001)

# These definitions at the top level of the file are evaluated once,
# when the worker process is started.

connectionDefaults.defaultHeaders = 
  ( NVPair('Accept-Language', 'en-us,en;q=0.5'),
    NVPair('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'),
    NVPair('Accept-Encoding', 'gzip,deflate'),
    NVPair('User-Agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2009060308 Ubuntu/9.04 (jaunty) Firefox/3.0.11'), )

  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', ''), )

  ( NVPair('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
    NVPair('Referer', ''), )

The first statement creates an HTTPPluginConnection object, which lets you control the behavior of the connection. The next statement creates an instance of an HTTPUtilities object which provides access to various utility methods.

In the next few lines, the script actually defines the headers. First, it sets up the default headers that are used by each request.

URL definitions

this is Test URL definitions, which look like this:

url0 = ''

Request and test definitions

this is the actual requests that we’re going to use for our tests:

# Create an HTTPRequest for each request, then replace the
# reference to the HTTPRequest with an instrumented version.
# You can access the unadorned instance using request101.__target__.

request101 = HTTPRequest(url=url0, headers=headers0)
request101 = Test(101, 'POST processLogin.jsp').wrap(request101)

request102 = HTTPRequest(url=url0, headers=headers0)
request102 = Test(102, 'GET home.jsp').wrap(request102)

request201 = HTTPRequest(url=url0, headers=headers1)
request201 = Test(201, 'GET popUpTask.jsp').wrap(request201)

request301 = HTTPRequest(url=url0, headers=headers2)
request301 = Test(301, 'POST calendarBackend.jsp').wrap(request301)
comments powered by Disqus
Page info
viewed 2675 times
translations en
posted 4 years ago by
updated 3 years ago by
View revisions
Share this article