I get this error that my attribute is not defined and I can't figure out why.
I have it it first saved in my first request as CSRF variable.
Later on I try to access it while doing post request to fill out the form.
This is my main simulation class:
package simulations.stage
import io.ecx.steps.{Config, Login}
import io.gatling.core.Predef._
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import scala.concurrent.duration._
class RampUsersLoadSimulations extends Simulation{
val httpConf: HttpProtocolBuilder = http.baseUrl(Config.baseUrl)
.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.userAgentHeader("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36")
.inferHtmlResources()
.acceptEncodingHeader("gzip, deflate, br")
.proxy(Proxy("localhost", 8866))
before {
println(s"Running for: ${Config.baseUrl}")
}
val login: ScenarioBuilder = scenario("Scenario: Login to the storefront")
.exec(
Login.login(Config.accounts),
Login.navigateToMyAccountPage())
setUp(login.inject(atOnceUsers(1))).protocols(httpConf)
}
This is my steps object where I try to save it and then use it in the post request:
package io.ecx.steps
import io.gatling.core.Predef._
import io.gatling.http.Predef._
object Login {
def login(accountsPath: String) = {
val accounts = csv(accountsPath).random
exec(http("Load Login Page")
.get("/login")
.check(regex("<title>My Title</title>").exists)
.check(css("[name=CSRFToken]", "value").saveAs("CSRF"))
.check(status.is(200)))
.pause(2)
// .exec{session => println(session); session}
feed(accounts)
.exec(http("Log in with credentials to the storefront")
.post("/j_spring_security_check")
.formParam("username", "${username}")
.formParam("password", "${password}")
.formParam("rememberMe", "${rememberMe}")
.formParam("CSRFToken", "${CSRF}")
.check(css("#loginForm").notExists)
.check(status.in(200)))
.pause(5)
}
def navigateToMyAccountPage() = {
exec(http("Open My account Page")
.get("accountSummary")
.check(css(".page-AccountSummaryPage").exists)
.check(status.in(200)))
.pause(2)
}
}
In the HTML that is loaded when login page loads we have:
<input type="hidden" name="CSRFToken" value="6ac89c39-ee25-4cdc-9553-cc8a7824f43b" />
This is the logs:
Simulation simulations.stage.RampUsersLoadSimulations started...
Session(Scenario: Login to the storefront,1,Map(gatling.http.ssl.sslContexts -> io.gatling.http.util.SslContexts@6e62fe0c, gatling.http.cache.dns -> io.gatling.http.resolver.ShufflingNameResolver@56fe67f3, gatling.http.cache.baseUrl -> https://my-site.com),KO,List(),io.gatling.core.protocol.ProtocolComponentsRegistry$$Lambda$434/1485485458@7dcefc4,io.netty.channel.nio.NioEventLoop@70f02c32)
23:29:59.611 [ERROR] i.g.h.a.HttpRequestAction - 'httpRequest-4' failed to execute: No attribute named 'CSRF' is defined
================================================================================
2021-03-03 23:30:00 5s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=1 )
> Load Login Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 1 (50.00%)
on
> Log in with credentials to the storefront: Failed to build req 1 (50.00%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-03-03 23:30:05 10s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=1 )
> Load Login Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 1 (50.00%)
on
> Log in with credentials to the storefront: Failed to build req 1 (50.00%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[--------------------------------------------------------------------------] 0%
waiting: 0 / active: 1 / done: 0
================================================================================
================================================================================
2021-03-03 23:30:08 13s elapsed
---- Requests ------------------------------------------------------------------
> Global (OK=0 KO=2 )
> Load Login Page (OK=0 KO=1 )
> Open My account Page (OK=0 KO=1 )
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 2 (66.67%)
on
> Log in with credentials to the storefront: Failed to build req 1 (33.33%)
uest: No attribute named 'CSRF' is defined
---- Scenario: Login to the storefront -----------------------------------------
[##########################################################################]100%
waiting: 0 / active: 0 / done: 1
================================================================================
Simulation simulations.stage.RampUsersLoadSimulations completed in 13 seconds
Parsing log file(s)...
Parsing log file(s) done
Generating reports...
================================================================================
---- Global Information --------------------------------------------------------
> request count 2 (OK=0 KO=2 )
> min response time 2015 (OK=- KO=2015 )
> max response time 2019 (OK=- KO=2019 )
> mean response time 2017 (OK=- KO=2017 )
> std deviation 2 (OK=- KO=2 )
> response time 50th percentile 2017 (OK=- KO=2017 )
> response time 75th percentile 2018 (OK=- KO=2018 )
> response time 95th percentile 2019 (OK=- KO=2019 )
> response time 99th percentile 2019 (OK=- KO=2019 )
> mean requests/sec 0.143 (OK=- KO=0.143 )
---- Response Time Distribution ------------------------------------------------
> t < 800 ms 0 ( 0%)
> 800 ms < t < 1200 ms 0 ( 0%)
> t > 1200 ms 0 ( 0%)
> failed 2 (100%)
---- Errors --------------------------------------------------------------------
> j.n.ConnectException: Connection refused: no further informati 2 (66.67%)
on
> Log in with credentials to the storefront: Failed to build req 1 (33.33%)
uest: No attribute named 'CSRF' is defined
================================================================================
Could it be that I have this behavior because the input field is marked as hidden?
Or there is something I can't see.
Please help.
Thanks!
You have an error in your code: you're missing a dot before feed(accounts)
. Because of this, it's not attached to the head and only the tail is considered.