driver object in selenium

Solutions on MaxInterview for driver object in selenium by the best coders in the world

showing results for - "driver object in selenium"
Tommaso
11 May 2016
1Driver class:
2-Driver class is public, has a private
3constructor and private WebDriver object
4which named driver, so that no object
5can be created outside the class. 
6It is also an example for "singleton design pattern". 
7-Webdriver driver is private and static.
8Static so it is only a single copy and 
9shared among the class. It is private 
10so that it is encapsulated. It has a
11public getter method which returns driver object 
12(browser) based on the condition (if driver==null) 
13as a result of launching a browser based on the 
14info retrieved from .properties file using 
15Configuration class get method. No setter method,
16so it can not be modified anyway
17
18Driver class is singleton
19To create a singleton class, we need to
201.Declare constructor of class as private 
21so nobody can instantiate a WebDriver
22object of this class from out of it.
232.Declare a private static WebDriver object.
24Static is needed to make it available globally.
253.Declare a public static method(getter)
26with return type as object of class which 
27should check if class is already instantiated once.