Failed to build request request_2: No attribute named 'personId 1 (100.0%) is defined

import scala.concurrent.duration._

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

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL(“http://115.249.227.253:85”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”"..png"""), WhiteList())
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,
/*;q=0.8")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0”)

val headers_0 = Map(“Upgrade-Insecure-Requests” → “1”)

val headers_1 = Map(
“Accept” → “/”,
“Pragma” → “no-cache”)

val uri1 = “http://detectportal.firefox.com/success.txt
val uri2 = “http://xxxxxxxxxx:xx/SampleApplication”

val scn = scenario(“RecordedSimulation”)
// AppLaunch
.exec(http(“request_0”)
.get("/SampleApplication/login")
.headers(headers_0)
.resources(http(“request_1”)
.get(uri1 + “”)
.headers(headers_1)))
.pause(16)
// Login
.exec(http(“request_2”)
.post("/SampleApplication/login")
.headers(headers_0)
.check(regex(""“value=”(.*?)"""").saveAs(“personId”) )
.formParam(“ssoId”, “test1”)
.formParam(“password”, “test1”)
.formParam("_csrf","${personId}"))
.pause(48)

I am trying to capture the csrf token for my app I got No attribute named 'personId is defined Kindly help on this

I did not see the response body but I guess there are two problems.

  1. .check(regex(""“value=”(.*?)"""").saveAs(“personId”) ) should take place at the request request_0
  2. regex(""“value=”(.*?)""""). is a vague expression regular. It does not get what you want.

Hi Falvio,

Thanks for your quick reply.I am new to gatling tool. Below is response data. how to construct the regex for data

I think these regex must solve, choose one
regex(css(“input[name=_csrf]”, “value”).saveAs(“personId”))
or
.regex("<input type=“hidden” name="_csrf" value="(.*?)"").saveAs(“personId”))

Hi Flavio

I tried second option. But i got script compilation error.Kindly help on this what i missing

import scala.concurrent.duration._

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

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL(“http://115.249.227.253:85”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”"..png"""), WhiteList())
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,
/*;q=0.8")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0”)

val headers_0 = Map(“Upgrade-Insecure-Requests” → “1”)

val headers_1 = Map(
“Accept” → “/”,
“Pragma” → “no-cache”)

val uri1 = “http://detectportal.firefox.com/success.txt
val uri2 = “http://115.249.227.253:85/SampleApplication

val scn = scenario(“RecordedSimulation”)
// AppLaunch
.exec(http(“request_0”)
.get("/SampleApplication/login")
.headers(headers_0)
.check(
regex(""""<input type=“hidden” name="_csrf" value="(.*?)"""").find.saveAs(“personId”))
.resources(http(“request_1”)
.get(uri1 + “”)
.headers(headers_1)))
.pause(16)
// Login
.exec(http(“request_2”)
.post("/SampleApplication/login")
.headers(headers_0)
.check(
regex(css(“input[name=_csrf]”, “value”).saveAs(“CorpersonId”)
.formParam(“ssoId”, “test1”)
.formParam(“password”, “test1”)
.formParam("_csrf","${personId}"))
.pause(48)
// ClkTransfer
.exec(http(“request_3”)
.get("/SampleApplication/newTrans")
.headers(headers_0))
.pause(26)
// Submit
.exec(http(“request_4”)
.post("/SampleApplication/newTrans")
.headers(headers_0)
.formParam(“status”, “Success”)
.formParam(“date”, “17/08/2018”)
.formParam(“accNo”, “98765423101”)
.formParam(“toAccNo”, “548702010010012”)
.formParam(“type”, “Transfer”)
.formParam(“Amount”, “3”)
.formParam(“remarks”, “TestData”)
.formParam("_csrf", “${CorpersonId}”))
.pause(9)
// logout
.exec(http(“request_5”)
.get("/SampleApplication/logout")
.headers(headers_0))

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

Look at the this line regex(css(“input[name=_csrf]”, “value”).saveAs(“CorpersonId”)
There are two missing things.:wink:

Hi Flavio,

Can you please elaborate on the missing things. Because i am still getting the same compilation error.

import scala.concurrent.duration._

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

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL(“http://115.249.227.253:85”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”"..png"""), WhiteList())
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,
/*;q=0.8")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0”)

val headers_0 = Map(“Upgrade-Insecure-Requests” → “1”)

val headers_1 = Map(
“Accept” → “/”,
“Pragma” → “no-cache”)

val uri1 = “http://detectportal.firefox.com/success.txt
val uri2 = “http://115.249.227.253:85/SampleApplication

val scn = scenario(“RecordedSimulation”)
// AppLaunch
.exec(http(“request_0”)
.get("/SampleApplication/login")
.headers(headers_0)
.check(regex(css(“input[name=_csrf]”, “value”).saveAs(“personId”))
.resources(http(“request_1”)
.get(uri1 + “”)
.headers(headers_1)))
.pause(16)
// Login
.exec(http(“request_2”)
.post("/SampleApplication/login")
.headers(headers_0)
.check(
regex("<input type=“hidden” name="_csrf" value="(.*?)"").saveAs(“CpersonId”))
.formParam(“ssoId”, “test1”)
.formParam(“password”, “test1”)
.formParam("_csrf","${personId}"))
.pause(48)
// ClkTransfer
.exec(http(“request_3”)
.get("/SampleApplication/newTrans")
.headers(headers_0))
.pause(26)
// Submit
.exec(http(“request_4”)
.post("/SampleApplication/newTrans")
.headers(headers_0)
.formParam(“status”, “Success”)
.formParam(“date”, “17/08/2018”)
.formParam(“accNo”, “98765423101”)
.formParam(“toAccNo”, “548702010010012”)
.formParam(“type”, “Transfer”)
.formParam(“Amount”, “3”)
.formParam(“remarks”, “TestData”)
.formParam("_csrf", “${CpersonId}”))
.pause(9)
// logout
.exec(http(“request_5”)
.get("/SampleApplication/logout")
.headers(headers_0))

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

This message is due to a missing parenthesis here

.check(regex(css(“input[name=_csrf]”, “value”).saveAs(“personId”))

Hi Flavio
Unable to capture the csfr token. Kindly help on this
I got found nothing during execution

to extract csfr use
regex("<input type=“hidden” name="_csrf" value="(.*?)"").saveAs(“personId”))

Hi Flavio,

Thanks for your great support.

I think I capture the login csrf token(green highlighted) .but I try the same thing for submit csrf token(yellow highlighted) I got not found the error. Please help on this.What i am missing
i had enclosed the script, simulation log and error screenshot

import scala.concurrent.duration._

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

class RecordedSimulation extends Simulation {

val httpProtocol = http
.baseURL(“http://115.249.227.253:85”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”"..png"""), WhiteList())
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,
/*;q=0.8")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0”)

val headers_0 = Map(“Upgrade-Insecure-Requests” → “1”,

“Accept” → “/”,
“Pragma” → “no-cache”,
“X-Content-Type-Options” → “nosniff”,
“X-Frame-Options” → “DENY”,
“Upgrade-Insecure-Requests” → “1”,
“Content-Type” → “application/x-www-form-urlencoded”,
“Accept-Encoding” → “gzip,deflate”,
“Accept-Language” → “en-US,en;q=0.9”,
“X-XSS-Protection” → “1”)

val headers_1 = Map(
“Accept” → “/”,
“Pragma” → “no-cache”,
“X-Content-Type-Options” → “nosniff”,
“X-Frame-Options” → “DENY”,
“Upgrade-Insecure-Requests” → “1”,
“Content-Type” → “application/x-www-form-urlencoded”,
“Accept-Encoding” → “gzip,deflate”,
“Accept-Language” → “en-US,en;q=0.9”,
“X-XSS-Protection” → “1”)

val uri1 = “http://detectportal.firefox.com/success.txt
val uri2 = “http://115.249.227.253:85/SampleApplication

val scn = scenario(“RecordedSimulation”)
// AppLaunch
.exec(http(“request_0”)
.get("/SampleApplication/login")
.headers(headers_0)
.check(
regex("""""").find .saveAs(“personId”)) //
.resources(http(“request_1”)
.get(uri2 + “”)
.headers(headers_1)))
.pause(16)
// Login
.exec(http(“request_2”)
.post("/SampleApplication/login")
.headers(headers_0)
.formParam(“ssoId”, “test1”)
.formParam(“password”, “test1”)
.formParam("_csrf", “${personId}”))
.pause(48)
// ClkTransfer
.exec(http(“request_3”)
.get("/SampleApplication/newTrans")
.check(
regex("""""").find .saveAs(“CpersonId”))
.headers(headers_0))
.pause(26)
// Submit
.exec(http(“request_4”)
.post("/SampleApplication/newTrans")
.headers(headers_0)
.formParam(“status”, “Success”)
.formParam(“date”, “18/08/2018”)
.formParam(“accNo”, “98765423101”)
.formParam(“toAccNo”, “548702010010012”)
.formParam(“type”, “Transfer”)
.formParam(“Amount”, “3”)
.formParam(“remarks”, “TestData”)
.formParam("_csrf", “${CpersonId}”))
.pause(9)
// logout
.exec(http(“request_5”)
.get("/SampleApplication/logout")
.headers(headers_0))

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

simulation.log (1.05 KB)

Hi Flavio,

Once again Thanks for your great support. Finally, I capture all the csrf token using below function and submitted the transaction successfully.

.check(css(“input[name=_csrf]”, “value”).saveAs(“CpersonId”))

Regards
Krishna