SeleniumHQ / seleniumhq.github.io

Official Selenium website and documentation
https://selenium.dev
Apache License 2.0
1.02k stars 1.22k forks source link

[🐛 Bug]: Getting java.lang.IllegalArgumentException: WebDriver instance must support BiDi protocol #1797

Open fabytta opened 4 days ago

fabytta commented 4 days ago

What happened?

I'm running my tests on the AWS Device Farm grid using RemotWebDriver, the browsers there are up to date, but when I use the bedi features I get java.lang.IllegalArgumentException: WebDriver instance must support BiDi protocol my code :

public class AWSTests {
    WebDriver driver;

 @Before
   public void setUp() throws MalformedURLException {
//I have a code that build the aws url
 URL testGridUrl = new URL(aws_grid_url);
 // You can now pass this URL into RemoteWebDriver.
        FirefoxOptions options = new FirefoxOptions();
        options.setPlatformName("windows");
        Proxy proxy = new Proxy();
        proxy.setHttpProxy("my-proxy:port");
        proxy.setSslProxy("my-proxy:port");
        options.setCapability("proxy", proxy);
        driver = new RemoteWebDriver(testGridUrl,options );
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
        driver.manage().window().maximize();
    }

    @Test
    public void canContinueWithAuthCredentials() {
        try (Network network = new Network(driver)) {
            network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
            network.onAuthRequired(
                    responseDetails ->
                            network.continueWithAuth(
                                    responseDetails.getRequest().getRequestId(),
                                    new UsernameAndPassword("admin", "admin")));
            driver.get("https://the-internet.herokuapp.com/basic_auth");
            String successMessage = "Congratulations! You must have the proper credentials.";
            WebElement elementMessage = driver.findElement(By.tagName("p"));
            Assert.assertEquals(successMessage, elementMessage.getText());
        }
    }
    @After
    public void tearDown() {
        // make sure to close your WebDriver:
        driver.quit();
    }
}

The error I'm getting : java.lang.IllegalArgumentException: WebDriver instance must support BiDi protocol

What can I do to make the webdriver instance support bidi, is there a specifci update or request to make to AWS device farm team ?

What browsers and operating systems are you seeing the problem on?

issue reproducible with Firefox and Chrome on Windows

github-actions[bot] commented 4 days ago

@fabytta, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

harsha509 commented 4 days ago

hi @fabytta ,

can you set the following capability to enable BiDi protocol and try

options.setCapability("webSocketUrl", true);

Thanks, Sri Harsha

pujagani commented 4 days ago

And also augment the driver. Let me share an example. https://github.com/SeleniumHQ/selenium/blob/trunk/java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java#L99

fabytta commented 3 days ago

Hello @harsha509, Thanks for the suggestion, but it still didn't work with the proposed option :(

fabytta commented 3 days ago

Hello @pujagani, when I tried augmenting without options.setCapability("webSocketUrl", true); --> I got the same error : java.lang.IllegalArgumentException: WebDriver instance must support BiDi protocol when I tried augmenting with options.setCapability("webSocketUrl", true); --> I got the new error : org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error

pujagani commented 3 days ago

"when I tried augmenting with options.setCapability("webSocketUrl", true); --> I got the new error : org.openqa.selenium.remote.http.ConnectionFailedException: JdkWebSocket initial request execution error" - Can you help share a script/setup that can help reproduce this? I have not faced this error earlier, and I can help triage it further if I can reproduce it. Also, please ensure the Grid version on the device farm supports BiDi and allows websocket connection.

fabytta commented 3 days ago

Hey @pujagani, I understand that you need full script t reproduce, I tried to clean it a little to be able to share

public class AWSTests {
    WebDriver driver;

    @Before
   public void setUp() throws MalformedURLException {
        String myProjectARN = "arnProjectFromAWSDeviceFarm";
        DeviceFarmClient client  = DeviceFarmClient.builder().region(Region.US_WEST_2).build();
        //I use AWS sdk here to build the url and I pass keys as environement variables of my run
        CreateTestGridUrlRequest request = CreateTestGridUrlRequest.builder()
                .expiresInSeconds(300)
                .projectArn(myProjectARN)
                .build();
        CreateTestGridUrlResponse response = client.createTestGridUrl(request);
        URL testGridUrl = new URL(response.url());
        // You can now pass this URL into RemoteWebDriver.
        ChromeOptions options = new ChromeOptions();
        options.setPlatformName("windows");
        Proxy proxy = new Proxy();
        proxy.setHttpProxy("myproxy:80");
        proxy.setSslProxy("myProxy:80");
        options.setCapability("proxy", proxy);
        options.addArguments(
                "--proxy-server=my_proxy:80");
        options.setCapability("webSocketUrl", true);
        DesiredCapabilities desired_capabilities = new DesiredCapabilities();
        desired_capabilities.setCapability(ChromeOptions.CAPABILITY,options);
        driver = new RemoteWebDriver(testGridUrl,desired_capabilities );
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(30));
        driver.manage().window().maximize();
        driver = new Augmenter().augment(driver);
    }

    @Test
   public void canContinueWithAuthCredentials() {
        try (Network network = new Network(driver)) {
            network.addIntercept(new AddInterceptParameters(InterceptPhase.AUTH_REQUIRED));
            network.onAuthRequired(
                    responseDetails ->
                            network.continueWithAuth(
                                    responseDetails.getRequest().getRequestId(),
                                    new UsernameAndPassword("admin", "admin")));
            driver.get("https://the-internet.herokuapp.com/basic_auth");
            String successMessage = "Congratulations! You must have the proper credentials.";
            WebElement elementMessage = driver.findElement(By.tagName("p"));
            Assert.assertEquals(successMessage, elementMessage.getText());
        }
    }

    @After
    public void tearDown() {
        // make sure to close your WebDriver:
        driver.quit();
    }

}

To be able to reproduce you may need an access to the device farm : https://docs.aws.amazon.com/devicefarm/latest/testgrid/getting-started-migration.html

fabytta commented 3 days ago

@pujagani , regarding your comment : "Also, please ensure the Grid version on the device farm supports BiDi and allows websocket connection." is there and documentation on how to make the grid support BIDI and allows websocket so that I share it with the support of the aws grid ?

pujagani commented 3 days ago

Which version of Grid are you using? Nothing special needs to be done to enable it. Actually, in such cases where proxy is used, I have often seen that proxy does not allow websocket connections. So there is nothing Selenium specific, but it is more on how the proxy or even firewall is configured.