In this article, we would discuss about the scope of multiple driver instances and their usability perspective. We would understand the entire concept with the appropriate examples and code samples.

By the term, “Multiple WebDriver Instances”, we mean to say that we create more than one Webdriver instances and launch those using different or same browser specific drivers.

Why do we need multiple WebDriver instances?

We may require such configuration when we have master slave configuration.

–          Master – Slave Setup – In such setups, if we want to execute the test suite on slave setup but a few of the operations are backed up only on Master. Thus, when the user is required to communicate with two different applications in order to accomplish one whole operation, we are tempt to use multiple WebDriver configuration.

1Thus, when multiple web based applications are involved to accomplish a particular test scenario, it is advisable to create multiple WebDriver instances each dedicated to a particular application.

Now let us understand the concept with the help of the code snippet.

Before motioning towards the code, let us take a moment to introduce you with the two applications we have chosen to illustrate the concept.

–          Gmail.com

–          Google.com

I hope the application names are self explanatory and need no introduction.

Code Overview

We have created the following two classes:

–          SwitchDriver: SwitchDriver is a test class that contains the actual test scenario

–          Generic: Generic is a java class that we have used to instantiate the driver objects, launching the browser, opening applications on the instances or any other setting related stuff. We can moreover use the class to create common methods applicable to application one as well as application two and thus, just by passing the driver instance, the system would realize which application to invoke.

SwitchDriver Class

Generic Class

Conclusion:

I hope the tutorial made a clear impression on when to create multiple WebDriver instances. We also showed the working example in order to explain the concept. There can be various alterations that can be incorporated so as to customize it based on our requirements.

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *