s

nGrinder学习笔记 — post请求

https://blog.csdn.net/meyoung01/article/details/50435881

import HTTPClient.HTTPResponse
import HTTPClient.NVPair
import ch.qos.logback.classic.Level
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.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
import org.junit.Test
import org.junit.runner.RunWith
import org.slf4j.LoggerFactory import static net.grinder.script.Grinder.grinder
import static org.hamcrest.Matchers.is
import static org.junit.Assert.assertThat /**
* Created by lindows
*/
@RunWith(GrinderRunner)
class LoginDemo {
public static GTest test
public static HTTPRequest request @BeforeProcess
public static void beforeProcess() {
HTTPPluginControl.getConnectionDefaults().timeout = 6000
test = new GTest(1, "192.168.70.206")
request = new HTTPRequest()
test.record(request);
grinder.logger.info("before process.");
} @BeforeThread
public void beforeThread() {
// 只打印错误的log
LoggerFactory.getLogger("worker").setLevel(Level.ERROR) grinder.statistics.delayReports = true;
grinder.logger.info("before thread.");
} private NVPair[] headers() {
return [
new NVPair("Content-type", "application/json;charset=UTF-8")
];
} @Test
public void test1() {
// json字符串
def json = '{"tenant_code":"XXX","user_name":"XX","password":"X","skip_duplicate_entries":true,"type":"0"}';
// 发起请求
HTTPResponse result = request.POST("http://192.XXX.XX.XXX:XXXX/XXX/XX/login", json.getBytes(), headers());
grinder.logger.info(result.getText());
grinder.logger.info(result.getHeader("Content-type")); if (result.statusCode == 301 || result.statusCode == 302) {
grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
} else {
assertThat(result.statusCode, is(200));
}
}
}

end

nGrinder TestRunner http post json的更多相关文章

  1. nGrinder TestRunner DNS / sun.net.spi.nameservice.NameServiceDescriptor

    s ngrinder3.3控制台验证脚本报错 http://ngrinder.642.n7.nabble.com/ngrinder3-3-td1301.html 目前发现3.3版本在控制台校验脚本报错 ...

  2. nGrinder TestRunner XFF / X-Forwarded-For

    s 我们在压测请求报文里面带了这个"x-forward-for":"10.24.51.132"这个字段,所以我们所有的压测请求穿透到应用系统的时候,应用系统上采 ...

  3. nGrinder工具进行接口性能测试

    1.背景 之前在这篇文章中性能测试初探—接口性能测试介绍过nGrinder,本文将介绍在nGrinder脚本中使用资源文件中数据作为接口参数和解析生成的CSV结果,生成TPS标准差,TPS波动率,最小 ...

  4. 基于Groovy搭建Ngrinder脚本调试环境

    介绍 最近公司搭建了一套压力测试平台,引用的是开源的项目 Ngrinder,做了二次开发,在脚本管理方面,去掉官方的SVN,引用的是Git,其他就是做了熔断处理等. 对技术一向充满热情的我,必须先来拥 ...

  5. [asp.net core]project.json(1)

    摘要 前面介绍了使用vs2015新建asp.net core web的内容,这篇文章学习下project.json文件的内容. project.json 原文:https://docs.microso ...

  6. Groovy获取json和xml数据

    如果是xml就用这个 // to read a node from your Response def grUtils = new com.eviware.soapui.support.GroovyU ...

  7. Android上解析Json格式数据

    package com.practice.json; import org.json.JSONArray; import org.json.JSONException; import org.json ...

  8. 使用Groovy处理SoapUI中Json response

    最近工作中,处理最多的就是xml和json类型response,在SoapUI中request里面直接添加assertion处理json response的话,可以采用以下方式: import gro ...

  9. nGrinder Loadrunner vs nGrinder

    s d 功能 参数类型 取值方式 迭代方式 Loadrunner实现方式 nGrinder实现方式 参数化 文件  sequential (顺序取值) Each Iteration (每次迭代) 在参 ...

随机推荐

  1. Idea中JavaWeb项目部署

    1. 添加应用服务器tomcat 2. 将tomcat配置添加到项目中 artifacts配置:添加deploy, 添加artifacts,选择Web Application: Exploded &g ...

  2. Codeforces Round #437 Div. 1

    A:显然构造一组只包含1和2面值的数据即可. #include<iostream> #include<cstdio> #include<cmath> #includ ...

  3. 洛谷P1209修理牛棚题解

    题目 这个题一眼看上去是一个贪心,但是一个贪心题就一定要用一个贪心的做法来做吗,为什么不能写一个DP呢,这个题我们可以从他修理牛棚的角度来看,价值就是一个木板可以修几个,但是也同时消耗掉了一个木板的长 ...

  4. python中切片的理解

    Python中什么可以切片 l  Python中符合序列的有序序列都支持切片(slice) l  如:列表,字符,元祖 Python中切片的格式 l  格式:[start : end : step] ...

  5. 【hdu 6172】Array Challenge(数列、找规律)

    多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...

  6. hdu5017 Ellipsoid (模拟退火)

    Ellipsoid 原题链接 题目描述 给定.一个要满足的椭球的方程\(ax^2+by^2+cz^2+dyz+exz+fxy=1\) 求球面上一个点到原点\((0,0,0)\)的距离最小. 有多组输入 ...

  7. 【CF1097F】Alex and a TV Show(bitset)

    [CF1097F]Alex and a TV Show(bitset) 题面 洛谷 CF 题解 首先模\(2\)意义下用\(bitset\)很明显了. 那么问题在于怎么处理那个\(gcd\)操作. 然 ...

  8. [hexo]如何更换主题、删除文章

    如何修改主题 hexo有很多主题,每个人可以选择自己喜欢的主题来应用,也可以自己设计主题并且上传形成公共主题供大家下载. 如果是自己设计主题的话,会稍微麻烦一些,需要自己配置很多文件,并且编写css以 ...

  9. POJ 1845 Sumdiv(逆元)

    题目链接:Sumdiv 题意:给定两个自然数A,B,定义S为A^B所有的自然因子的和,求出S mod 9901的值. 题解:了解下以下知识点   1.整数的唯一分解定理 任意正整数都有且只有唯一的方式 ...

  10. NOIP 飞扬的小鸟 题解

    题目描述 Flappy Bird是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管或者掉在地上的话,便宣 ...