-
Notifications
You must be signed in to change notification settings - Fork 130
Advanced Browser Capabilities and Options
Jakub Raczek edited this page Apr 25, 2019
·
5 revisions
In some scenarios, you may require more control over the browser capabilities or browser options you set. You can achieve this by using the CapabilitiesSet event or DriverOptionsSet against the DriverContext.
This event fires after all the capabilities or options have bee read from the configuration file, but before the driver is created. It can be useful for creating runtime dependent capabilities or options.
Method CapabilitiesSet was removed in framework 3.1.8, please use DriverOptionsSet instead.
// SpecFlow example
[Binding]
public class ProjectTestBase : TestBase
{
private readonly ScenarioContext scenarioContext;
private readonly DriverContext driverContext = new DriverContext();
/// <summary>
/// Initializes a new instance of the <see cref="ProjectTestBase"/> class.
/// </summary>
/// <param name="scenarioContext"> Scenario Context </param>
public ProjectTestBase(ScenarioContext scenarioContext)
{
if (scenarioContext == null)
{
throw new ArgumentNullException("scenarioContext");
}
this.scenarioContext = scenarioContext;
this.driverContext.CapabilitiesSet += DriverContext_CapabilitiesSet; ;
}
private void DriverContext_CapabilitiesSet(object sender, CapabilitiesSetEventArgs args)
{
if (args == null || args.Capabilities == null)
{
throw new ArgumentNullException();
}
// Check for an existing capability
if (args.Capabilities.GetCapability("testcapability") != null)
{
// Capability Exists
.... Do something ....
}
else
{
// Add the capability
args.Capabilities.SetCapability("testcapability", ..some value..);
}
}
}
// NUnit example
public class ProjectTestBase : TestBase
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
private readonly DriverContext
driverContext = new DriverContext();
public ProjectTestBase()
{
this.driverContext.CapabilitiesSet += this.DriverContext_CapabilitiesSet;
}
private void DriverContext_CapabilitiesSet(object sender, CapabilitiesSetEventArgs args)
{
if (args == null || args.Capabilities == null)
{
throw new ArgumentNullException();
}
// Check for an existing capability
if (args.Capabilities.GetCapability("testcapability") != null)
{
// Capability Exists
.... Do something ....
}
else
{
// Add the capability
args.Capabilities.SetCapability("testcapability", ..some value..);
}
}
}
// NUnit example
public class ProjectTestBase : TestBase
{
private readonly DriverContext driverContext = new DriverContext();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public ProjectTestBase()
{
this.driverContext.DriverOptionsSet += this.DriverContext_DriverOptionsSet;
}
private void DriverContext_DriverOptionsSet(object sender, DriverOptionsSetEventArgs args)
{
if (args == null || args.DriverOptions == null)
{
throw new ArgumentNullException();
}
args.DriverOptions.SetLoggingPreference("performance", OpenQA.Selenium.LogLevel.All);
args.DriverOptions.SetLoggingPreference(LogType.Browser, OpenQA.Selenium.LogLevel.All);
}
Example can be found here
- Home
- Getting started
- Parallel tests execution
- MsTest DataDriven tests from Xml and CSV files
- NUnit DataDriven tests from Xml, CSV and Excel files
- Comparing files by NUnit DataDriven tests
- Visual Testing
- Screen shots: full desktop, selenium. PageSource saving
- Verify-asserts without stop tests
- Downloading files
- Helpers
- Override browser profile preferences, install browser extensions, Headless mode
- Debugging Test.Automation framework
- Logging
- Performance measures
- Webdriver Extends
- More common locators
- Selenium-Grid-support
- Advanced Browser Capabilities and Options
- AngularJS synchronization
- Update App.config or appsettings.json
- Cross browser parallel test execution with testing-Cloud-Providers\SeleniumGrid
- Verifying Javascript Errors from browser
- Enabling Performance Log for Chrome
- Azure DevOps Support
- Edge browser Support
- Downloading and running Selenium Grid with Powershell
- Run Ocaramba tests with Docker container
- HTTP auth in Internet explorer
- ExtentReports Support