I have been working on this automation project for 2 years and now I am trying to implement parallel testing with ThreadLocal. I have done a lot of research on this and I have implemented ThreadLocal driver = new ThreadLocal<>(); in my BaseTestClass. My problem is I am using the page object model where each page is a class with objects. Eclipse is saying change constructor to
public LoginLogoutPage(ThreadLocal<WebDriver> driver) {
this.driver = driver;
}
I do that then I am prompted to change WebDriver driver; to ThreadLocal driver. After I do that all my fluent wait have a red line under them saying
"The constructor FluentWait<WebDriver>(ThreadLocal<WebDriver>) is undefined"
However I do not know how to fix this. Here is a snippet below.
public class BaseTestCriticalScenarios {
protected static ThreadLocal<WebDriver> driver = new ThreadLocal<>();
@BeforeClass
public void setUp() throws InterruptedException, MalformedURLException {
// --------Extent Report--------
report = ExtentManager.getInstance();
// -----------------------------
System.setProperty("webdriver.chrome.driver", "C:\\GRID\\chromedriver.exe");
ChromeOptions option = new ChromeOptions();
// --https://stackoverflow.com/questions/43143014/chrome-is-being-controlled-by-automated-test-software
option.setExperimentalOption("useAutomationExtension", false);
option.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
// --https://stackoverflow.com/questions/56311000/how-can-i-disable-save-password-popup-in-selenium
option.addArguments("--disable-features=VizDisplayCompositor");
option.addArguments("--start-maximized");
option.addArguments("--disable-gpu");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("credentials_enable_service", false);
prefs.put("profile.password_manager_enabled", false);
option.setExperimentalOption("prefs", prefs);
System.out.println(System.getenv("BUILD_NUMBER"));
String env = System.getProperty("BUILD_NUMBER");
if (env == null) {
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capability.setCapability(ChromeOptions.CAPABILITY, option);
option.merge(capability);
driver.set(new RemoteWebDriver(new URL(COMPLETE_NODE_URL), capability));
getDriver().get(HOME_PAGE);
getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
} else {
driver.set(new ChromeDriver(option));
getDriver().manage().window().maximize();
getDriver().get(HOME_PAGE);
getDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
public WebDriver getDriver() {
//Get driver from ThreadLocalMap
return driver.get();
}
Below is my page object class
Any help would be appreciated.