wttech / bobcat

Bobcat is an automated testing framework for functional testing of web applications.
https://cognifide.github.io/bobcat/
Apache License 2.0
90 stars 40 forks source link

How to add the following chromeOptions? #369

Closed moitrso closed 5 years ago

moitrso commented 5 years ago

I tried using this, but it didn't work. What is the correct format to pass chrome options? webdriver.chrome.ChromeOptions={\ 'args': ['--disable-extensions', '--start-maximized'],\ 'useAutomationExtension': false\ };

mkrzyzanowski commented 5 years ago

Hi @moitrso!

Handling capabilities is a bit all over the place, especially via properties - we have some legacy code handling translation of those properties into Capabilities, hence it's not possible to set it that way.

Since recently the WebDriver's API exposes Capabilities classes specialised towards specific browsers, I'd suggest to use them at the moment. Fortunately, Bobcat has a dedicated extension point for modifying Capabilities that you can plug into. You will need a CapabilitiesModifier implementation like this one:

public class ChromeOpt implements CapabilitiesModifier {
  @Override
  public boolean shouldModify() {
    return true;
  }

  @Override
  public Capabilities modify(Capabilities capabilities) {
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("start-maximized");
    chromeOptions.addArguments("disable-extensions");
    chromeOptions.setExperimentalOption("useAutomationExtension", "false");
    return chromeOptions;
  }
}

which you need to register in your Guice module:

//...
  @Override
  protected void configure() {
  //..
    Multibinder<CapabilitiesModifier> capabilitiesModifiers = Multibinder
        .newSetBinder(binder(), CapabilitiesModifier.class);
    capabilitiesModifiers.addBinding().to(ChromeOpt.class);
  //...
  }

If you are using the runmode feature, simply create a dedicated module:

public class ChromeOptModule extends AbstractModule {
  @Override
  protected void configure() {
    Multibinder<CapabilitiesModifier> capabilitiesModifiers = Multibinder
        .newSetBinder(binder(), CapabilitiesModifier.class);
    capabilitiesModifiers.addBinding().to(ChromeOpt.class);
  }
}

and add it to your resources/runmodes/default.yaml:

- com.cognifide.qa.bb.modules.CoreModule
- <yourpackage>.ChromeOptModule
moitrso commented 5 years ago

Thanks, the above mentioned code snippet worked for me!