I am trying to run a Selenium Webdriver MultiThreaded Test using WebDriverManager ( Reference was taken -> https://www.programcreek.com/java-api-examples/?api=io.github.bonigarcia.wdm.WebDriverManager
@Test
public void test() throws InterruptedException {
private int NUM_DATA =2;
private int NUM_LATCH=2;
private int POOL_SIZE=2;
CountDownLatch latch = new CountDownLatch(NUM_LATCH);
ExecutorService executorService = newFixedThreadPool(POOL_SIZE);
for (int i = 0; i < NUM_DATA; i++) {
executorService.submit(() -> {
try {
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver.get(
"https://bonigarcia.github.io/selenium-jupiter/");
String title = driver.getTitle();
System.out.println(title);
driver.quit();
} finally {
latch.countDown();
}
});
}
latch.await();
executorService.shutdown(); }
In my case
- NUM_LATCH = POOL_SIZE = NUM_DATA == > WORKING FINE
- NUM_LATCH = 2 = POOL_SIZE , NUM_DATA =6 = > NOT ALL INSTANCES ARE CLOSED FOR TRHEAD
- NUM_LATCH = NUM_DATA = 6 , POOL_SIZE = 2 => WORKING FINE
BY working fine means here means , all the browsers instances are opened and execution happens and then all browser are closed.
My problem statement is if i have 1000 set of NUM_DATA and POOL_SIZE is 10 at a time . do i have to set NUM_LATCH always equal to NUM_DATA ?
As per the article in "https://www.baeldung.com/java-countdown-latch"
"If we were doing some parallel processing, we could instantiate the CountDownLatch with the same value for the counter as a number of threads we want to work across"
but here we are not setting NUM_LATCH = POOL_SIZE but rather number of num_Latch= Num_Data_Set . Is this correct way to use CountDownLatch ??