Class SafariDriver
Provides a way to access Safari to run your tests by creating a SafariDriver instance
public class SafariDriver : WebDriver, IWebDriver, IDisposable, ISearchContext, IJavaScriptExecutor, IFindsElement, ITakesScreenshot, ISupportsPrint, IActionExecutor, IAllowsFileDetection, IHasCapabilities, IHasCommandExecutor, IHasSessionId, ICustomDriverCommandExecutor, IHasVirtualAuthenticator
- Inheritance
-
SafariDriver
- Implements
- Inherited Members
- Extension Methods
Examples
[TestFixture]
public class Testing
{
private IWebDriver driver;
[SetUp]
public void SetUp()
{
driver = new SafariDriver();
}
[Test]
public void TestGoogle()
{
driver.Navigate().GoToUrl("http://www.google.co.uk");
/*
* Rest of the test
*/
}
[TearDown]
public void TearDown()
{
driver.Quit();
driver.Dispose();
}
}
Remarks
When the WebDriver object has been instantiated the browser will load. The test can then navigate to the URL under test and start your test.
Constructors
SafariDriver()
Initializes a new instance of the SafariDriver class.
public SafariDriver()
SafariDriver(SafariDriverService)
Initializes a new instance of the SafariDriver class using the specified driver service.
public SafariDriver(SafariDriverService service)
Parameters
serviceSafariDriverServiceThe SafariDriverService used to initialize the driver.
Exceptions
- ArgumentNullException
If
serviceis null.
SafariDriver(SafariDriverService, SafariOptions)
Initializes a new instance of the SafariDriver class using the specified SafariDriverService and options.
public SafariDriver(SafariDriverService service, SafariOptions options)
Parameters
serviceSafariDriverServiceThe SafariDriverService to use.
optionsSafariOptionsThe SafariOptions used to initialize the driver.
Exceptions
- ArgumentNullException
If
serviceoroptionsare null.
SafariDriver(SafariDriverService, SafariOptions, TimeSpan)
Initializes a new instance of the SafariDriver class using the specified SafariDriverService.
public SafariDriver(SafariDriverService service, SafariOptions options, TimeSpan commandTimeout)
Parameters
serviceSafariDriverServiceThe SafariDriverService to use.
optionsSafariOptionsThe SafariOptions to be used with the Safari driver.
commandTimeoutTimeSpanThe maximum amount of time to wait for each command.
Exceptions
- ArgumentNullException
If
serviceoroptionsare null.
SafariDriver(SafariOptions)
Initializes a new instance of the SafariDriver class using the specified SafariOptions.
public SafariDriver(SafariOptions options)
Parameters
optionsSafariOptionsThe SafariOptions to use for this SafariDriver instance.
Exceptions
- ArgumentNullException
If
optionsis null.
SafariDriver(string)
Initializes a new instance of the SafariDriver class using the specified path
to the directory containing safaridriver.
public SafariDriver(string safariDriverDirectory)
Parameters
safariDriverDirectorystringThe full path to the directory containing SafariDriver executable.
SafariDriver(string, SafariOptions)
Initializes a new instance of the SafariDriver class using the specified path
to the directory containing safaridriver and options.
public SafariDriver(string safariDriverDirectory, SafariOptions options)
Parameters
safariDriverDirectorystringThe full path to the directory containing SafariDriver executable.
optionsSafariOptionsThe SafariOptions to be used with the Safari driver.
Exceptions
- ArgumentNullException
If
optionsis null.
SafariDriver(string, SafariOptions, TimeSpan)
Initializes a new instance of the SafariDriver class using the specified path
to the directory containing safaridriver, options, and command timeout.
public SafariDriver(string safariDriverDirectory, SafariOptions options, TimeSpan commandTimeout)
Parameters
safariDriverDirectorystringThe full path to the directory containing SafariDriver executable.
optionsSafariOptionsThe SafariOptions to be used with the Safari driver.
commandTimeoutTimeSpanThe maximum amount of time to wait for each command.
Exceptions
- ArgumentNullException
If
optionsis null.
Properties
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 Safari driver does not allow a file detector to be set, as the server component of the Safari driver (the Safari extension) 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 Safari driver remotely, use RemoteWebDriver in conjunction with a standalone WebDriver server.
Methods
AttachDebugger()
This opens Safari's Web Inspector. If driver subsequently executes script of "debugger;" the execution will pause, no additional commands will be processed, and the code will time out.
public void AttachDebugger()
GetPermissions()
Returns Each available permission item and whether it is allowed or not.
public object? GetPermissions()
Returns
- object
whether the item is allowed or not.
SetPermission(string, bool)
Set permission of an item on the browser. The only supported permission at this time is "getUserMedia".
public void SetPermission(string permissionName, bool permissionValue)
Parameters
permissionNamestringThe name of the item to set permission on.
permissionValueboolWhether the permission has been granted.