Skip to content

[🐛 Bug]: Set DriverSession TimeOut - Script throws timeout if the node is not available with in 3 minute #13884

Closed as not planned
@gitissuepost

Description

@gitissuepost

What happened?

I am using a grid on GKE where the node gets spinn up on-demand. Desired pod count for the deployment has been set as 0. As the script connects with teh grid, it spins up a POD to cater that request. However, the script fails as it doesn't get a node assgned with in 3 minutes.

I followed details mentioned in Issue-9314 to use WebDriverBuilder to set a higher timeout. However, the script leads to IllegalArgumentException: Base URI has already been set. Cannot also set driver service.

How can we reproduce the issue?

import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.logging.LogType;
import org.openqa.selenium.logging.LoggingPreferences;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.ClientConfig;
import org.openqa.selenium.remote.service.DriverService;

import java.io.FileOutputStream;
import java.net.URL;
import java.time.Duration;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

public class TestDriverBuilder {
    public static void main(String[] args) {
        try {
            System.out.println(new Date());

            ChromeOptions options = new ChromeOptions();
            options.setPageLoadStrategy(PageLoadStrategy.EAGER);
            options.setAcceptInsecureCerts(true);
            options.addArguments("--disable-extensions", "--dns-prefetch-disable", "--disable-logging", "--remote-allow-origins=*");
            options.addArguments("--disable-dev-shm-usage", "--disable-infobars");
            options.addArguments("--unexpectedAlertBehaviour=dismiss", "--silent", "--blink-settings=imagesEnabled=false", "--inprivate");
            options.addArguments("--disable-blink-features", "--disable-blink-features=AutomationControlled", "--disable-gpu");
            options.addArguments("--no-sandbox", "--window-size=1920,1200", "--ignore-certificate-errors", "--disable-application-cache");

            Map<String, Object> chromePrefs = new HashMap<String, Object>();
            chromePrefs.put("download_restrictions", 3);
            options.setExperimentalOption("prefs", chromePrefs);

            LoggingPreferences logPrefs = new LoggingPreferences();
            logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
            options.setCapability("goog:loggingPrefs", logPrefs);

            DriverService.Builder serviceBuilder = new ChromeDriverService.Builder();
            ChromeDriverService chromeDriverService = (ChromeDriverService) serviceBuilder.build();
            chromeDriverService.sendOutputTo(new FileOutputStream(System.getProperty("user.dir") + "/target/driverlog"));

            WebDriver driver = (RemoteWebDriver) RemoteWebDriver
                    .builder()
                    .config(
                            ClientConfig.defaultConfig()
                                    .connectionTimeout(Duration.ofMinutes(10))
                                    .readTimeout(Duration.ofMinutes(10))
                                    .baseUrl(new URL("<GRID_HUB_URL>"))
                    )
//                    .withDriverService(chromeDriverService)
                    .addAlternative(options)
                    .build();
            driver.get("http://www.google.com");
            System.out.println(new Date());
            Thread.sleep(3000);
            driver.quit();
            System.out.println(new Date());
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(new Date());
        }
    }
}

Relevant log output

Mon Apr 29 13:52:22 BST 2024
java.lang.IllegalArgumentException: Base URI has already been set. Cannot also set driver service.
	at org.openqa.selenium.remote.RemoteWebDriverBuilder.withDriverService(RemoteWebDriverBuilder.java:276)
	at TestDriverBuilder.main(TestDriverBuilder.java:53)
Mon Apr 29 13:52:23 BST 2024

Update added to Comment Below

Operating System

Windows10

Selenium version

Java 4.19.1

What are the browser(s) and version(s) where you see this issue?

Chrome - Latest Docker Image

What are the browser driver(s) and version(s) where you see this issue?

Grid - Docker - Chrome Node (GKE) - Latest

Are you using Selenium Grid?

4.20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions