0

I have two specs in BDD. There's samples how to manage a single selenium driver using a central static variable (example) in a "DriverFactory".

That's nice as long as you don't run more than one spec in parallel. If you do, then the different specs will get confused because they are using the same driver.

This is really because the spec needs to be mapped to the driver, Java code is not tied to a spec. In other words, any spec can call any Java code. So you can't instantiate a class that's fully mapped to a spec and have a local driver.

Anyone came across this?

One idea to overcome is to have a "DriverFactory" with array of drivers, mapped to specs. But this means that Java step using the driver would need to know the context of the spec in which it's being executed..

1 Answers1

0

I assume you are using Gauge because of the [getgauge] tag and the example referred to.

Gauge's parallel execution executes each spec in parallel. The recommended way is to not have specs share states/resources, and if you have to, make them thread safe.

This example uses a static Driverfactory.getDriver method, to initialize a new Driver whenever requested. In this setup, every spec will get a new instance of the driver. Does this help your case?

Srikanth Venugopalan
  • 9,011
  • 3
  • 36
  • 76
  • Thanks Srikanth. What I see is that Driver allocates a new driver on suite initiation. That driver is a static variable. So now, if you run specs in parallel, they will share a driver. So let's say one spec goes and does testing on Google.com, and another on Amazon.com. What will happen is that sharing the driver, the specs will get confused a fail. Because they are using the same driver... – Amir Rozenberg Apr 09 '18 at 13:41