I'm using Cucumber, TestNG, WebDriver, WebDriverFactory and PicoContainer. Scenarios run in parallel. I'm getting strange intermittent failures - every now and then (perhaps one in 20 runs) in one of the scenarios the webdriver doesn't control the browser. Strange thing is the steps pass (e.g. entering email address and password and then clicking the Login button), but on the browser nothing is happening.

I have a WebDriverFactory:

public class WebDriverFactory implements Startable {

    private volatile WebDriver driver;

    public WebDriverFactory() { try { Thread.sleep(5000); } catch(Exception e) {} }
    public void setDriver() { driver = new ChromeDriver().instantiate(); }

    public synchronized WebDriver getDriver() {
        if (driver == null) {
        return driver;

    public void start() {}
    public void stop() {}

My StepDefs are injected with an instance of the WebDriverFactory, and whenever getDriver() is called, it will create an ChromeDriver instance (if one doesn't already exist):

public class AuthLoginStepDefs extends BaseStepDefs {
    private final AuthLoginPage authLoginPage;
    public AuthLoginStepDefs(WebDriverFactory webDriverFactory) {
        this.authLoginPage = new AuthLoginPage(webDriverFactory.getDriver());

    @Given("I enter {string} in the email address textbox")
    public void enterEmail(String emailAddress) {

And my "pages" files are straight forward:

public class AuthLoginPage extends BasePage {

    private final By email = By.name("email-input");
    private final By password = By.name("password-input");
    private final By loginButton = By.name("login-button");

    public AuthLoginPage(WebDriver driver) {

    public void enterEmailAddress(String email) {

    public void enterPassword(String password) {

When this intermittent issue occurs, I can see the login page load, but the username (email address) is not entered on the browser, even though the step passes. Same with the password - the step passes, but nothing is entered in the Password input. The step that clicks on the Login button passes, but the browser remains on the untouched Login page. The test then fails because it thinks the browser is on the user's signed-in-homepage, but it's not.

Some things I've tried so far:

  • Use a different version of Java (i.e. JDK 20 instead of 17).
  • Changes the structure of the project to use ThreadLocal<WebDriver> instead of Pico.
  • Placing a 5 second wait before instantiating ChromeDriver.
  • Using the volatile keyword in case it's something to do with low-level caching.
  • Trying Chromium instead of google-chrome-stable.
  • (many other things I just can't remember right now)

It's driving me crazy - I'm still getting these intermittent failures where in one thread it looks like steps are passing, but webdriver doesn't seem to be controlling the Chrome browser. This only happens when I run tests in parallel, I've never seen it happen when I run tests individually.

If anyone could shed some light on this issue, it would really be appreciated.

1 Answer 1


After outputting console logs from the test, I have found the issue, and it has nothing to do with the test/test framework. The issue occurs because this particular login page sends a POST request after the user clicks the login button, but this POST request sometimes fail, causing the flow to return to the login page (making it look like nothing happened).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.