private async Task<IWebDriver> WaitForAvailable(string processId) { var stopwa = new Stopwatch(); stopwa.Start(); IWebDriver claimedDriver = null; while (claimedDriver == null) { var firstAvailable = _drivers.FirstOrDefault(d => !_claimedDrivers.ContainsKey(d.Id)); if (firstAvailable != null) { var added = _claimedDrivers.TryAdd(firstAvailable.Id, DateTime.UtcNow); if (added) { bool cont = true; if (!firstAvailable.IsInitialized) { try { firstAvailable.WebDriver = SeleniumSetup.GetWebDriver(_preferredBrowser); } catch (Exception) { DateTime timestamp; firstAvailable.IsInitialized = false; _claimedDrivers.TryRemove(firstAvailable.Id, out timestamp); cont = false; } } if (cont) { firstAvailable.IsInitialized = true; claimedDriver = firstAvailable.WebDriver; break; } } } else { _logger.Info("Process with id " + processId + " still waiting for webdriver to claim. Waited for " + stopwa.Elapsed.TotalMinutes + " minutes"); await Task.Delay(2000); } } return claimedDriver; }
public async Task <IWebDriver> Get(string processId) { return(SeleniumSetup.GetWebDriver(_preferredBrowser)); }