-1

While trying to execute below script getting ERROR as i.g.h.a.HttpRequestAction - 'httpRequest-1' failed to execute: No attribute named 'testReqJson' is defined.

Need to set a session variable & pass it in body.

object PostTest extends BaseHttpRequest {

  override val basicRequestExecutor = exec(_.set("testReqJson", createTestJsonPayload(100)))
    .exec(hitApiAndVerify())

  override protected def hitApi(): HttpRequestBuilder = {
    http("testJson")
      .post(testJson.APP_URL + "/test/json")
      .body(StringBody("${testReqJson}")).asJson
      .header("Content-Type", "application/json")
  }
}


  protected def hitApiAndVerify(): HttpRequestBuilder = super.hitApiAndVerify {
    if (ConfigLoader.getPropertyOrElse("localProxy", "false").equalsIgnoreCase("true")) {
      hitApi().proxy(Proxy("localhost", 8888))
    } else {
      hitApi()
    }
  }
user16666530
  • 1
  • 1
  • 1

2 Answers2

0

Impossible to tell for sure because you're only providing pieces of your actual code, so it's impossible to compile and run. I suspect you're messing up with the overrides.

For example, you should probably declare basicRequestExecutor as def everywhere instead of val.

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
-1

Tried to run using session variable & it worked.

override val basicRequestExecutor = exec(session =>   
  session.set("testReqJson", createTestJsonPayload(100)))
      .exec(hitApiAndVerify())

override protected def hitApi(): HttpRequestBuilder = {
  http("testJson")
      .post(testJson.APP_URL + "/test/json")
      .body(StringBody("${testReqJson}"))
      .header("Content-Type", "application/json")   }
jwvh
  • 50,871
  • 7
  • 38
  • 64
user16666530
  • 1
  • 1
  • 1
  • `exec(_.set("testReqJson", createTestJsonPayload(100)))` and `exec(session => session.set("testReqJson", createTestJsonPayload(100)))` do the exact same thing. You must have changed something else to make it work. – Stéphane LANDELLE Aug 17 '21 at 21:18