// --------------------------------------------------------------- // CREATING A SESSION // --------------------------------------------------------------- // --------------------------------------------------------------- /// <summary> /// <para>Returns a String for the filename of the WebDriver</para> /// <para>browserName = The name of the browser /// <br>---Gecko = FF or FireFox</br> /// <br>---Chrome = Google or Chrome</br> /// <br>---IE = IE or IExplore</br> /// <br>---MSEdge = Edge or MSEdge</br></para> /// </summary> /// <returns>String value for the driver's file name</returns> private void SetDriverFileName() { string funcName = "SetDriverFileName"; switch (BrowserName.ToLower()) { case "ff": case "firefox": DriverFileName = CTConstants.FIREFOX_DRIVER_NAME; break; case "chrome": case "google": DriverFileName = CTConstants.CHROME_DRIVER_NAME; break; case "ie": case "iexplore": DriverFileName = CTConstants.IE_DRIVER_NAME; break; case "edge": case "msedge": DriverFileName = CTConstants.MSEDGE_DRIVER_NAME; break; default: string LogMsg = "The Browser Provided does not match an acceptable value."; logger.Write(LogMsg, funcName, CTConstants.LOG_CRITICAL); throw new Exception(LogMsg); } }
/// <summary> /// <para>Creates the IWebDriver session based on the browser selected</para> /// <para>browserName = The name of the browser /// <br>---Gecko = FF or FireFox</br> /// <br>---Chrome = Google or Chrome</br> /// <br>---IE = IE or IExplore</br> /// <br>---MSEdge = Edge or MSEdge</br></para> /// </summary> /// <param name="browserName"></param> /// <returns></returns> private IWebDriver CreateSession() { string funcName = "CreateSession"; try { switch (BrowserName.ToLower()) { case "ff": return(new FirefoxDriver(DriverFilePath)); case "firefox": return(new FirefoxDriver(DriverFilePath)); case "chrome": return(new ChromeDriver(DriverFilePath)); case "google": return(new ChromeDriver(DriverFilePath)); case "ie": return(new InternetExplorerDriver(DriverFilePath)); case "iexplore": return(new InternetExplorerDriver(DriverFilePath)); case "edge": return(new EdgeDriver(DriverFilePath)); case "msedge": return(new EdgeDriver(DriverFilePath)); default: string LogMsg = "Unable to Locate WebDriver"; logger.Write(LogMsg, funcName); throw new Exception(LogMsg); } } catch (Exception e) { LogMsg = $"Error while Attempting to Create Session\n{e}"; logger.Write(LogMsg, funcName, CTConstants.LOG_CRITICAL); throw new Exception(LogMsg); } }
private DesiredCapabilities PopulateCapabilities() { NameValueCollection capabilities = ConfigurationManager.GetSection("capabilities/" + RunProfile.ToString().ToLower()) as NameValueCollection; NameValueCollection browserSettings = ConfigurationManager.GetSection("environments/" + BrowserName.ToLower()) as NameValueCollection; DesiredCapabilities capability = new DesiredCapabilities(); foreach (string key in capabilities.AllKeys) { capability.SetCapability(key, capabilities[key].FormatTokens(ScenarioContext)); } foreach (string key in browserSettings.AllKeys) { capability.SetCapability(key, browserSettings[key]); } return(capability); }
private static DesiredCapabilities BuildDesiredCapabilities() { DesiredCapabilities dc; if (IsSauceLabsDesktopTest) { switch (BrowserName.ToLower()) { case "firefox": dc = DesiredCapabilities.Firefox(); break; case "chrome": dc = DesiredCapabilities.Chrome(); break; case "safari": dc = DesiredCapabilities.Safari(); break; case "ie": dc = DesiredCapabilities.InternetExplorer(); break; default: dc = DesiredCapabilities.InternetExplorer(); break; } dc.SetCapability(CapabilityType.Version, BrowserVersion); dc.SetCapability(CapabilityType.Platform, OperatingSystem); dc.SetCapability("screen-resolution", Resolution); } else { switch (DeviceType.ToLower()) { case "android": dc = DesiredCapabilities.Android(); break; case "iphone": dc = DesiredCapabilities.IPhone(); break; default: dc = DesiredCapabilities.IPhone(); break; } dc.SetCapability(CapabilityType.Platform, DevicePlatform); dc.SetCapability(CapabilityType.Version, DeviceOsVersion); dc.SetCapability("deviceName", DeviceName); dc.SetCapability("device-orientation", DeviceOrientation); } dc.SetCapability(CapabilityType.IsJavaScriptEnabled, JavaScriptEnabled); dc.SetCapability(CapabilityType.HandlesAlerts, "dismiss"); dc.SetCapability(CapabilityType.TakesScreenshot, "true"); dc.SetCapability("tags", Tags); dc.SetCapability("name", TestName); dc.SetCapability("username", "seanrand"); dc.SetCapability("accessKey", "2002db9c-71fb-4f6a-a691-2e249eea98c2"); return(dc); }