Answers for "driver utility"

0

driver utility

We have too many repeated lines to just to initialize the driver
Being able to pass the same driver instance 
when calling methods from other classes 
get amazon page - Webdriver driver1.get / 
find search bar Webdriver driver2.search / 
send keys Webdriver driver3.sendKey
1- Private constructor: ensures that no one else 
can create an instance of the WebDriver
-We will allow reach to this driver only through our getter method.
2- We create a logic to ensure that the same driver instance 
is passed every single time:
    if(driver==null) {
//this statement will ensure that the new instance will be created 
only if the driver object is empty
String browser = ConfigurationReader.getProperty("browser");
//this line will read what browser we want to run on dynamically 
from configuration.properties
                    switch (browser){
                case "chrome":
                    WebDriverManager.chromedriver().setup();
                    driver = new ChromeDriver();
                    break;}
Posted by: Guest on May-28-2021

Browse Popular Code Answers by Language