需要 Postman curl url中的等效gatling scala代码

s6fujrry  于 2021-07-14  发布在  Java
关注(0)|答案(0)|浏览(291)

需要 Postman curl url中的等效gatling scala代码
请您为下面的身份验证请求逻辑地编写一个等价的gatling scala代码,首先我需要使用gatling scala获得一个身份验证请求及其响应,下面是postman中的身份验证curl请求,它工作正常,我的意思是给出201响应,但是我在gatling中使用git-url-github得到了400个响应
从curl请求生成:

curl 'https://api.platform.com/auth/oauth/token' -H 'Accept: application/json, text/plain, */*' -H 'Referer: https://api-origin.cloud/dev/reservations-web/signin' -H 'Origin: https://api.origin.cloud' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36' -H 'Authorization: Basic aWtyd3VnaDM4NzFnaHc4cmduN3E4M2c2c3I=' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'grant_type=password&username=abc.xyc1%40abc.com&password=Password1%21' --compressed

下面是我尝试生成但得到400响应的scala等效代码

package simulations

import baseConfig.BaseSimulation
import io.gatling.core.Predef._
import io.gatling.core.session
import io.gatling.http.Predef._

import scala.concurrent.duration.DurationInt
import scala.util.Random

class ogrebattledriverPostAccessToken extends BaseSimulation {

   exec(
      http("HTTP Request auth")
        .post("https://api.platform.com/auth/oauth/token")
        .header("Content-Type","application/x-www-form-urlencoded")
        .formParam("grant_type","password")
        .formParam("username", "TableTopEng%40xxxs.com")
        .formParam("password", "actual password")
        .check(status is 200)
        .check(jsonPath("$.access_token").saveAs("access_token"))
        .check(jsonPath("$.token_type").saveAs("token_type"))
    )

  //val PostData=jsonFile("input-json.json").circular
  def name() = Random.nextInt(Integer.MAX_VALUE).toString

   //val headers_10 = Map("Content-Type" -> """application/json""","Authorization","${token_type} + ${access_token}" )

  def getSpecificOgreID()={
    repeat(140000){
      exec(flushHttpCache)

        feed(usersDataSource)
        .exec(http("PostRequestPerformanceTestingOgreBattleDriver")
          .post("https://api.tabletop-stage.tiamat-origin.cloud/dev/ogre-battledriver/Organizations")
         // .headers(headers_10)
          .header("Authorization", "${token_type} + ${access_token}")
          .body(StringBody(session =>
            s"""
               |{
               |  "name": "${name()}",
               |  "latitude": 66.256538,
               |  "longitude": -95.934502,
               |  "phoneNumber": "555-555-5555",
               |  "emailAddress": "perftest1@perftest1.com",
               |  "website": "https://perftest1",
               |  "streetLine1": "123 perftest1.",
               |  "streetLine2": "Ste 400",
               |  "city": "Omaha",
               |  "state": "NE",
               |  "zipCode": "98002"
               |}
          """.stripMargin)).asJSON

          .check(status.in(200,201))//checkforaspecificstatus
          .check(jsonPath(path="$.name").saveAs(key="name")))//checkforaspecificstatus
        .exec{session=>println(session);session}//parameterfortheorgIdgoeshere
        .pause(1)

    }
  }

  // add a scenario
  val scn = scenario("Battle Driver Get Orgs ")

    .forever() { // add in the forever() method - users now loop forever
      exec(getSpecificOgreID())
    }

在intellij编辑器中出错

20:22:56.563 [ERROR] i.g.h.a.s.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'access_token' is defined

有人能从上面的 Postman curl请求中写一个逻辑gatling scala代码吗??

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题