I am using SpringBootTest 3.0.5, Java 17, Selenium 4.8, Junit-Jupiter 5.9.2 and trying to run tests in parallel.
My Config class is:
@Component
public class WebDriverLibrary {
@Bean
@ConditionalOnProperty(name = "default.browser", havingValue = "chrome")
public WebDriver getDriver() {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
return new ChromeDriver(options);
} }
My TestCase is:
@SpringBootTest
@SpringJUnitConfig(WebDriverLibrary.class)
public class AppTestCase {
@Autowired
public WebDriver driver;
@Test
public void testYoutube() {
driver.get("https://www.youtube.com");
}
@Test
public void testGoogle() {
driver.get("https://www.google.com");
}
}
The issue here is, same @Autowired instance of WebDriver is shared by two tests parallel. So only one browser session is launched and YouTube.com and google.com urls are loaded sequentially. Can anyone please let me know how to ensure a separate @Autowired WebDriver instead is created a each test (basically each thread) and ensure two separate webdriver driver sessions are launched in parallel ?