Hello
ist there a best practice or example how to apply common functions to all requests.
In the documentation I have seen the hint gatling uses a real programming language thus you can write your own functions.
However when I tried to do this I could not manage it.
i want the two apply these two functions to every request
.formParam(“javax.faces.ClientWindow”, “${dswid}”)
.formParam(“dspwid”, “${dswid}”)
Since I had my project opened in IntellJ I tried to user refactoring to extract a method.
Thus I marked the two function and tried to call refactor> extract methos.
However this did not work due to some error message.
Is there a sample that shows how to define such a function or is there a better way to do it?
My complete Program looks like thisprogram looked like this
package pass.shops
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class XCor extends Simulation {
val httpProtocol = http
.baseUrl(“https://xxx.example.comcom/Shop”)
.acceptHeader("/")
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.9,de-DE;q=0.8,de;q=0.7”)
.doNotTrackHeader(“1”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36”)
val headers_0 = Map(
“accept” → “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”,
“cache-control” → “no-cache”,
“pragma” → “no-cache”,
“sec-fetch-dest” → “document”,
“sec-fetch-mode” → “navigate”,
“sec-fetch-site” → “none”,
“sec-fetch-user” → “?1”,
“upgrade-insecure-requests” → “1”)
val headers_31 = Map(
“accept” → “text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9”,
“cache-control” → “no-cache”,
“origin” → “https://solution-test.pass-consulting.com”,
“pragma” → “no-cache”,
“sec-fetch-dest” → “document”,
“sec-fetch-mode” → “navigate”,
“sec-fetch-site” → “same-origin”,
“sec-fetch-user” → “?1”,
“upgrade-insecure-requests” → “1”)
val scn = scenario(“xxx”)
.exec(http(“landing”)
.get("/")
.headers(headers_0)
.check(currentLocationRegex(".*dswid=(-?[0-9]+)").saveAs(“dswid”))
)
.pause(9)
.exec(http(“form”)
.post("/faces/modules/PassShop/pages/DlgStartShop.xhtml?${dswid}")
.headers(headers_31)
.formParam(“DlgStartShop”, “DlgStartShop”)
.formParam(“DlgStartShop:observedDataChanged”, “false”)
.formParam(“invokedMenuName”, “MenuTopRight”)
.formParam(“invokedMenuPoint”, “mpLogin”)
.formParam(“DlgStartShop:menuControlMenuTopRight:menuPointCommand”, “”)
.formParam(“javax.faces.ClientWindow”, “${dswid}”)
.formParam(“dspwid”, “${dswid}”)
)
.pause(5)
.exec(http(“doLogin”)
.post("/faces/modules/PassShop/pages/DlgLogin.xhtml?dswid=${dswid}")
.headers(headers_31)
.formParam(“DlgLogin:txtUsername”, “user”)
.formParam(“DlgLogin:txtPassword”, “password”)
.formParam(“DlgLogin”, “DlgLogin”)
.formParam(“DlgLogin:observedDataChanged”, “false”)
.formParam(“DlgLogin:btnOk”, “DlgLogin:btnOk”)
.formParam(“javax.faces.ClientWindow”, “${dswid}”)
.formParam(“dspwid”, “${dswid}”)
)
.pause(5)
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}