request.json
Save as request.json
TestRunner.groovy
Save as TestRunner.groovy
import static net.grinder.script.Grinder.grinder import static org.hamcrest.Matchers.* import static org.junit.Assert.* import net.grinder.plugin.http.HTTPPluginControl import net.grinder.plugin.http.HTTPRequest import net.grinder.script.GTest import net.grinder.scriptengine.groovy.junit.GrinderRunner import net.grinder.scriptengine.groovy.junit.annotation.AfterThread import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread import org.codehaus.groovy.reflection.ReflectionUtils; import org.junit.Test import org.junit.runner.RunWith import org.ngrinder.recorder.RecorderUtils import HTTPClient.CookieModule import HTTPClient.HTTPResponse /** * A simple example using the HTTPRequest that contain headers, cookies, body. * * This script is automatically generated by nGrinder recorder. * * @author Gisoo.Gwon */ @RunWith(GrinderRunner) class TestRunner { public static GTest test public static HTTPRequest request public static def requestJson public Object cookies = [] @BeforeProcess public static void beforeProcess() { HTTPPluginControl.getConnectionDefaults().timeout = 6000 HTTPPluginControl.getConnectionDefaults().setFollowRedirects(true) test = new GTest(1, "Test1") request = new HTTPRequest() // Upload request.txt at resources folder // If use Groovy Manve porject, "ReflectionUtils.getCallingClass(0).getResourceAsStream("/request.json").getText("UTF-8")" String requestStr = new File("./resources/request.json").getText("UTF-8") requestJson = RecorderUtils.parseRequestToJson(requestStr) } @BeforeThread public void beforeThread() { test.record(this, "test") grinder.statistics.delayReports=true HTTPResponse result
cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext()) } @Test public void test() { cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) } HTTPResponse result
cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext()) } @AfterThread public void afterThread() { cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) } HTTPResponse result
} }
TestRunner.py
Save as TestRunner.py
# -*- coding:utf-8 -*- # A simple example using the HTTPRequest that contain headers, cookies, body. # This script is automatically generated by nGrinder recorder. # # @author Gisoo.Gwon import codecs from net.grinder.script.Grinder import grinder from net.grinder.script import Test from net.grinder.plugin.http import HTTPRequest from net.grinder.plugin.http import HTTPPluginControl from org.ngrinder.recorder import RecorderUtils from HTTPClient import CookieModule control = HTTPPluginControl.getConnectionDefaults() control.followRedirects = 1 # if you want to increase the timeout, please modify the following option. control.timeout = 6000 test1 = Test(1, "Test1") request = HTTPRequest() class TestRunner: # initlialize a thread def __init__(self): test1.record(TestRunner.__call__) grinder.statistics.delayReports=True requestStr = codecs.open("./resources/request.json", "r", "UTF-8").read() self.requestJson = RecorderUtils.parseRequestToJson(requestStr)
self.cookies = CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext()) pass # test method def __call__(self): for c in self.cookies: CookieModule.addCookie(c,HTTPPluginControl.getThreadHTTPClientContext())