/// <summary> /// Creates an FirefoxDriver instance using the specified proxy settings. /// </summary> /// <param name="proxy">The WebDriver Proxy object containing the proxy settings.</param> /// <returns>An FirefoxDriver instance using the specified proxy settings</returns> private static IWebDriver CreateFirefoxDriverWithProxy(Proxy proxy) { // A future version of the .NET Firefox driver will likely move // to an "Options" model to be more consistent with other browsers' // API. FirefoxProfile profile = new FirefoxProfile(); profile.SetProxyPreferences(proxy); IWebDriver driver = new FirefoxDriver(profile); return driver; }
private static FirefoxProfile ExtractProfile(ICapabilities capabilities) { FirefoxProfile profile = new FirefoxProfile(); if (capabilities.GetCapability(ProfileCapabilityName) != null) { object raw = capabilities.GetCapability(ProfileCapabilityName); FirefoxProfile rawAsProfile = raw as FirefoxProfile; string rawAsString = raw as string; if (rawAsProfile != null) { profile = rawAsProfile; } else if (rawAsString != null) { try { profile = FirefoxProfile.FromBase64String(rawAsString); } catch (IOException e) { throw new WebDriverException("Unable to create profile from specified string", e); } } } if (capabilities.GetCapability(CapabilityType.Proxy) != null) { Proxy proxy = null; object raw = capabilities.GetCapability(CapabilityType.Proxy); Proxy rawAsProxy = raw as Proxy; Dictionary <string, object> rawAsMap = raw as Dictionary <string, object>; if (rawAsProxy != null) { proxy = rawAsProxy; } else if (rawAsMap != null) { proxy = new Proxy(rawAsMap); } profile.SetProxyPreferences(proxy); } if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null) { bool acceptCerts = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates); profile.AcceptUntrustedCertificates = acceptCerts; } return(profile); }
private static FirefoxProfile ExtractProfile(ICapabilities capabilities) { FirefoxProfile firefoxProfile = new FirefoxProfile(); if (capabilities.GetCapability(FirefoxDriver.ProfileCapabilityName) != null) { object capability = capabilities.GetCapability(FirefoxDriver.ProfileCapabilityName); FirefoxProfile firefoxProfile2 = capability as FirefoxProfile; string text = capability as string; if (firefoxProfile2 != null) { firefoxProfile = firefoxProfile2; } else if (text != null) { try { firefoxProfile = FirefoxProfile.FromBase64String(text); } catch (IOException innerException) { throw new WebDriverException("Unable to create profile from specified string", innerException); } } } if (capabilities.GetCapability(CapabilityType.Proxy) != null) { Proxy proxyPreferences = null; object capability2 = capabilities.GetCapability(CapabilityType.Proxy); Proxy proxy = capability2 as Proxy; Dictionary <string, object> dictionary = capability2 as Dictionary <string, object>; if (proxy != null) { proxyPreferences = proxy; } else if (dictionary != null) { proxyPreferences = new Proxy(dictionary); } firefoxProfile.SetProxyPreferences(proxyPreferences); } if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null) { bool acceptUntrustedCertificates = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates); firefoxProfile.AcceptUntrustedCertificates = acceptUntrustedCertificates; } return(firefoxProfile); }
protected WebDriverBackedSelenium webdriver; //for selenium #endregion Fields #region Constructors public TestRunner() { testcount = 0; errorcount = 0; passedcount = 0; warningcount = 0; ffprofile = new FirefoxProfile();//For internal firewal prxsettings = new Proxy();//Ditto^^ prxsettings.IsAutoDetect = true;//Ditto x2 ffprofile.SetProxyPreferences(prxsettings);//ditto x3 browsertext = new Font(FontFamily.GenericSansSerif, 14f, FontStyle.Bold); //These were picked testtext = new Font(FontFamily.GenericSansSerif, 10f, FontStyle.Regular); //to give better emphasis scripttext = new Font(FontFamily.GenericSansSerif, 10.5f, FontStyle.Bold);//for reporting regulartext = new Font(FontFamily.GenericSansSerif, 8f, FontStyle.Regular);//can be changed errortext = new Font(FontFamily.GenericSerif, 9.5f, FontStyle.Regular);//if better combo is found scriptlist = new List<List<ParentTest>>();//For grabbing the individual tests. The order they are added matters for index purposes. objectpool = new List<ParentTest>(); //list to hold old tests for recycling. //Thread.Sleep(1000); }
/// <summary> /// Gets the proxy profile. /// </summary> /// <returns></returns> private FirefoxProfile GetProxyProfile() { var settings = UserSettingsHelper.GlobalUserSettings; var useProxy = settings.useProxy; if (!useProxy) { return new FirefoxProfile(); } var proxy = new Proxy(); var proxyType = settings.proxyType; var port = settings.proxyPort; var ip = settings.proxyIp; if (ip.IsNullOrBlank() || port.IsNullOrBlank()) { return new FirefoxProfile(); } ip += ":" + port; var user = settings.proxyUser; var pass = settings.proxyPass; proxy.Kind = ProxyKind.Manual; //HTTP PROXY if (proxyType == 0) { proxy.HttpProxy = ip; } else { proxy.SocksProxy = ip; } proxy.SslProxy = ip; proxy.FtpProxy = ip; proxy.SocksUserName = user; proxy.SocksPassword = pass; var fp = new FirefoxProfile(); fp.SetProxyPreferences(proxy); fp.SetPreference("network.websocket.enabled", "false"); return fp; }
private static FirefoxProfile ExtractProfile(ICapabilities capabilities) { FirefoxProfile profile = new FirefoxProfile(); if (capabilities.GetCapability(ProfileCapabilityName) != null) { object raw = capabilities.GetCapability(ProfileCapabilityName); FirefoxProfile rawAsProfile = raw as FirefoxProfile; string rawAsString = raw as string; if (rawAsProfile != null) { profile = rawAsProfile; } else if (rawAsString != null) { try { profile = FirefoxProfile.FromBase64String(rawAsString); } catch (IOException e) { throw new WebDriverException("Unable to create profile from specified string", e); } } } if (capabilities.GetCapability(CapabilityType.Proxy) != null) { Proxy proxy = null; object raw = capabilities.GetCapability(CapabilityType.Proxy); Proxy rawAsProxy = raw as Proxy; Dictionary<string, object> rawAsMap = raw as Dictionary<string, object>; if (rawAsProxy != null) { proxy = rawAsProxy; } else if (rawAsMap != null) { proxy = new Proxy(rawAsMap); } profile.SetProxyPreferences(proxy); } if (capabilities.GetCapability(CapabilityType.AcceptSslCertificates) != null) { bool acceptCerts = (bool)capabilities.GetCapability(CapabilityType.AcceptSslCertificates); profile.AcceptUntrustedCertificates = acceptCerts; } return profile; }
/// <summary> /// Возвращает драйвер браузера с настройками прокси на актуальный сервер /// </summary> /// <returns></returns> public IWebDriver GetDriver(bool useProxy) { IWebDriver driver = null; if (useProxy) { Random r = new Random(DateTime.Now.Millisecond); bool workedProxyIsFound = false; //выбираем случайный прокси из списка адресов в конфиге до тех пор, пока не найдем рабочий do { int proxyIndex = r.Next(document["settings"]["proxies"].ChildNodes.Count); string PROXY = document["settings"]["proxies"].ChildNodes[proxyIndex].Attributes[0].Value; Proxy proxy = new Proxy(); proxy.HttpProxy = PROXY; proxy.FtpProxy = PROXY; proxy.SslProxy = PROXY; switch (document["settings"]["driver"].GetAttribute("name")) { case "GoogleChrome": ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.Proxy = proxy; driver = new ChromeDriver(document["settings"]["driver"].GetAttribute("path"), chromeOptions, TimeSpan.FromSeconds(300)); break; case "Firefox": FirefoxProfile profile = new FirefoxProfile(); profile.SetProxyPreferences(proxy); driver = new FirefoxDriver(new FirefoxBinary(), profile, TimeSpan.FromSeconds(300)); break; case "Opera": OperaOptions operaOptions = new OperaOptions(); operaOptions.Proxy = proxy; driver = new OperaDriver(document["settings"]["driver"].GetAttribute("path"), operaOptions, TimeSpan.FromSeconds(300)); break; case "IE": InternetExplorerOptions IEOptions = new InternetExplorerOptions(); IEOptions.Proxy = proxy; driver = new InternetExplorerDriver(document["settings"]["driver"].GetAttribute("path"), IEOptions, TimeSpan.FromSeconds(300)); break; } //Проверяем работу прокси обращаясь к гуглу driver.Navigate().GoToUrl("http://www.google.ru/"); Thread.Sleep(10000); workedProxyIsFound = driver.Title == "Google"; if (!workedProxyIsFound) driver.Quit(); } while (!workedProxyIsFound); } else { switch (document["settings"]["driver"].GetAttribute("name")) { case "GoogleChrome": driver = new ChromeDriver(document["settings"]["driver"].GetAttribute("path")); break; case "Firefox": driver = new FirefoxDriver(new FirefoxBinary(), new FirefoxProfile(), TimeSpan.FromSeconds(120)); break; case "Opera": driver = new OperaDriver(document["settings"]["driver"].GetAttribute("path")); break; case "IE": driver = new InternetExplorerDriver(document["settings"]["driver"].GetAttribute("path")); break; } } return driver; }
/// <summary> /// Performs the initialize of the browser. /// </summary> /// <param name="driverFolder">The driver folder.</param> /// <param name="proxy">The proxy.</param> /// <returns> /// The web driver. /// </returns> protected override IWebDriver PerformInitialize(string driverFolder, Proxy proxy) { var profile = new FirefoxProfile(); profile.SetProxyPreferences(proxy); return new FirefoxDriver(profile); }