ngrinder python编写case

1.case 用户python代码编写

# -*- coding:utf-8 -*-


# A simple example using the HTTP plugin that shows the retrieval of a
# single page via HTTP. 
#
# This script is automatically generated by ngrinder.
#
# @author admin
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 java.util import Date
from HTTPClient import NVPair, Cookie, CookieModule


control = HTTPPluginControl.getConnectionDefaults()
# if you don't want that HTTPRequest follows the redirection, please modify the following option 0.
# control.followRedirects = 1
# if you want to increase the timeout, please modify the following option.
control.timeout = 6000


#代码hi自动生成,这个给测试开发减少工量;


test1 = Test(1, "testdo")
request1 = HTTPRequest()


# Set header datas
headers = [] # Array of NVPair
# Set param datas
params = [] # Array of NVPair
# Set cookie datas
cookies = [] # Array of Cookie


class TestRunner:
# initlialize a thread 
def __init__(self):
test1.record(TestRunner.__call__)
grinder.statistics.delayReports=True
pass

def before(self):
request1.headers = headers
for c in cookies: CookieModule.addCookie(c, HTTPPluginControl.getThreadHTTPClientContext())


# test method
def __call__(self):
self.before()
#快手的话直接修改这个就可以,对开发来说比较简单的;
result = request1.GET("https://XXXXconfig/testdo", params)

# You get the message body using the getText() method.
# if result.getText().find("HELLO WORLD") == -1 :
# raise

# if you want to print out log.. Don't use print keyword. Instead, use following.
# grinder.logger.info("Hello World")

if result.getStatusCode() == 200 :
return
elif result.getStatusCode() in (301, 302) :
grinder.logger.warn("Warning. The response may not be correct. The response code was %d." %  result.getStatusCode()) 
return
else :

raise


2.自己测试的结果


INFO  
             Tests        Errors       Mean Test    Test Time    TPS          Mean         Response     Response     Mean time to Mean time to Mean time to 
                                       Time (ms)    Standard                  response     bytes per    errors       resolve host establish    first byte   
                                                    Deviation                 length       second                                 connection                
                                                    (ms)                                                                                                    

Test 1       1            0            569.00       0.00         1.74         1767.00      3078.40      0            37.00        48.00        547.00        "testdo"

Totals       1            0            569.00       0.00         1.74         1767.00      3078.40      0            37.00        48.00        547.00     

猜你喜欢

转载自blog.csdn.net/keny88888/article/details/80812871