當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。