package com.yorel.incredible.core;

import io.github.bonigarcia.wdm.ChromeDriverManager;
import io.github.bonigarcia.wdm.EdgeDriverManager;
import io.github.bonigarcia.wdm.FirefoxDriverManager;
import io.github.bonigarcia.wdm.InternetExplorerDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class WebDriverFactory {

    private static WebDriver driver;

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

    }

    private static WebDriver createDriver() {
        String browser = Config.BROWSER;
        switch (browser) {
            case "Chrome":
                ChromeDriverManager.getInstance().setup();
                return new ChromeDriver();
            case "Firefox":
                FirefoxDriverManager.getInstance().setup();
                return new FirefoxDriver();
            case "IE":
                InternetExplorerDriverManager.getInstance().setup();
                return new InternetExplorerDriver();
            case "Edge":
                EdgeDriverManager.getInstance().setup();
                return new EdgeDriver();
            default:
                throw new RuntimeException("Unknown browser: " + browser);
        }
    }

    public static void closeDrvier() {
        if(driver != null)
            driver.quit();
    }
}

@@ -485,16 +485,64 @@
 river;%0A%0A
+import java.util.concurrent.ConcurrentHashMap;%0A%0A
 public c
@@ -576,32 +576,56 @@
   private static
+ ConcurrentHashMap%3CLong,
  WebDriver drive
@@ -618,23 +618,50 @@
 ebDriver
+%3E
  driver
+ = new ConcurrentHashMap()
 ;%0A%0A    p
@@ -709,26 +709,55 @@
     
-if(driver == null)
+long threadId = Thread.currentThread().getId();
 %0A   
@@ -765,20 +765,45 @@
     
-    
 driver
- =
+.computeIfAbsent(threadId, k -%3E
  cre
@@ -805,32 +805,33 @@
 %3E createDriver()
+)
 ;%0A        return
@@ -837,16 +837,30 @@
 n driver
+.get(threadId)
 ;%0A%0A    %7D
@@ -1668,11 +1668,64 @@
     
-if(
+driver.forEach((number, webdriver) -%3E %7B%0A          if(web
 driv
@@ -1744,24 +1744,29 @@
             
+  web
 driver.quit(
@@ -1764,20 +1764,36 @@
 ver.quit();%0A
+        %7D);%0A    
     %7D%0A%7D%0A

Allow parallel execution