本文整理汇总了C#中OpenQA.Selenium.Firefox.FirefoxProfile.AddExtension方法的典型用法代码示例。如果您正苦于以下问题:C# FirefoxProfile.AddExtension方法的具体用法?C# FirefoxProfile.AddExtension怎么用?C# FirefoxProfile.AddExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Firefox.FirefoxProfile
的用法示例。
在下文中一共展示了FirefoxProfile.AddExtension方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartBrowser
internal IWebDriver StartBrowser(string browserType)
{
if (_driver != null)
{
_driver.Quit();
}
switch (browserType)
{
case "ie":
{
_driver = new InternetExplorerDriver();
break;
}
case "firefox":
{
const string fileFirebug = "E:/DotNetNuke/Selenium/firebug-1.11.1-fx.xpi";
const string fileNetExport = "E:/DotNetNuke/Selenium/netExport-0.9b3.xpi";
const string resultDir = "E:/DotNetNuke/Results";
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.AcceptUntrustedCertificates = true;
firefoxProfile.AddExtension(fileFirebug);
firefoxProfile.AddExtension(fileNetExport);
firefoxProfile.SetPreference("extensions.firebug.currentVersion", "1.11.1"); // Avoid startup screen
firefoxProfile.SetPreference("extensions.firebug.previousPlacement", 1); //Previous Firebug UI placement within the browser (0-unknown, 1-in browser, 2-in a new window, 3-minimized
firefoxProfile.SetPreference("extensions.firebug.onByDefault", true);
firefoxProfile.SetPreference("extensions.firebug.defaultPanelName", "net"); //Panel shown by default; "console", "html", "stylesheet", "script", "dom", "net" + Panels from extensions
firefoxProfile.SetPreference("extensions.firebug.netexport.alwaysEnableAutoExport", true);
firefoxProfile.SetPreference("extensions.firebug.netexport.defaultLogDir", resultDir);
firefoxProfile.SetPreference("extensions.firebug.netexport.showPreview", false);
firefoxProfile.SetPreference("extensions.firebug.allPagesActivation", "on"); //Specifies whether Firebug shall be enabled by default for all websites
firefoxProfile.SetPreference("extensions.firebug.net.enableSites", true); //Specifies whether the Net Panel is enabled
_driver = new FirefoxDriver(firefoxProfile);
break;
}
case "chrome":
{
_driver = new ChromeDriver();
break;
}
}
_driver.Manage().Window.Maximize();
return _driver;
}
示例2: OpenPage
private RemoteWebDriver OpenPage(string url)
{
var profile = new FirefoxProfile();
profile.AddExtension("firebug-1.6.2.xpi");
profile.SetPreference("extensions.firebug.currentVersion", "9.99");
RemoteWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl(url);
return driver;
}
示例3: BuildFFDriver
private IWebDriver BuildFFDriver()
{
FirefoxProfile ffProfile = new FirefoxProfile();
JavaScriptError.AddExtension(ffProfile);
ffProfile.AddExtension(SaveBinaryResource("firebug-2.0.8-fx.xpi", TestResources.firebug_2_0_8_fx));
ffProfile.SetPreference("extensions.firebug.showStackTrace", "true");
ffProfile.SetPreference("extensions.firebug.delayLoad", "false");
ffProfile.SetPreference("extensions.firebug.showFirstRunPage", "false");
ffProfile.SetPreference("extensions.firebug.allPagesActivation", "on");
ffProfile.SetPreference("extensions.firebug.console.enableSites", "true");
ffProfile.SetPreference("extensions.firebug.defaultPanelName", "console");
return new FirefoxDriver(ffProfile);
}
示例4: TakeScreenshotsByCityCoordinates
public void TakeScreenshotsByCityCoordinates()
{
FirefoxProfile profile = new FirefoxProfile();
profile.AddExtension(this.adBlockPath);
this.driver = new FirefoxDriver(profile);
//ChromeOptions options = new ChromeOptions();
//options.AddExtension(this.adBlockChromePath);
//this.driver = new ChromeDriver(this.chromeDriverPath, options);
this.driver.Manage().Window.Maximize();
this.driver.Url = this.baseUrl;
this.driver.Url = this.cityListUrl;
CityListPage cityListPage = new CityListPage();
this.WaitForElement(cityListPage.ResultsTableLocator);
IWebElement[] links = this.driver.FindElements(cityListPage.ResultsTableLocator).ToArray();
List<string> linkUrls = new List<string>();
for (int i = 0; i < 10; i++)
{
linkUrls.Add(links[i].GetAttribute("href"));
}
CityInfoPage cityInfoPage = new CityInfoPage();
GoogleMapsPage googleMapsPage = new GoogleMapsPage();
foreach (var linkUrl in linkUrls)
{
this.driver.Url = linkUrl;
this.WaitForElement(cityInfoPage.CityTableLocator);
CityInfo info = cityInfoPage.GetCityInfo(this.driver);
this.driver.Url = info.GoogleMapsLink;
this.WaitForElement(googleMapsPage.StreetViewControl);
this.TakeScreenshot(this.screenshotsPath + info.ToString() + ".jpg");
}
this.driver.Dispose();
}
示例5: CreateExtensionConnection
private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
{
FirefoxProfile profileToUse = profile;
string suggestedProfile = Environment.GetEnvironmentVariable("webdriver.firefox.profile");
if (profileToUse == null && suggestedProfile != null)
{
profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
}
else if (profileToUse == null)
{
profileToUse = new FirefoxProfile();
profileToUse.AddExtension(false);
}
else
{
profileToUse.AddExtension(false);
}
ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");
return extension;
}
示例6: CreateExtensionConnection
private static ExtensionConnection CreateExtensionConnection(FirefoxBinary binary, FirefoxProfile profile)
{
FirefoxProfile profileToUse = profile;
// TODO (JimEvans): Provide a "named profile" override.
// string suggestedProfile = System.getProperty("webdriver.firefox.profile");
string suggestedProfile = null;
if (profileToUse == null && suggestedProfile != null)
{
profileToUse = new FirefoxProfileManager().GetProfile(suggestedProfile);
}
else if (profileToUse == null)
{
profileToUse = new FirefoxProfile();
profileToUse.AddExtension(false);
}
else
{
profileToUse.AddExtension(false);
}
ExtensionConnection extension = ConnectTo(binary, profileToUse, "localhost");
return extension;
}
示例7: tstObject
public tstObject(int typNum, ref string profilePath, string baseURL)
{
brwsrType = typNum;
switch (typNum)
{
case 0:
{
SafariOptions opt1 = new SafariOptions();
opt1.CustomExtensionPath = Application.StartupPath + "\\SafariDriver2.32.0.safariextz";
opt1.SkipExtensionInstallation = false;
driver = new SafariDriver(opt1);
break;
}
case 1:
{
string runProfile = Application.StartupPath + "\\Firefox Profile";
string firebugPath = Application.StartupPath + "\\Firefox Profile\\firebug-1.9.2.xpi";
FirefoxProfile profile = new FirefoxProfile(runProfile);
//add firebug to the profile
//profile.AddExtension(firebugPath);
//add firePath to the profile
profile.AddExtension(firebugPath);
//set the webdriver_assume_untrusted_issuer to false
profile.SetPreference("webdriver_assume_untrusted_issuer", false);
//run the profile
driver = new FirefoxDriver(profile);
//maximize window
driver.Manage().Window.Maximize();
//Wait 4 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
break;
}
//create a Chrome object
case 2:
{
var options = new ChromeOptions();
//set the startup options to start maximzed
options.AddArguments("start-maximized");
//start Chrome maximized
driver = new ChromeDriver(@Application.StartupPath, options);
//Wait 10 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
break;
}
//create an IE object
case 3:
{
//var options = new InternetExplorerOptions();
//set the startup options to start maximzed
//options.ToCapabilities();
driver = new InternetExplorerDriver(@Application.StartupPath);
//maximize window
driver.Manage().Window.Maximize();
//Wait 4 seconds for an item to appear
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
break;
}
}
}
示例8: AddExtension
/// <summary>
/// Adds the Firefox extension collecting JS errors to the profile, which allows later use of
/// ReadErrors(WebDriver).
/// </summary>
/// <example><code>
/// FirefoxProfile profile = new FirefoxProfile();
/// JavaScriptError.AddExtension(profile);
/// IWebDriver driver = new FirefoxDriver(profile);
/// </code></example>
public static void AddExtension(FirefoxProfile ffProfile)
{
ffProfile.AddExtension(extractedXpiPath);
}
示例9: GetFirefoxptions
private static FirefoxProfile GetFirefoxptions()
{
var profile = new FirefoxProfile();
profile.AddExtension(@"C:\downloads\FirefoxGoogleAnalytics.xpi");
return profile;
}
示例10: IntiailizeDriver
public void IntiailizeDriver(ref IWebDriver driver, ref bool isBrowserDimendion, ref List<IWebDriver> driverlist, ref int width, ref int height, ref string addonsPath)
{
if ((FirefoxProfilePath.Length != 0) && Directory.Exists(FirefoxProfilePath) && (FirefoxProfilePath.Split('.').Last().ToString().ToLower() != "zip"))
{
string ffProfileSourcePath = FirefoxProfilePath;
DirectoryInfo ffProfileSourceDir = new DirectoryInfo(ffProfileSourcePath);
if (!ffProfileSourceDir.Exists)
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0012"));
FfProfile = new FirefoxProfile(ffProfileSourceDir.ToString());
if ((Common.Utility.GetParameter("FirefoxProfilePath")).Equals(Common.Utility.GetVariable("FirefoxProfilePath")))
{
InitFireFox(ref driver,ref isBrowserDimendion,ref driverlist,ref width,ref height);
Common.Utility.SetVariable("FirefoxProfilePath", _ffProfileDestDir.ToString());
}
else
{
//If Profile path is empty in parameter file then add setpreference to profile.:
if (Common.Utility.GetParameter("FirefoxProfilePath").Equals(""))
{
FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
}
InitFireFox(ref driver, ref isBrowserDimendion, ref driverlist, ref width, ref height);
}
}
else
{
// If "addonsPath" contains path then load addons from that directory path.
if (addonsPath.Length != 0)
{
try
{
string adPath = addonsPath;
if (!Directory.Exists(adPath))
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0014"));
DirectoryInfo adDir = new DirectoryInfo(adPath);
DirectoryInfo adDirTemp = new DirectoryInfo("AddonsTemp");
adDirTemp.Create();
foreach (FileInfo fi in adDir.GetFiles())
{
fi.CopyTo(Path.Combine(adDirTemp.FullName, fi.Name), true);
}
int firebugCount = 0;
string[] addonFilePaths = Directory.GetFiles(adPath);
FfProfile = new FirefoxProfile();
FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
FfProfile.SetPreference("network.cookie.lifetimePolicy", 0);
FfProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
FfProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
SetCommonPreferences();
//Assigning profile location so that firefox can next time use same profile to open
Common.Utility.SetVariable("FirefoxProfilePath", FfProfile.ProfileDirectory.ToString());
// Add all the addons found in the specified addon directory
foreach (FileInfo afi in adDirTemp.GetFiles())
{
if (afi.Name.ToLower().Contains("firebug"))
firebugCount++;
FfProfile.AddExtension(adDirTemp.Name + '/' + afi.Name);
}
// If user placed multiple versions of firebug in Addons directory then give error
if (firebugCount > 1)
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0015"));
// Start firefox with the profile that contains all the addons in addon directory
driver = new FirefoxDriver(FfProfile);
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
driver.Manage().Window.Maximize();
if (isBrowserDimendion)
driver.Manage().Window.Size = new System.Drawing.Size(width, height);
driverlist.Add(driver);
}
catch (Exception e)
{
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0009").Replace("{MSG}", e.Message));
}
}
else
{
int webDriverPort = 7055;
FfProfile = new FirefoxProfile();
FfProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
FfProfile.SetPreference("network.cookie.lifetimePolicy", 0);
FfProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
FfProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
SetCommonPreferences();
for (int port = webDriverPort; port <= webDriverPort + 5; port++)
{
//Allowing security exception to appear and being able to handle.
FfProfile.SetPreference("browser.xul.error_pages.expert_bad_cert", true);
FfProfile.AcceptUntrustedCertificates = true;
string profileDir = FfProfile.ProfileDirectory;
FfProfile.Port = port;
driver = new FirefoxDriver(FfProfile);
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
driver.Manage().Window.Maximize();
if (isBrowserDimendion)
driver.Manage().Window.Size = new System.Drawing.Size(width, height);
//.........这里部分代码省略.........
示例11: AddExtension
/// <summary>
/// Adds the Firefox extension collecting JS errors to the profile what allows later use of ReadErrors(WebDriver).
///
/// Example:
///
/// FirefoxProfile profile = new FirefoxProfile();
/// JavaScriptError.AddExtension(profile);
/// IWebDriver driver = new FirefoxDriver(profile);
///
/// </summary>
/// <param name="ffProfile"></param>
/// <param name="xpiDirectory"></param>
public static void AddExtension(FirefoxProfile ffProfile, string xpiDirectory)
{
ffProfile.AddExtension(Path.Combine(xpiDirectory, "JSErrorCollector.xpi"));
}
示例12: initDriver
//.........这里部分代码省略.........
{
fi.CopyTo(Path.Combine(adDirTemp.FullName, fi.Name), true);
}
int firebugCount = 0;
string[] addonFilePaths = Directory.GetFiles(adPath);
ffProfile = new FirefoxProfile();
ffProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
ffProfile.SetPreference("network.cookie.lifetimePolicy", 0);
ffProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
ffProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
// for ff5 support.
ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);
#region Handling Downloading Window.
ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
ffProfile.SetPreference("browser.download.useDownloadDir", true);
ffProfile.SetPreference("browser.download.defaultFolder", Common.Utility.GetParameter("downloadpath"));
ffProfile.SetPreference("browser.download.folderList", 2);
ffProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff");
#endregion
#region Handling Unresponsive Script Warning.
ffProfile.SetPreference("dom.max_script_run_time", 10 * 60);
ffProfile.SetPreference("dom.max_chrome_script_run_time", 10 * 60);
#endregion
//Assigning profile location so that firefox can next time use same profile to open
Common.Utility.SetVariable("FirefoxProfilePath", ffProfile.ProfileDirectory.ToString());
// Add all the addons found in the specified addon directory
foreach (FileInfo afi in adDirTemp.GetFiles())
{
if (afi.Name.ToLower().Contains("firebug"))
firebugCount++;
ffProfile.AddExtension(adDirTemp.Name + '/' + afi.Name);
}
// If user placed multiple versions of firebug in Addons directory then give error
if (firebugCount > 1)
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0015"));
// Start firefox with the profile that contains all the addons in addon directory
driver = new FirefoxDriver(ffProfile);
driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(150));
driver.Manage().Window.Maximize();
if (IsBrowserDimendion)
driver.Manage().Window.Size = new System.Drawing.Size(width, height);
driverlist.Add(driver);
}
catch (Exception e)
{
throw new Exception(Common.Utility.GetCommonMsgVariable("KRYPTONERRCODE0009").Replace("{MSG}", e.Message));
}
}
else
{
int webDriverPort = 7055;
ffProfile = new FirefoxProfile();
ffProfile.SetPreference("webdriver_assume_untrusted_issuer", false);
ffProfile.SetPreference("network.cookie.lifetimePolicy", 0);
ffProfile.SetPreference("privacy.sanitize.sanitizeOnShutdown", false);
ffProfile.SetPreference("privacy.sanitize.promptOnSanitize", false);
ffProfile.SetPreference("extensions.checkCompatibility.5.0", false);//For FF5 version support.
#region Handling Downloading Window.
ffProfile.SetPreference("browser.download.dir", Common.Utility.GetParameter("downloadpath"));
ffProfile.SetPreference("browser.download.useDownloadDir", true);
示例13: BuildFFDriver
private IWebDriver BuildFFDriver()
{
FirefoxProfile ffProfile = new FirefoxProfile();
string xpiPath;
int depth = 0;
do
{
string relative = "";
for (int i = 0; i < depth; i++)
relative += @"..\";
xpiPath = Path.Combine(TestContext.DeploymentDirectory, relative, @"dist\JSErrorCollector.xpi");
depth++;
if (depth > 10)
throw new FileNotFoundException("Could not find JSErrorCollector.xpi after 10 iterations.");
} while (!File.Exists(xpiPath));
ffProfile.AddExtension(xpiPath);
return new FirefoxDriver(ffProfile);
}