I have a project I'm working on with several test methods. I need WebDriver to be available globally after I instantiate it and with ChromeOptions.
I'm using a @Before annotation to do a lot of setup and I thought I could pass ChromeOptions into the webdriver which is instantiated globally. 'options.addArguments()' isn't available globally and it isn't recognizing my options. Example below:
public class classThatDoesStuff_Test {
private static WebDriver driver = new ChromeDriver();
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\TestUser\\Desktop\\SeleniumWorkspace\\ABC\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("--window-size-1400,800");
options.addArguments("--disable-gpu");
}
public void doStuff() {
driver.get("http://foo.bar.com");
}
Running this does not start the browser headless.
I tried creating a method with ChromeOptions and passing it to the driver. That didn't work
private static ChromeOptions options() {
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
options.addArguments("window-size=1400,800");
options.addArguments("disable-gpu");
return options;
Then passing it to my instantiation. But that didn't work - as you probably guessed :)