ngrinder里,如何测试上传文件的接口?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ngrinder里,如何测试上传文件的接口?

Frank.Wang
今天碰到一个这样的需求,需要压测上传一个文件的接口。
这样的接口的脚本应该要怎么写?
Reply | Threaded
Open this post in threaded view
|

Re: ngrinder里,如何测试上传文件的接口?

taohuang
按这个案例方法可以

http://grinder.sourceforge.net/g3/script-gallery.html#form.py

class TestRunner:
    def __call__(self):
 
        files = ( NVPair("self", "form.py"), )
        parameters = ( NVPair("run number", str(grinder.runNumber)), )
 
        # This is the Jython way of creating an NVPair[] Java array
        # with one element.
        headers = zeros(1, NVPair)
 
        # Create a multi-part form encoded byte array.
        data = Codecs.mpFormDataEncode(parameters, files, headers)
        grinder.logger.output("Content type set to %s" % headers[0].value)
 
        # Call the version of POST that takes a byte array.
        result = request1.POST("/upload", data, headers)

groovy版本参考post源码,类似