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;}


Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source