本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}