当前位置: 首页>>代码示例>>C#>>正文


C# FirefoxProfile.SetProxyPreferences方法代码示例

本文整理汇总了C#中OpenQA.Selenium.Firefox.FirefoxProfile.SetProxyPreferences方法的典型用法代码示例。如果您正苦于以下问题:C# FirefoxProfile.SetProxyPreferences方法的具体用法?C# FirefoxProfile.SetProxyPreferences怎么用?C# FirefoxProfile.SetProxyPreferences使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenQA.Selenium.Firefox.FirefoxProfile的用法示例。


在下文中一共展示了FirefoxProfile.SetProxyPreferences方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFirefoxDriverWithProxy

        /// <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;
        }
开发者ID:jimevans,项目名称:WebDriverProxyExamples,代码行数:16,代码来源:WebDriverFactory.cs

示例2: TestRunner

        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);
        }
开发者ID:garqahub,项目名称:SeleniumRegression,代码行数:25,代码来源:TestRunner.cs

示例3: GetProxyProfile

        /// <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;
        }
开发者ID:rosudrag,项目名称:SomerBlinkBotPublic,代码行数:53,代码来源:LocalBot.cs

示例4: ExtractProfile

        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;
        }
开发者ID:glib-briia,项目名称:selenium,代码行数:51,代码来源:FirefoxDriver.cs

示例5: GetDriver

 /// <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;
 }
开发者ID:CitrusVento,项目名称:AutoTest,代码行数:72,代码来源:DriverConfig.cs

示例6: PerformInitialize

 /// <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);
 }
开发者ID:giacomelli,项目名称:SpecFlowHelper,代码行数:14,代码来源:FirefoxBrowser.cs


注:本文中的OpenQA.Selenium.Firefox.FirefoxProfile.SetProxyPreferences方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。