Gatling - 脚本中常用到的方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gatling - 脚本中常用到的方法相关的知识,希望对你有一定的参考价值。

参考技术A *Add cookie:

.exec(addCookie(Cookie("<cookie_name>", "<cookie_value>").withDomain("<domain_name>")))

*打印Session:

.exec session =>

        println("session:" + session)

        session



*body:

.body(RawFileBody("<path>/0006_request.json"))

或者

.body(StringBody(

"""

"<body string>"

"""

))

<body string>里的内容来自于<path>/0006_request.json。

*Blacklist:

通常我们不希望脚本记录一些无关紧要的内容,比如一些css,js等等,这些会使report看起来很繁琐。

所以,我们在录制脚本之前,可以加一些过滤条件,比如将下边这些加到Blacklist里。

.*\.json

.*\.js

.*\.svg

.*\.woff

.*\.ico

.*\.css

.*\.jpg

.*\.png

.*\.gif

.*\.woff2

工作中常用到的一些方法

1.执行SQL(dao层的实现类中)

/**
* 通过名称查找id
* @param psname
* @return id
*/
@Override
public String findEnterpriseId(String psname) {
  String id = "";
  //查找信息的sql
  String sql = "select id from t_enterprise where psname = ‘"+psname+"‘";
  //创建Query对象接收通过createSqlQuery()方法解析sql语句得到的结果
  Query query = this.createSqlQuery(sql);
  List<String[]> list = query.list();
  for (int i = 0; i < list.size(); i++) {
    Object obj = list.get(0);
    if (obj!=null) {
      id = obj.toString();
    }
  }
  return id;
}

 

以上是关于Gatling - 脚本中常用到的方法的主要内容,如果未能解决你的问题,请参考以下文章

rampUser 方法卡在 gatling 3.3 中

工作中常用到的一些方法

如何在Gatling脚本中传递soap XML

php中常用到的魔术方法

JAVA中常用到的Math类中的方法有哪些?

Gatling性能测试工具入门