簡體   English   中英

如何在http請求中獲取Gatling的隨機URL?

[英]How can I get a Random URL on http request for Gatling?

我想在http請求中獲取隨機URL以獲取Gatling

我的場景定義如下:

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import scala.util.Random

class testSimulation extends Simulation {

  val httpConf = http.baseURL("OURURL")


  val scn = scenario("View HomePages")
                .exec(
                        http("Home page")
                                .get("/" + new Random().nextInt())
                              .resources(
                                      http("genericons.css").get("/wp-content/themes/twentyfifteen/genericons/generi$
                                      http("style.css").get("/wp-content/themes/twentyfifteen/style.css?ver=4.2.3"),
                                      http("jquery.js").get("/wp-includes/js/jquery/jquery.js?ver=1.11.2"),
                                      http("jquery-migrate.min.js").get("/wp-includes/js/jquery/jquery-migrate.min.j$
                                      http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
                                      http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
                                      http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
                                      http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$
                                      http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$
                                      http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$
                              )
                )

  setUp(
      scn.inject
      (
      rampUsersPerSec(1) to(300) during(60 seconds),
      constantUsersPerSec(300) during(600 seconds)
      )
      .protocols(httpConf)
      )
}

我只生成一個隨機數而不是每個請求一個。 你知道怎么解決嗎? 謝謝 !

你正在傳遞一個值,所以new Random().nextInt只在構建Simulation時被調用一次。

你必須傳遞一個表達式 ,即一個函數。 只有這樣才會每次都進行評估。

.get(session => "/" + new Random().nextInt())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM