标签: scala-gatling

加特林:如何在控制台中显示完整的HTTP响应正文或将其打印到文件中

我是加特林的新手。我找不到有关如何查看完整的HTTP响应正文的简单完整示例。

这是我简单的例子

class CreateNotecard extends Simulation 
{  
  val baseURL = "https://portal.apps.stg.bluescape.com" 
  val httpConf = http 
    .baseURL(baseURL) 
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36") 

  val scn = scenario("Create a notecard")  
    .exec(http("Get authenticity token") 
    .get("/users/sign_in") 
    .check(bodyString.saveAs("BODY"))) 

  setUp( 
    scn.inject(atOnceUsers(1))  
  ).protocols(httpConf)  
}
Run Code Online (Sandbox Code Playgroud)

如何将bodyString打印到文件中或在控制台上?

提前致谢

gatling scala-gatling

8
推荐指数
2
解决办法
1万
查看次数

使用Gatling和Content-Type进行负载性能测试

我正在使用gatling在一个全新的API上进行负载性能测试.这看起来相当容易并且有很好的文档记录,但是我遇到的问题很简单,就像将一个请求的内容类型设置为Header上的'application/vnd.api + json'一样简单.在进行GET操作时一切正常,但在启动POST测试时,我得到了一个

HTTP response:
status=
415 Unsupported Media Type
headers= 
cache-control: [no-cache]
Content-Type: [application/vnd.api+json; charset=utf-8]
Date: [Fri, 08 Sep 2017 12:57:10 GMT]
Server: [nginx]
Vary: [Origin]
x-content-type-options: [nosniff]
x-frame-options: [SAMEORIGIN]
X-Request-Id: [ff993645-8e01-4689-82a8-2f0920e4f2a9]
x-runtime: [0.040662]
x-xss-protection: [1; mode=block]
Content-Length: [218]
Connection: [keep-alive]

body=
{"errors":[{"title":"Unsupported media type","detail":"All requests that create or update must use the 'application/vnd.api+json' Content-Type. This request specified 'application/json'.","code":"415","status":"415"}]}
Run Code Online (Sandbox Code Playgroud)

这是我用于http请求的scala代码:

