wttech/bobcat

How to add the following chromeOptions?

moitrso opened this issue · 2 comments

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
};

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

Thanks, the above mentioned code snippet worked for me!