Class FirefoxDriver
Provides a way to access Firefox to run tests.
public class FirefoxDriver : WebDriver, IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsElement, ITakesScreenshot, ISupportsPrint, IActionExecutor, IAllowsFileDetection, IHasCapabilities, IHasCommandExecutor, IHasSessionId, ICustomDriverCommandExecutor, IHasVirtualAuthenticator
- Inheritance
-
FirefoxDriver
- Implements
- Inherited Members
- Extension Methods
Examples
[TestFixture]
public class Testing
{
private IWebDriver driver;
[SetUp]
public void SetUp()
{
driver = new FirefoxDriver();
}
[Test]
public void TestGoogle()
{
driver.Navigate().GoToUrl("http://www.google.co.uk");
/*
* Rest of the test
*/
}
[TearDown]
public void TearDown()
{
driver.Quit();
}
}
Remarks
When the FirefoxDriver object has been instantiated the browser will load. The test can then navigate to the URL under test and start your test.
In the case of the FirefoxDriver, you can specify a named profile to be used, or you can let the driver create a temporary, anonymous profile. A custom extension allowing the driver to communicate to the browser will be installed into the profile.
Constructors
FirefoxDriver()
Initializes a new instance of the FirefoxDriver class.
public FirefoxDriver()
FirefoxDriver(FirefoxDriverService)
Initializes a new instance of the FirefoxDriver class using the specified driver service. Uses the Mozilla-provided Marionette driver implementation.
public FirefoxDriver(FirefoxDriverService service)
Parameters
serviceFirefoxDriverServiceThe FirefoxDriverService used to initialize the driver.
Exceptions
- ArgumentNullException
If
serviceis null.
FirefoxDriver(FirefoxDriverService, FirefoxOptions)
Initializes a new instance of the FirefoxDriver class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
Parameters
serviceFirefoxDriverServiceThe FirefoxDriverService to use.
optionsFirefoxOptionsThe FirefoxOptions to be used with the Firefox driver.
Exceptions
- ArgumentNullException
If
serviceoroptionsare null.
FirefoxDriver(FirefoxDriverService, FirefoxOptions, TimeSpan)
Initializes a new instance of the FirefoxDriver class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
Parameters
serviceFirefoxDriverServiceThe FirefoxDriverService to use.
optionsFirefoxOptionsThe FirefoxOptions to be used with the Firefox driver.
commandTimeoutTimeSpanThe maximum amount of time to wait for each command.
Exceptions
- ArgumentNullException
If
serviceoroptionsare null.
FirefoxDriver(FirefoxOptions)
Initializes a new instance of the FirefoxDriver class using the specified options. Uses the Mozilla-provided Marionette driver implementation.
public FirefoxDriver(FirefoxOptions options)
Parameters
optionsFirefoxOptionsThe FirefoxOptions to be used with the Firefox driver.
Exceptions
- ArgumentNullException
If
optionsis null.
FirefoxDriver(string)
Initializes a new instance of the FirefoxDriver class using the specified path
to the directory containing geckodriver.exe.
public FirefoxDriver(string geckoDriverDirectory)
Parameters
geckoDriverDirectorystringThe full path to the directory containing
geckodriver.exe.
FirefoxDriver(string, FirefoxOptions)
Initializes a new instance of the FirefoxDriver class using the specified path
to the directory containing geckodriver.exe and options.
public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options)
Parameters
geckoDriverDirectorystringThe full path to the directory containing
geckodriver.exe.optionsFirefoxOptionsThe FirefoxOptions to be used with the Firefox driver.
Exceptions
- ArgumentNullException
If
optionsis null.
FirefoxDriver(string, FirefoxOptions, TimeSpan)
Initializes a new instance of the FirefoxDriver class using the specified path
to the directory containing geckodriver.exe, options, and command timeout.
public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
Parameters
geckoDriverDirectorystringThe full path to the directory containing
geckodriver.exe.optionsFirefoxOptionsThe FirefoxOptions to be used with the Firefox driver.
commandTimeoutTimeSpanThe maximum amount of time to wait for each command.
Exceptions
- ArgumentNullException
If
optionsis null.
Fields
GetContextCommand
Command for getting the command context of a Firefox driver.
public static readonly string GetContextCommand
Field Value
GetFullPageScreenshotCommand
Command for getting aa full page screenshot from a Firefox driver.
public static readonly string GetFullPageScreenshotCommand
Field Value
InstallAddOnCommand
Command for installing an addon to a Firefox driver.
public static readonly string InstallAddOnCommand
Field Value
SetContextCommand
Command for setting the command context of a Firefox driver.
public static readonly string SetContextCommand
Field Value
UninstallAddOnCommand
Command for uninstalling an addon from a Firefox driver.
public static readonly string UninstallAddOnCommand
Field Value
Properties
CustomCommandDefinitions
Gets a read-only dictionary of the custom WebDriver commands defined for FirefoxDriver. The keys of the dictionary are the names assigned to the command; the values are the CommandInfo objects describing the command behavior.
public static IReadOnlyDictionary<string, CommandInfo> CustomCommandDefinitions { get; }
Property Value
FileDetector
Gets or sets the IFileDetector responsible for detecting sequences of keystrokes representing file paths and names.
public override IFileDetector FileDetector { get; set; }
Property Value
Remarks
The Firefox driver does not allow a file detector to be set, as the server component of the Firefox driver only allows uploads from the local computer environment. Attempting to set this property has no effect, but does not throw an exception. If you are attempting to run the Firefox driver remotely, use RemoteWebDriver in conjunction with a standalone WebDriver server.
Methods
Dispose(bool)
Disposes of the FirefoxDriver and frees all resources.
protected override void Dispose(bool disposing)
Parameters
disposingboolA value indicating whether the user initiated the disposal of the object. Pass true if the user is actively disposing the object; otherwise false.
GetContext()
Gets the command context used when issuing commands to geckodriver.
public FirefoxCommandContext GetContext()
Returns
- FirefoxCommandContext
The context of commands.
Exceptions
- WebDriverException
If response is not recognized
GetFullPageScreenshot()
Gets a Screenshot object representing the image of the full page on the screen.
public Screenshot GetFullPageScreenshot()
Returns
- Screenshot
A Screenshot object containing the image.
InstallAddOn(string, bool)
Installs a Firefox add-on.
public string InstallAddOn(string base64EncodedAddOn, bool temporary = false)
Parameters
base64EncodedAddOnstringThe base64-encoded string representation of the add-on binary.
temporaryboolWhether the add-on is temporary; required for unsigned add-ons.
Returns
- string
The unique identifier of the installed add-on.
Exceptions
- ArgumentNullException
If
base64EncodedAddOnis null or empty.
InstallAddOnFromDirectory(string, bool)
Installs a Firefox add-on from a directory.
public string InstallAddOnFromDirectory(string addOnDirectoryToInstall, bool temporary = false)
Parameters
addOnDirectoryToInstallstringFull path of the directory of the add-on to install.
temporaryboolWhether the add-on is temporary; required for unsigned add-ons.
Returns
- string
The unique identifier of the installed add-on.
Exceptions
- ArgumentNullException
If
addOnDirectoryToInstallis null or empty.- ArgumentException
If the directory at
addOnDirectoryToInstalldoes not exist.
InstallAddOnFromFile(string, bool)
Installs a Firefox add-on from a file, typically a .xpi file.
public string InstallAddOnFromFile(string addOnFileToInstall, bool temporary = false)
Parameters
addOnFileToInstallstringFull path and file name of the add-on to install.
temporaryboolWhether the add-on is temporary; required for unsigned add-ons.
Returns
- string
The unique identifier of the installed add-on.
Exceptions
- ArgumentNullException
If
oraddOnFileToInstallis null or empty.If the file at
addOnFileToInstalldoes not exist.
PrepareEnvironment()
In derived classes, the PrepareEnvironment() method prepares the environment for test execution.
protected virtual void PrepareEnvironment()
SetContext(FirefoxCommandContext)
Sets the command context used when issuing commands to geckodriver.
public void SetContext(FirefoxCommandContext context)
Parameters
contextFirefoxCommandContextThe FirefoxCommandContext value to which to set the context.
UninstallAddOn(string)
Uninstalls a Firefox add-on.
public void UninstallAddOn(string addOnId)
Parameters
addOnIdstringThe ID of the add-on to uninstall.
Exceptions
- ArgumentNullException
If
addOnIdis null or empty.