Search code examples
javaserenity-bddserenity-spring

Serenity BDD Remote Chrome capabilities using serenity.conf


I am trying to execute a spring boot integration test using a remote selenium chrome driver.

In my serenity.conf I have the following:

webdriver {
  driver = "remote"
  remote {
      url="http://localhost:4444/wd/hub"
      driver=chrome
  }
}

When I try to execute my IT it fails to connect to the local server I get ERR_CONN_REFUSED, probably due to a missing "remote-allow-origins=*" chrome capability.

Here's my test:

    @Managed(driver = "remote")
    private WebDriver webDriver;

    @LocalServerPort
    private int serverPort;
    ....
    
    @Test
    void pageLoads() {
        webDriver.get("http://" + "localhost" + ":" + serverPort);
        ....
    }

Question is - Is it possible to add the desired capability (and any other capabilities) in the serenity.conf?

P.S. I am new to BDD testing and serenity.

tried to load a simple web page e.g. https://google.com and it worked. Also tried adding in serenity.conf (nested within the remote object)

 capabilities {
      "goog:chromeOptions" {
        args = [
        "start-maximized",
        "headless",
        "remote-allow-origins=*",
        "test-type",
        "no-sandbox",
        "ignore-certificate-errors",
        "disable-popup-blocking",
        "version",
        "disable-infobars",
        "disable-extensions",
        "disable-gpu"
        ]
      }

similar to how one would add these when the driver is embedded, but when tried to load the localhost it was again unsuccessful. Note that when using an embedded chrome it works with the above capabilities.


Solution

  • You have almost done it correctly, you need to use "goog:chromeOptions" capability to define any of the ChromeDriver options in below w3c format in your serenity.conf file -

    webdriver {
      capabilities {
        browserName = "Chrome"
        browserVersion = "103.0"
        platformName = "Windows 11"
        acceptInsecureCerts = true
         "goog:chromeOptions" {
              args = ["test-type", "ignore-certificate-errors", "headless",
            "incognito", "disable-infobars", "disable-gpu", "disable-default-apps", "disable-popup-blocking"]
        }
        timeouts {
          script = 30000
          pageLoad = 300000
          implicit = 2000
        }
      }
    }