BrowserSession is the object passed into your executeFlow/browserSessionFunction callbacks (see
Flow Action and Browser Session Function). It wraps the
current Gatling Session and adds a few browser-action-specific extras: resolving Gatling EL expressions,
overriding the reported timing of the action, and setting its OK/KO status by hand.
Gatling sessions are immutable, and BrowserSession follows the same model: none of its methods mutate
it in place. To persist any session change you make, call updateBrowserSession(...) and return the
BrowserSession it gives back — the same rule as returning a new Session from a plain Gatling exec.
browserAction("test").executeFlow((page, browserSession) => {
val updated = browserSession.getGatlingSession.set("your_args", "value")
browserSession.updateBrowserSession(updated) // <- must return this, not browserSession itself
})
| Method | Returns | Description |
|---|---|---|
getGatlingSession |
Session |
The current Gatling session, read-only. |
getGatlingSession(name: String) |
SessionAttribute |
Shorthand for reading a single attribute, equivalent to getGatlingSession(name) on a plain Gatling session(name). |
updateBrowserSession(session: Session) |
BrowserSession |
A new BrowserSession wrapping session. This is the only way to persist a session change — always return the result. |
| Method | Returns | Description |
|---|---|---|
resolveSessionValue(value: String) |
Any |
Resolves a Gatling EL expression, e.g. "#{url}", against the current session. |
resolveSessionValue(value: Expression[Any]) |
Any |
Resolves a value by running an arbitrary Session => T function against the current session (Gatling’s usual implicit conversion to Expression applies). |
val exists = browserSession.resolveSessionValue("#{url.exists()}")
val updated = browserSession.resolveSessionValue(session => s"${session("url").as[String]}-suffix")
By default, an action’s reported start/end time is when the plugin actually started/finished it. Use these
if you want to report different timestamps instead — for example, timings read from
page.evaluate("performance.timing") (see advanced Flow Action examples).
| Method | Description |
|---|---|
setActionStartTime() |
Sets the reported start time to now. |
setActionStartTime(timestamp: Long) |
Sets the reported start time to an explicit epoch-millis timestamp. |
getActionStartTime |
Returns the previously set start time, or 0 if never set. |
setActionEndTime() |
Sets the reported end time to now. |
setActionEndTime(timestamp: Long) |
Sets the reported end time to an explicit epoch-millis timestamp. |
getActionEndTime |
Returns the previously set end time, or 0 if never set. |
| Method | Description |
|---|---|
setStatusOK() |
Marks this action as successful. |
setStatusKO() |
Marks this action as failed, with no custom error message. |
setStatusKO(errorMessage: String) |
Marks this action as failed with a custom error message. |
getStatus |
Returns the Status (OK/KO) that will be reported for this action. |
getErrorMessage |
Returns Option[String] — the error message set via setStatusKO(String), if any. |
browserSession.setStatusKO("custom failure reason")
val message: Option[String] = browserSession.getErrorMessage
Setting a KO status here does not stop your callback or throw — code after setStatusKO(...) still
runs, and it doesn’t retroactively mark browserSession.getGatlingSession.isFailed as true either; the
plugin only applies that to the Gatling session after your callback returns. If you want to skip the rest
of the current callback once you’ve called setStatusKO(...), use an ordinary early return.
getGatlingSession.isFailed is still useful, but across actions rather than within one: check it at the
top of a later executeFlow in the same scenario to skip risky work once an earlier action already
failed — see the guard pattern in advanced Flow Action examples.