testbench icon indicating copy to clipboard operation
testbench copied to clipboard

Allow specifying `--headless` Chrome option for ParallelTest

Open OlliTietavainenVaadin opened this issue 7 years ago • 6 comments

Currently, the only way to set the --headless Chrome option seems to be like thus:

protected WebDriver createDriver() {
  ChromeOptions options = new ChromeOptions();
  options.addArguments("--headless");
  options.addArguments("--disable-gpu");
  return TestBench.createDriver(new ChromeDriver(options));  	
} 

but for ParallelTest, you shouldn't create your own driver. Typically, this kind of configuration could be done with DesiredCapabilities, but even that is deprecated. If there's a way to run headless Chrome tests with ParallelTest, it should be documented; if not, this feature should be implemented somehow.

OlliTietavainenVaadin avatar Jan 14 '19 10:01 OlliTietavainenVaadin

This should probably be fixed here: https://github.com/vaadin/testbench/blob/master/vaadin-testbench-core/src/main/java/com/vaadin/testbench/parallel/setup/LocalDriver.java#L75

OlliTietavainenVaadin avatar Jan 14 '19 10:01 OlliTietavainenVaadin

This can be done with having a method annotated @BrowserConfiguration Check out Defining the Browsers to Run Tests On section: https://vaadin.com/docs/v12/testbench/testbench-running-test-on-multiple-browsers.html

alexberazouski avatar Jan 14 '19 11:01 alexberazouski

Setting ChromeOptions with --headless argument as capability of DesiredCapabilities like this:

setDesiredCapabilities(DesiredCapabilities chrome) {
        ChromeOptions options= new ChromeOptions();
        options.addArguments("--headless");
        options.addArguments("--disable-gpu");
        chrome.setCapability(ChromeOptions.CAPABILITY, options);

does not work.

OlliTietavainenVaadin avatar Jan 14 '19 12:01 OlliTietavainenVaadin

This can be done with having a method annotated @BrowserConfiguration Check out Defining the Browsers to Run Tests On section: https://vaadin.com/docs/v12/testbench/testbench-running-test-on-multiple-browsers.html

Hi Alex,

maybe you can provide a working sample of how to set the headless mode for chrome. I did not manage this.

Thanks, Erik

voodoohoo avatar Jan 14 '19 12:01 voodoohoo

Quick research showed that ParallelTest ignores the DesiredCapabilities indeed.

Thanks for reporting this!

And the workaround for this could be:

    @Override
    public void setup() throws Exception {
        if (BrowserUtil.isChrome(getDesiredCapabilities()) && (getRunLocallyBrowser() != null)) {
            ChromeOptions options= new ChromeOptions();
            options.setHeadless(true);
            setDriver(new ChromeDriver(options));
        } else {
            super.setup();
        }
  }

Unfortunately, it's needed to re-implement each needed conditional branch of super.setup()

super class in this case is ParallelTest

alexberazouski avatar Jan 14 '19 13:01 alexberazouski

I was unable to find an easy way to fix this. Browser options do not merge correctly, for instance merging a ChromeOptions object with another ChromeOptions or Capabilities will not merge the command line arguments. Using the deprecated Capabilities API is an option, but in LocalDriver we still need to add manually the extra command line argument. In this PR https://github.com/vaadin/testbench/pull/1130 I made the changes to allow at least running headless chrome by manually casting and merging the options in the DesiredCapabilities.

I believe the way to go would be to remove the usage of DesiredCapabilities. To replace that, we could have factories for each type of Driver and and allow the user to change the <Browse>Options object before the driver is created.

tulioag avatar Jan 28 '19 15:01 tulioag