Skip to content
Ben Weese edited this page Jun 12, 2019 · 2 revisions

I like to make a setup class for setting up the driver, the website, and anything else that might be something that is needed.

Setup Chrome Driver

Here I use a Setter and Getter. This way I can setup the driver with the setter and get the driver with the getter.

Setter

private WebDriver driver;
private String url;

void setDriver() {

   System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/src/main/resources/chromedriver");

   ChromeOptions options = new ChromeOptions();
   options.addArguments("--no-sandbox");
   options.addArguments("--headless");
   options.addArguments("--disable-gpu");
   options.addArguments("--window-size=1200x1100");
   options.addArguments("--disable-extensions");

   driver = new ChromeDriver(options);

  }

So I download and place the Chrome Driver from google into the /src/main/resources/ directory. This is so I can set the property of the webdriver using the current user directory.

I then define the options I want with crome and set the driver.

Getter

WebDriver getDriver() {
        return driver;
    }

The getter is a simple return the driver that I set in the setter.

You can also use a getter and setter for the base URL or you can just make a setup object and use setup.url

Clone this wiki locally