Skip to content

Commit

Permalink
Create new Webdriver because it is disposed
Browse files Browse the repository at this point in the history
  • Loading branch information
DSPaul committed Feb 20, 2023
1 parent f54d5bb commit d9ee962
Showing 1 changed file with 33 additions and 36 deletions.
69 changes: 33 additions & 36 deletions src/Tools/WebDriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,51 @@ public enum Browser
private static WebDriver _webDriver;
public static WebDriver GetWebDriver()
{
if (_webDriver is null)
string driverName = browser switch
{
string driverName = browser switch
{
Browser.Chrome => "chromedriver.exe",
Browser.Firefox => "geckodriver.exe",
_ => "msedgedriver.exe"
};
Browser.Chrome => "chromedriver.exe",
Browser.Firefox => "geckodriver.exe",
_ => "msedgedriver.exe"
};

string driverPath = FindFileDirectory(driverName, WebDriverDirectoryPath);
string driverPath = FindFileDirectory(driverName, WebDriverDirectoryPath);

DriverService driverService = browser switch
{
Browser.Chrome => ChromeDriverService.CreateDefaultService(driverPath),
Browser.Firefox => FirefoxDriverService.CreateDefaultService(driverPath),
_ => EdgeDriverService.CreateDefaultService(driverPath)
};
DriverService driverService = browser switch
{
Browser.Chrome => ChromeDriverService.CreateDefaultService(driverPath),
Browser.Firefox => FirefoxDriverService.CreateDefaultService(driverPath),
_ => EdgeDriverService.CreateDefaultService(driverPath)
};

driverService.HideCommandPromptWindow = true;
driverService.HideCommandPromptWindow = true;

List<string> DriverArguments = new()
List<string> DriverArguments = new()
{
"--headless",
"--window-size=3000,3000",
"--width=3000",
"--height=3000"
};

switch (browser)
{
case Browser.Chrome:
ChromeOptions CO = new();
CO.AddArguments(DriverArguments);
_webDriver = new ChromeDriver((ChromeDriverService)driverService, CO);
break;

case Browser.Firefox:
FirefoxOptions FO = new();
FO.AddArguments(DriverArguments);
_webDriver = new FirefoxDriver((FirefoxDriverService)driverService, FO);
break;

default:
EdgeOptions EO = new();
EO.AddArguments(DriverArguments);
_webDriver = new EdgeDriver((EdgeDriverService)driverService, EO);
break;
}
switch (browser)
{
case Browser.Chrome:
ChromeOptions CO = new();
CO.AddArguments(DriverArguments);
_webDriver = new ChromeDriver((ChromeDriverService)driverService, CO);
break;

case Browser.Firefox:
FirefoxOptions FO = new();
FO.AddArguments(DriverArguments);
_webDriver = new FirefoxDriver((FirefoxDriverService)driverService, FO);
break;

default:
EdgeOptions EO = new();
EO.AddArguments(DriverArguments);
_webDriver = new EdgeDriver((EdgeDriverService)driverService, EO);
break;
}
return _webDriver;
}
Expand Down

0 comments on commit d9ee962

Please sign in to comment.