Loading drivers for cross-browser testing with Selenium
Another post so I don't forget how I fixed a problem....
I have been making sure some Selenium UX tests that were originally written against Chrome also work with other browsers. I have had a few problems, the browser under test failing to load or Selenium not being able to find elements.
Turns out the solution is to just use the custom driver start-up options, the default constructors don't seem to work for browsers other theran Chrome and Firefox.
Hence, I not have helper method that creates a driver from me based the a configuration parameter
1 internal static IWebDriver GetWebDriver()
2 {
3 var driverName = GetWebConfigSetting("webdriver");
4 switch (driverName)
5 {
6 case "Chrome":
7 return new ChromeDriver();
8 case "Firefox":
9 return new FirefoxDriver();
10 case "IE":
11 InternetExplorerOptions caps = new InternetExplorerOptions();
12 caps.IgnoreZoomLevel = true;
13 caps.EnableNativeEvents = false;
14 caps.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
15 caps.EnablePersistentHover = true;
16 return new InternetExplorerDriver(caps);
17 case "Edge-Chromium":
18 var service = EdgeDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), "msedgedriver.exe");
19 return new EdgeDriver(service);
20 default:
21 throw new ConfigurationErrorsException($"{driverName} is not a known Selenium WebDriver");
22 }
23 }