public static IWebDriver initializeDriver(BrowserType myBrowser) { if (myBrowser.Equals(BrowserType.Chrome)) { driver = new ChromeDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(5000); driver.Manage().Window.Maximize(); } else if (myBrowser.Equals(BrowserType.Firefox)) { driver = new FirefoxDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(5000); driver.Manage().Window.Maximize(); } else if (myBrowser.Equals(BrowserType.InternetExplorer)) { driver = new InternetExplorerDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(5000); driver.Manage().Window.Maximize(); } else { driver = new SafariDriver(); driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMilliseconds(5000); driver.Manage().Window.Maximize(); } return(driver); }
private RemoteWebDriver GetAuthenticatedDriver(BrowserType browserType, String browserMobPath, String domain, String username, String password) { if (browserType.Equals(BrowserType.Firefox)) { return(GetModifiedFirefoxDriver(browserMobPath, domain, username, password)); } else if (browserType.Equals(BrowserType.IE)) { return(GetModifiedIEDriver(browserMobPath, domain, username, password)); } else if (browserType.Equals(BrowserType.Chrome)) { return(GetModifiedChromeDriver(browserMobPath, domain, username, password)); } else { throw new Exception("BrowserType: " + browserType.ToString() + " not supported"); } }
public override bool Equals(object obj) { var browserConfiguration = (BrowserConfiguration)obj; return(ExecutionType.Equals(browserConfiguration?.ExecutionType) && BrowserType.Equals(browserConfiguration?.BrowserType) && ShouldCaptureHttpTraffic.Equals(browserConfiguration?.ShouldCaptureHttpTraffic) && Size.Equals(browserConfiguration?.Size) && ShouldAutomaticallyScrollToVisible.Equals(browserConfiguration?.ShouldAutomaticallyScrollToVisible)); }
private static IWebDriver GetDriverForGrid(BrowserType browserType) { DesiredCapabilities capabilities; switch (browserType) { case BrowserType.Firefox: capabilities = DesiredCapabilities.Firefox(); break; case BrowserType.IE: capabilities = DesiredCapabilities.InternetExplorer(); capabilities.SetCapability("ie.ensureCleanSession", "true"); break; case BrowserType.Chrome: capabilities = DesiredCapabilities.Chrome(); break; case BrowserType.Safari: capabilities = DesiredCapabilities.Safari(); break; default: throw new ArgumentException("Unrecognised browser choice '" + browserType + "' when initialising driver for Grid."); } var platform = browserType.Equals(BrowserType.Safari) ? PlatformType.Mac : PlatformType.Vista; capabilities.SetCapability(CapabilityType.Platform, new Platform(platform)); // So we know who's using it capabilities.SetCapability("environment", String.Format("{0} ({1})", Configuration.Configuration.GridIdentifier, Environment.MachineName)); IWebDriver driver; try { driver = new SeleniumGridDriver( new Uri(Configuration.Configuration.GridHubUrl), capabilities, TimeSpan.FromSeconds(900)); } catch (Exception) { WebDriverEventLog.Add(String.Format("Failed when attempting to initialise a {0} browser on the Selenium Grid.{1}", capabilities.BrowserName, Environment.NewLine)); throw; } WebDriverEventLog.Add(String.Format("Grid Node: '{0}'{1}", ((SeleniumGridDriver)driver).RemoteHost, Environment.NewLine)); return(driver); }
private void SelectBrowser(BrowserType browser) { if (browser.Equals(BrowserType.FireFox)) { var dirDriver = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\Resource\"; FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(dirDriver, "geckodriver.exe"); service.HideCommandPromptWindow = true; driver = new FirefoxDriver(service); objectContainer.RegisterInstanceAs <RemoteWebDriver>(driver); } }
public bool Equals(BrowserConfiguration other) => ExecutionType.Equals(other?.ExecutionType) && BrowserType.Equals(other?.BrowserType) && ShouldCaptureHttpTraffic.Equals(other?.ShouldCaptureHttpTraffic) && Size.Equals(other?.Size) && IsLighthouseEnabled.Equals(other?.IsLighthouseEnabled) && ShouldAutomaticallyScrollToVisible.Equals(other?.ShouldAutomaticallyScrollToVisible);
private static string GetURLFromProcess(Process process, BrowserType browser, IntPtr handle) { if (process == null) { throw new ArgumentNullException("process"); } if (process.MainWindowHandle == IntPtr.Zero) { return(null); } AutomationElement automationElement = null; try { automationElement = AutomationElement.FromHandle(handle); } catch (Exception ex) { StaticFileLogger.Current.LogEvent("CurrentBrowswerUrlsTool.GetUrlFromProcess()", "Error getting AutomationElement.FromHandle()", ex.ToString(), EventLogEntryType.Error); } if (automationElement == null) { return(null); } if (browser.Equals(BrowserType.GOOGLE_CHROME)) { AutomationElement automationElement2 = null; try { AutomationElement automationElement3 = automationElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Google Chrome")); if (automationElement3 == null) { return(null); } AutomationElement lastChild = TreeWalker.RawViewWalker.GetLastChild(automationElement3); AutomationElement automationElement4 = lastChild.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane)); AutomationElement automationElement5 = automationElement4.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Pane)); automationElement2 = automationElement5.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AccessKeyProperty, "Ctrl+L")); if (automationElement2 == null) { automationElement2 = automationElement3.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.AccessKeyProperty, "Ctrl+L")); } } catch { return(null); } if (automationElement2 != null) { if ((bool)automationElement2.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty)) { return(null); } AutomationPattern[] supportedPatterns = automationElement2.GetSupportedPatterns(); if (supportedPatterns.Length == 1) { string text = ""; try { text = ((ValuePattern)automationElement2.GetCurrentPattern(supportedPatterns[0])).Current.Value; } catch { } if (text != "" && Regex.IsMatch(text, "^(https:\\/\\/)?[a-zA-Z0-9\\-\\.]+(\\.[a-zA-Z]{2,4}).*$")) { if (!text.StartsWith("http")) { text = "http://" + text; } return(text); } return(null); } } return(null); } if (browser.Equals(BrowserType.FIREFOX)) { try { AutomationElementCollection automationElementCollection = automationElement.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.ToolBar)); foreach (AutomationElement item in automationElementCollection) { AutomationElementCollection automationElementCollection2 = item.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); foreach (AutomationElement item2 in automationElementCollection2) { if ((bool)item2.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty)) { return(null); } string text2 = ((ValuePattern)item2.GetCurrentPattern(ValuePattern.Pattern)).Current.Value; if (text2 != "") { if (Regex.IsMatch(text2, "^(https:\\/\\/)?[a-zA-Z0-9\\-\\.]+(\\.[a-zA-Z]{2,4}).*$")) { if (!text2.StartsWith("http")) { text2 = "http://" + text2; } return(text2); } return(text2); } } } } catch { } } if (browser.Equals(BrowserType.INTERNET_EXPLORER)) { AutomationElement automationElement8 = automationElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "ReBarWindow32")); if (automationElement8 == null) { return(null); } AutomationElement automationElement9 = automationElement8.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); if (automationElement9 != null) { string text3 = ((ValuePattern)automationElement9.GetCurrentPattern(ValuePattern.Pattern)).Current.Value; if (text3 != "" && Regex.IsMatch(text3, "^(https:\\/\\/)?[a-zA-Z0-9\\-\\.]+(\\.[a-zA-Z]{2,4}).*$")) { if (!text3.StartsWith("http")) { text3 = "http://" + text3; } return(text3); } } } if (browser.Equals(BrowserType.MICROSOFT_EDGE)) { AutomationElement automationElement10 = automationElement.FindFirst(TreeScope.Children, new AndCondition(new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window), new PropertyCondition(AutomationElement.NameProperty, "Microsoft Edge"))); if (automationElement10 == null) { return(null); } AutomationElement automationElement11 = automationElement10.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "addressEditBox")); if (automationElement11 != null) { if ((bool)automationElement11.GetCurrentPropertyValue(AutomationElement.HasKeyboardFocusProperty)) { return(null); } string text4 = ((TextPattern)automationElement11.GetCurrentPattern(TextPattern.Pattern)).DocumentRange.GetText(int.MaxValue); if (text4 != "" && Regex.IsMatch(text4, "^(https:\\/\\/)?[a-zA-Z0-9\\-\\.]+(\\.[a-zA-Z]{2,4}).*$")) { if (!text4.StartsWith("http")) { text4 = "http://" + text4; } return(text4); } return(text4); } } return(null); }