object PostTokenGcm {
 val token = exec {
  http("TestAPI POST /tokens")
    .post("/tokens")
    .headers(Map("Authorization" -> testApiToken,
       "Content-Type" -> "application/vnd.api+json",
        "Accept" …
Run Code Online (Sandbox Code Playgroud)

scala gatling scala-gatling

7
推荐指数
1
解决办法
803
查看次数

如何从 Gatling 的响应体中获取值?

我尝试了在 Gatling.io 上找到的不同方法,但我的问题仍然存在。当我发送 GET 请求时,有一个 API 以 JSON 格式返回一个简短的响应。

获取请求:

http://localhost:some_port/api/endpoint1?parameter1=1234¶meter2=5678

回复:

{“交易”:“6d638b9b-f131-41b1-bd07-0d1c6a1d4bcc”,“参考”:“some_text”}

我需要从响应中获取事务值并在另一个请求中使用它。

下一个请求:

http://localhost:some_port/api/endpoint2?transaction= $transactionValue¶meter=8

到目前为止,我已经尝试使用 regex、jsonPath 和 Int 或 String 值,但结果是 0 或 None。

到目前为止,这是我的场景代码:

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class class1 extends Simulation {

    val httpProtocol = http
        .baseURL("http://localhost:port")
        .inferHtmlResources()
        .acceptHeader("text/html,application/json")
        .acceptEncodingHeader("gzip, deflate")
        .acceptLanguageHeader("en-US,en;q=0.9,hr;q=0.8,sr;q=0.7,bs;q=0.6")
        .userAgentHeader("Mozilla/5.0 (X11; Fedora; Linux x86_64)")

    val headers = Map(
        "Content-Type" -> "application/json")

    val uri1 = "http://localhost:port/api/endpoint1"
    val uri2 = "http://localhost:port/api/endpoint2"

    val scn = scenario("getEndpoint1")
        .exec(http("endpoint1")
            .get("/api/endpoint1?parameter1=1234&parameter2=5678")
            .headers(headers)
      .check(jsonPath("$.transaction").findAll.saveAs("transaction")))
    .pause(3)
    .exec(session => {
      val …
Run Code Online (Sandbox Code Playgroud)

performance-testing gatling scala-gatling

7
推荐指数
0
解决办法
1万
查看次数

Gatling checkIf 语法

遗留应用程序具有以下工作 Gatling 测试

private val getUserByTuid = scenario("GetActiveUserInfoWrapper")
    .feed(users.toArray.circular)
    .exec(
      http("GET /v1/foo/{id}")
        .get("/v1/foo/${id}")
        .header("Content-Type", "application/json")
        .header("User-Agent", "gatling")
        .check(status is 200)
        .check(jsonPath("$..ID") exists)
    )
Run Code Online (Sandbox Code Playgroud)

我需要更改它,以便状态为 200,在这种情况下它检查 jsonnode ID 是否存在(就像上面一样),或者状态为 401,在这种情况下它检查 jsonnode Description 是否存在。任何其他状态都应导致失败。

这是我到目前为止所做的,但它似乎没有按预期工作,因为 Gatling 考虑了所有响应失败,即使是 ID 为 200 和描述为 401 的响应失败。

private val getUserByTuid = scenario("GetActiveUserInfoWrapper")
    .feed(users.toArray.circular)
    .exec(
      http("GET /v1/foo/{id}")
        .get("/v1/foo/${id}")
        .header("Content-Type", "application/json")
        .header("User-Agent", "gatling")
        .check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == 200)(jsonPath("$..ID") exists))
        .check(checkIf((response: Response, session: Session) => response.status.get.getStatusCode == 401)(jsonPath("$..Description") exists))
    )
Run Code Online (Sandbox Code Playgroud)

我查看了文档并在网上搜索,但无法找出实现我想要的正确方法,因此在这里询问。

scala gatling scala-gatling

7
推荐指数
1
解决办法
1870
查看次数

Gatling 错误:无法找到或加载主类引擎

我安装了最新的 IntelliJ idea, latest maven 3.6.3Java 1.8,设置 JAVA_HOME / JRE_HOME 环境变量。然后使用mvn archetype:generate -Dfilter=gatling. 总之,我按照此处的说明进行操作。我也为 IntelliJ idea 安装了 Scala 插件。当我尝试通过右键单击 Engine 类来运行 Gatling 引擎时,出现以下错误。有人能告诉我这里发生了什么吗?我在网上尝试了所有建议,但到目前为止没有运气。谢谢

"C:\Program Files (x86)\Java\jdk1.8.0_221\bin\java.exe".....

Error: Could not find or load main class Engine

Process finished with exit code 1 
Run Code Online (Sandbox Code Playgroud)

这是我的 POM 文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.gatling</groupId>
  <artifactId>pert-tests</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <encoding>UTF-8</encoding>

    <gatling.version>3.2.1</gatling.version>
    <gatling-maven-plugin.version>3.0.3</gatling-maven-plugin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.gatling.highcharts</groupId>
      <artifactId>gatling-charts-highcharts</artifactId>
      <version>${gatling.version}</version>
    </dependency>
    <dependency>
      <groupId>io.gatling</groupId>
      <artifactId>gatling-app</artifactId>
      <version>${gatling.version}</version> …
Run Code Online (Sandbox Code Playgroud)

scala intellij-idea performance-testing gatling scala-gatling

6
推荐指数
2
解决办法
3403
查看次数

在三重 qouted 字符串中使用 gatling 会话变量

如何在 gatling 的 StringBody 中使用会话变量?

我已经定义了我的exec喜欢,

val migrateAsset = exec(_.set("assetId", AssetIdGenerator.generateRandomAssetId()))
      .exec(http("Migrate Asset")
      .post(s"$url/asset/metadata")
      .header("Content-Type", "application/json")
      .header("Authorization", s"Bearer ${authToken}")
      .body(StringBody(
          s"""
            |{
            |    "objectType" : "DocumentType",
            |    "fileName" : "main.xml",
            |    "locations" : [
            |        {
            |            "region" : "eu-west-1",
            |            "url" : "https://s3-eu-west-1.amazonaws.com/${bucketName}/${assetId}"
            |        },
            |        {
            |            "region" : "us-east-1",
            |            "url" : s"https://s3.amazonaws.com/${bucketName}/${assetId}"
            |        }
            |    ],
            |    "format" : "MAIN",
            |    "mimeType" : "text/plain"
            |}
          """.stripMargin
      ))
      .check(status.is(200)))
Run Code Online (Sandbox Code Playgroud)

在正文中,我希望assetId欧盟西部和美国东部地区都通过同样的检查。由于 assetId 是随机生成的,因此我将其存储在会话变量中以确保我对两个位置使用相同的 assetId。 …

scala performance-testing gatling scala-gatling gatling-plugin

5
推荐指数
1
解决办法
1621
查看次数

加特林的替代品

我最近遇到了问题,因为我的依赖项已更新为使用netty 4.1,而Gatling已有一段时间没有更新,并且仍然只能在Netty 4.0上运行。

有人知道加特林可以创建类似的模拟和方案,以便在我的Maven生命周期中自动运行性能测试吗?

java scala performance-testing gatling scala-gatling

5
推荐指数
2
解决办法
3424
查看次数

如何使用加特林执行条件检查

我有一个这样的场景。

 private val feeder = Array(200, 404).map(e => Map("code" -> e)).random.circular

 private val search = scenario("search")
                          .feed(feeder)
                          .exec(http("search")
                          .get("/search/")
                          .headers(headers)
                          .check( if "${code}".equals(200) jsonPath("$.body").exists else jsonPath("$.exception").exists )
Run Code Online (Sandbox Code Playgroud)

有没有办法可以实现这种条件检查。截至目前,观察到的行为是,“${code}”.equals(200)将始终返回 false。

scala gatling scala-gatling

5
推荐指数
1
解决办法
4031
查看次数

Gatling:随时保持固定数量的用户/请求

我们如何在某个场景中同时保持固定数量的活动并发用户/请求。

我有一个独特的测试问题,我需要在给定的时间段(如 10 分钟或 30 分钟或 1 小时)内对具有固定请求数量的服务进行性能测试。

我不是在寻找每秒的事情,我正在寻找的是我们从 N 个请求开始,随着 N 个请求中的任何一个请求完成,我们再添加一个,以便在任何给定时刻我们只有 N 个并发请求。

我尝试过的事情是,rampUsers(100) over 10 seconds但我看到有时在一个给定的实例中有超过 50 个用户。

constantUsersPerSec(20) during (1 minute) 还花了一段时间的请求数 t0 50+。

atOnceUsers(20) 似乎相关,但我没有看到任何方法可以让它在给定的秒数内运行并在之前的请求完成时添加更多请求。

提前感谢社区,期待您的指导。

gatling scala-gatling

5
推荐指数
1
解决办法
5133
查看次数

gatling-3.0.0:javax.net.ssl.SSLHandshakeException:收到致命警报:bad_certificate

我在 SBT 中使用 Gatling 3.0.0 作为插件我正在配置浏览器,如配置标题下的https://gatling.io/docs/current/http/recorder/#recorder之后当我启动记录器时使用gatling:startRecorder在 sbt 并尝试点击我的网站https://www.example.com/ Firefox 显示

Did Not Connect: Potential Security Issue
Firefox detected a potential security threat and did not continue to www.mydomain.com because this website requires a secure connection.

www.mydomain.com has a security policy called HTTP Strict Transport Security (HSTS), which means that Firefox can only connect to it securely. You can’t add an exception to visit this site 
Run Code Online (Sandbox Code Playgroud)

这是异常日志

ioEventLoopGroup-2-1] DEBUG io.netty.handler.ssl.util.InsecureTrustManagerFactory - Accepting a server certificate: CN=www.mydomain.com …
Run Code Online (Sandbox Code Playgroud)

gatling scala-gatling gatling-plugin

5
推荐指数
1
解决办法
1408
查看次数