Skip to content

Selenium does not execute in Java ExecutorService #3281

@LusciousPear

Description

@LusciousPear

Meta -

OS: Ubuntu 16.04

Selenium Version: 3.0.1

Browser: Chrome

Browser Version: 55.0.2883.75 (64-bit)

Expected Behavior -

Multiple Chrome windows should open.

Actual Behavior -

No Chrome windows open.

Steps to reproduce -

I'm unable to get Selenium+ChromeDriver working inside an ExecutorService. This is so I can run multiple processes. It works just fine if I run it as a JUnit test inside a single thread.

There are no errors -- it runs fine until the WebDriver driver = new ChromeDriver(), and then just quits. No exceptions thrown.

To reproduce, just execute doPool().


    @Test
    public void doPool(){

        ExecutorService executor = Executors.newFixedThreadPool(10);

            executor.submit(() -> {

                testGoogleSearch();
            });

    }

    @Test
    public void testGoogleSearch() {
        //System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

        String threadName = Thread.currentThread().getName();
        System.out.println("Hello " + threadName);

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com/xhtml");
        try {
            Thread.sleep(5000);  // Let the user actually see something!

            WebElement searchBox = driver.findElement(By.name("q"));
            searchBox.sendKeys("ChromeDriver");
            searchBox.submit();
            Thread.sleep(5000);  // Let the user actually see something!

            screenshot(driver);
        }
        catch (InterruptedException e) {
            e.printStackTrace();
        }

    }




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