Driver Usage - so far

How are we using it thus far?

  • We first created a driver instance in the ExmapleSteps class.
  • Then at the point where we separated step classes, we moved the driver creation code to DriverFactory.
  • Next we made the driver instance static so that all the step classes could use the same instance.
  • Also, we have been passing the same driver instance to all the page classes.

Lets understand who all needs this driver.

  • StartingSteps class needs it, to launch the application using driver.get("applicationUrl") method call.
  • All the pages need it, to do page level action on the browser using this driver, like click, sendkeys etc.

Problems with the current approach.

Consider the case when we want to run all the tests in a feature file at once. Ideally we would want to start a new browser instance as part of every test, and then close the browser after every test.

But is that possible, given the current code which only instantiates a static driver instance just once? NO.

Let's assume we try to kill the browser after first test. This driver instance is an static instance. So although the browser will get closed, the instance being static will not be completely dead.

Now when the next test tries to use the driver again to launch a new browser instance, the execution will bomb. Reason being the fact that the static instance is not completely dead and this test will try to use the same instance.

The following articles will talk about how to abstract the driver and instantiate it in the right way so that the usage of the driver object is clean and clear.

results matching ""

    No results matching ""