Skip to content
CodeKruPro

A static WebDriver in a parallel run

QuizMediumJava onlyAsked in: Accenture, Capgemini, Infosys, SaaS Labs, Swiggy, TCS

The base class has protected static WebDriver driver;, set in @BeforeMethod. With parallel="methods", tests fail at random. Why?

  • All threads share one static field, so one test's @BeforeMethod replaces the driver another test is using
  • Static fields cannot hold a WebDriver
  • TestNG does not allow static fields in parallel mode
  • Chrome cannot run two windows at once

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in