vaadin / testbench

Vaadin TestBench is a tool for automated user interface testing of Vaadin applications.
https://vaadin.com/testbench
Other
20 stars 22 forks source link

Allow specifying `--headless` Chrome option for ParallelTest #1125

Open OlliTietavainenVaadin opened 5 years ago

OlliTietavainenVaadin commented 5 years ago

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 commented 5 years ago

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

alexberazouski commented 5 years ago

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

OlliTietavainenVaadin commented 5 years ago

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.

voodoohoo commented 5 years ago

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

alexberazouski commented 5 years ago

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

tulioag commented 5 years ago

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.