G4.Abstraction.WebDriver provides an abstraction layer for creating WebDriver instances with configurable parameters. This library allows developers to initialize WebDriver instances with options for command timeouts, driver types, binary paths (local file path or grid endpoint), service configurations, and driver capabilities. It simplifies the setup process for automated browser interactions in remote or local environments.
To install G4.Abstraction, add the NuGet package:
dotnet add package G4.Abstraction.WebDriver
- Driver Creation Abstraction: Simplifies the process of creating WebDriver instances with custom configuration.
- Plugin-Based Driver Management: Supports adding custom driver plugins to extend functionality.
- Service Configuration: Supports service parameters for additional customization.
- Serialization Options: Uses camel-case naming for JSON serialization and deserialization.
- Remote and Local Driver Support: Detects if drivers are local (using a file path) or remote (using a grid endpoint URL).
In this example, the driverBinaries
path points to a local file path where the driver binary (e.g., MicrosoftEdgeDriver.exe
) is located. This configuration is suitable for running WebDriver instances on the local machine.
using G4.Abstraction;
var driverParams = new Dictionary<string, object>
{
{ "driver", "MicrosoftEdgeDriver" },
{ "commandTimeout", 60000 },
{ "driverBinaries", @"C:\path\to\MicrosoftEdgeDriver.exe" }, // Local file path
{ "capabilities", new CapabilitiesModel
{
AlwaysMatch = new Dictionary<string, object>
{
{ "browserName", "MicrosoftEdge" },
{ "platformName", "Windows 10" }
},
FirstMatch = new List<Dictionary<string, object>>
{
new Dictionary<string, object> { { "browserVersion", "latest" } }
}
}
}
};
var driverFactory = new DriverFactory(driverParams);
var webDriver = driverFactory.NewDriver();
For remote setups, the driverBinaries
parameter points to a grid endpoint URL (e.g., Selenium Grid or BrowserStack), which allows running tests on remote browsers. This configuration is useful for distributed testing across different platforms.
using G4.Abstraction;
var driverParams = new Dictionary<string, object>
{
{ "driver", "MicrosoftEdgeDriver" },
{ "commandTimeout", 60000 },
{ "driverBinaries", "http://localhost:4444/wd/hub" }, // Grid endpoint URL
{ "capabilities", new CapabilitiesModel
{
AlwaysMatch = new Dictionary<string, object>
{
{ "browserName", "MicrosoftEdge" },
{ "platformName", "Windows 10" }
},
FirstMatch = new List<Dictionary<string, object>>
{
new Dictionary<string, object> { { "browserVersion", "latest" } },
new Dictionary<string, object> { { "headless", true } }
}
}
}
};
var driverFactory = new DriverFactory(driverParams);
var webDriver = driverFactory.NewDriver();
- Service Parameter Integration: Future versions will include support for service parameters during the initialization of new driver instances.
The DriverFactory
includes detailed error handling. If the specified driver or initialization method is not found, a NotImplementedException
or MissingMethodException
is thrown with a detailed error message.
This library is released under the Apache License 2.0.