【问题标题】:Why am i getting this "HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named"为什么我会收到此“HttpRequestAction - 'httpRequest-1' 无法执行:没有命名属性”
【发布时间】:2020-10-11 23:35:11
【问题描述】:

我正在尝试创建我的第一个 Gatling 性能测试并收到此错误,我无法找出原因。

错误

HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named 'anumber' is defined

这是我的代码

package sweetpackage

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

class OneClassToRuleThemAll extends Simulation {

  object SubmitGet {

    val feeder = csv("numbers.csv")

    val GetAPI = exec(
      http("/v0/playa/palyaid")
        .get("/services/playas/v0/playa/${anumber}")
    )
  }
  
  val httpProtocol = http
    .baseUrl("https://playassite")
    .header("Sec-Fetch-Site","same-origin")
    .header("Sec-Fetch-Mode","cors") 
    .header("Sec-Fetch-Dest","empty")
    .acceptHeader("application/json")
    .acceptLanguageHeader("en-US,en;q=0.9")
    .acceptEncodingHeader("gzip, deflate, br")
    .userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36 Edg/86.0.622.38")

  val users = scenario("KingPins").exec(SubmitGet.GetAPI)

  setUp(
    users.inject(atOnceUsers(1))
  ).protocols(httpProtocol)
}

我的测试数据文件是一个名为 numbers.csv 的 csv 文件,采用 UTF-8 编码。我在 MS Excel 中创建了文件

anumber
500100

【问题讨论】:

  • 所以我将 GetAPI 更改为这个并且它有效,但我不明白为什么`def GetAPI() = { repeat(1) { feed(csvFeeder) .exec(http("Get play" ) .get("services/playa/v0/playa/${anumber}") .check(status.is(200))) .pause(1) } }`

标签: scala csv gatling


【解决方案1】:

在您提供的示例中,您没有在场景中添加 feed 操作以实际从馈送器中读取。你只是在你的评论中这样做了。所以注入的数据注入了你的虚拟用户。

【讨论】:

    【解决方案2】:

    这似乎有效。虽然有一些错别字

    package sweetpackage
    
    import io.gatling.core.Predef._
    import io.gatling.http.Predef._
    import scala.concurrent.duration._
    
    class OneClassToRuleThemAll extends Simulation {
    
      object SubmitGet {
    
        val feeder = csv("numbers.csv")
    
        def GetAPI() = { repeat(1) 
          { feed(csvFeeder) 
            .exec(http("Get plays") 
            .get("services/playa/v0/playa/${anumber}") 
            .check(status.is(200))) .pause(1) 
          }
        }
      }
      
      val httpProtocol = http
        .baseUrl("https://playassite")
        .header("Sec-Fetch-Site","same-origin")
        .header("Sec-Fetch-Mode","cors") 
        .header("Sec-Fetch-Dest","empty")
        .acceptHeader("application/json")
        .acceptLanguageHeader("en-US,en;q=0.9")
        .acceptEncodingHeader("gzip, deflate, br")
        .userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36 Edg/86.0.622.38")
    
      val users = scenario("KingPins").exec(SubmitGet.GetAPI)
    
      setUp(
        users.inject(atOnceUsers(1))
      ).protocols(httpProtocol)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-05
      • 1970-01-01
      • 2020-01-08
      • 2021-01-10
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 2022-08-18
      相关资源
      最近更新 更多