I'm using Gatling.io to test a website. I have a scenario with multiple virtual users.
val users = scenario("Users").exec(Session.browse)
val admins = scenario("Admins").exec(Session.create)
I want the admin user to create a "session" on the website I'm testing, save the session name from the result returned by the website, and have the other users to visit the session previously created by getting the session name from the user admin.
How can I share the session name between users ?
I think the default Gatling answer for this is to create the session and persist it in a file of some kind and in a new simulation read that value and have the users pick it up. 'Fanning out' is not really a scenario Gatling supports in a single simulation.
That said, you can fudge it if you really want - particularly if you just need one quick execution by the Admin user and you're prepared to define your scenarios within your simulation file.
class simulation extends Simulation {
private var mySession = "NOT_SET"
val users = scenario("Users").exec(Session.browse)
val admins = scenario("Admins").exec(Session.create)
}
as part of the 'Admins' scenario save the value of your session into the 'mySession' var
as part of the users' scenario set a session variable from the 'mySession' var
then run your simulation something like...
setUp(
admins.inject(
atOnceUsers(1)
),
users.inject(
nothingFor(1 minutes), //enough time for admins to complete
atOnceUsers(10) //or however many you need
)
it works ok for quick and dirty data seeding, but you're really cutting against the grain of how Gatling is designed.
来源:https://stackoverflow.com/questions/47857825/gatling-io-share-data-between-virtual-users