Gap in understanding for parametrization script

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Gap in understanding for parametrization script

Sean Tiley
Hello, I am hoping to get some help in parametrizing a script that I am using.

I am using Grinder 3.11 on Windows 7 machine.
I have recorded the initial script using the HttpProxy and am parametrizing the GET to include one of the ID's I am reading from a file

I have added vert trivial code to the recorded script to load a file of ID's I would like to use during execution.

When each thread runs, I want to append a random ID to the base url to make a request for a form to be rendered
This is working for me now if I hardcode the index in the list to grab, (see line below -   rawID=idList[0]).

I want to randomize the ID that is selected for each thread that runs.
my script is as follows...

Any help or insight is much appreciated.



# The Grinder 3.11
# HTTP script recorded by TCPProxy 

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
from ValidationUtils import *
import csv
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)

def createRequest(test, url, headers=None):
    """Create an instrumented HTTPRequest."""
    request = HTTPRequest(url=url)
    if headers: request.headers=headers
    test.record(request, HTTPRequest.getHttpMethodFilter())
    return request

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


request101 = createRequest(Test(101, 'GET ApplicationForm'), url0)


# Read in the file that contains the ID's
f2 = open('render.csv', 'r')
reader = csv.reader(f2)
idList = list(reader)
f2.close();

#This is for display contents of file
#for item in idList:
# a=str(item).strip('[]')
# b=a.strip('\'')
# print b



class TestRunner:
  """A TestRunner instance is created for each worker thread."""

  # A method for each recorded page.
  def page1(self):
    """GET A40179400 (request 101)."""
    urlBase='/wcfservicesTest/ABER.Zephyr.Doucment.RESTServices/RenderService.svc/Ban/'
    
    #  grab an ID from the collection and append to url base
    #  The get call has to be as follows  
    #  /wcfservicesTest/ABER.Zephyr.Doucment.RESTServices/RenderService.svc/Ban/XXXXXXXXX   
    #  where the XXXXX is replaced by a random ID from the collection

    rawID=idList[0]  # Need to get random one
    idForRender=str(rawID).strip('[]').strip('\'')
    urlForRender=urlBase+idForRender
    result = request101.GET(urlForRender, None,
( NVPair('Accept', 'text/html, application/xhtml+xml, */*'),
        NVPair('Accept-Language', 'en-US'),
        NVPair('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko'),))
        
    saveBinaryToFile2 ("RenderedForm_"+idForRender, result,"pdf")
    
    return result

  def __call__(self):
    """Called for every run performed by the worker thread."""
    self.page1()      # GET ApplicationForm (request 101)


# Instrument page methods.
Test(100, 'Page 1').record(TestRunner.page1)





--
Sean Tiley
[hidden email]

------------------------------------------------------------------------------

_______________________________________________
grinder-use mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/grinder-use
Loading...