6.2 多事务

一个脚本里面如果需要包含多个接口请求,则需要先定义多个request并在call方法里面分别进行接口请求(请求为并发执行)。示例如下:

def call(self):

   result1 = request1.GET("http://waf-demo.qa.web.sdp.101.com/benchmark/blank")

   if result1.getText().find("age") != -1 :

      grinder.statistics.forLastTest.success = 1

   else :

      grinder.statistics.forLastTest.success = 0



   result2 = request2.GET("http://waf-demo.qa.web.sdp.101.com/benchmark/blank")

   if result2.getText().find("age") != -1 :

      grinder.statistics.forLastTest.success = 1

  else :

      grinder.statistics.forLastTest.success = 0

也可以先自定义事务方法,在并在call方法中调用,实例如下:

def tran1(self):

result = request1.GET("http://172.24.128.2/")

if result.getText().find("Welcome") != -1 :

    grinder.statistics.forLastTest.success = 1

else :

    grinder.statistics.forLastTest.success = 0

def tran2(self):

result = request2.GET("http://777.nd.com.cn/html/index.html")

if result.getText().find("Object moved") != -1 :

    grinder.statistics.forLastTest.success = 1

else :

    grinder.statistics.forLastTest.success = 0

def call(self):

self.tran1()

grinder.sleep(1000)

self.tran2()

results matching ""

    No results matching ""