Skip to content

Commit

Permalink
[dotnet] add ability to turn on driver logging in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Aug 14, 2023
1 parent ad49b44 commit 3778d9d
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 15 deletions.
3 changes: 3 additions & 0 deletions dotnet/test/common/Environment/DriverConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public class DriverConfig

[JsonProperty]
public bool AutoStartRemoteServer { get; set; }

[JsonProperty]
public bool Logging { get; set; }
}
}
24 changes: 21 additions & 3 deletions dotnet/test/common/Environment/DriverFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using OpenQA.Selenium.Chromium;

namespace OpenQA.Selenium.Environment
{
Expand Down Expand Up @@ -40,16 +41,17 @@ private void PopulateServiceTypes()

public event EventHandler<DriverStartingEventArgs> DriverStarting;

public IWebDriver CreateDriver(Type driverType)
public IWebDriver CreateDriver(Type driverType, bool logging = false)
{
return CreateDriverWithOptions(driverType, null);
return CreateDriverWithOptions(driverType, null, logging);
}

public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverOptions)
public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverOptions, bool logging = false)
{
Browser browser = Browser.All;
DriverService service = null;
DriverOptions options = null;
bool enableLogging = logging;

List<Type> constructorArgTypeList = new List<Type>();
IWebDriver driver = null;
Expand All @@ -58,24 +60,40 @@ public IWebDriver CreateDriverWithOptions(Type driverType, DriverOptions driverO
browser = Browser.Chrome;
options = GetDriverOptions<ChromeOptions>(driverType, driverOptions);
service = CreateService<ChromeDriverService>();
if (enableLogging)
{
((ChromiumDriverService)service).EnableVerboseLogging = true;
}
}
else if (typeof(EdgeDriver).IsAssignableFrom(driverType))
{
browser = Browser.Edge;
options = GetDriverOptions<EdgeOptions>(driverType, driverOptions);
service = CreateService<EdgeDriverService>();
if (enableLogging)
{
((ChromiumDriverService)service).EnableVerboseLogging = true;
}
}
else if (typeof(InternetExplorerDriver).IsAssignableFrom(driverType))
{
browser = Browser.IE;
options = GetDriverOptions<InternetExplorerOptions>(driverType, driverOptions);
service = CreateService<InternetExplorerDriverService>();
if (enableLogging)
{
((InternetExplorerDriverService)service).LoggingLevel = InternetExplorerDriverLogLevel.Trace;
}
}
else if (typeof(FirefoxDriver).IsAssignableFrom(driverType))
{
browser = Browser.Firefox;
options = GetDriverOptions<FirefoxOptions>(driverType, driverOptions);
service = CreateService<FirefoxDriverService>();
if (enableLogging)
{
((FirefoxDriverService)service).LogLevel = FirefoxDriverLogLevel.Trace;
}
}
else if (typeof(SafariDriver).IsAssignableFrom(driverType))
{
Expand Down
11 changes: 9 additions & 2 deletions dotnet/test/common/Environment/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class EnvironmentManager
private DriverFactory driverFactory;
private RemoteSeleniumServer remoteServer;
private string remoteCapabilities;
private bool logging;

private EnvironmentManager()
{
Expand Down Expand Up @@ -52,6 +53,7 @@ private EnvironmentManager()
driverType = driverAssembly.GetType(driverConfig.DriverTypeName);
browser = driverConfig.BrowserValue;
remoteCapabilities = driverConfig.RemoteCapabilities;
logging = driverConfig.Logging;

urlBuilder = new UrlBuilder(websiteConfig);

Expand Down Expand Up @@ -190,6 +192,11 @@ public string RemoteCapabilities
get { return remoteCapabilities; }
}

public bool Logging
{
get { return logging; }
}

public UrlBuilder UrlBuilder
{
get
Expand All @@ -210,12 +217,12 @@ public IWebDriver GetCurrentDriver()

public IWebDriver CreateDriverInstance()
{
return driverFactory.CreateDriver(driverType);
return driverFactory.CreateDriver(driverType, Logging);
}

public IWebDriver CreateDriverInstance(DriverOptions options)
{
return driverFactory.CreateDriverWithOptions(driverType, options);
return driverFactory.CreateDriverWithOptions(driverType, options, Logging);
}

public IWebDriver CreateFreshDriver()
Expand Down
30 changes: 20 additions & 10 deletions dotnet/test/common/appconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,71 +27,81 @@
"DriverTypeName": "OpenQA.Selenium.Chrome.StableChannelChromeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Chrome",
"RemoteCapabilities": "chrome"
"RemoteCapabilities": "chrome",
"Logging": false
},

"ChromeDev": {
"DriverTypeName": "OpenQA.Selenium.Chrome.DevChannelChromeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Chrome",
"RemoteCapabilities": "chrome"
"RemoteCapabilities": "chrome",
"Logging": false
},

"EdgeIEMode": {
"DriverTypeName": "OpenQA.Selenium.IE.EdgeInternetExplorerModeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "IE",
"RemoteCapabilities": "internet explorer"
"RemoteCapabilities": "internet explorer",
"Logging": false
},

"Edge": {
"DriverTypeName": "OpenQA.Selenium.Edge.StableChannelEdgeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Edge",
"RemoteCapabilities": "MicrosoftEdge"
"RemoteCapabilities": "MicrosoftEdge",
"Logging": false
},

"EdgeDev": {
"DriverTypeName": "OpenQA.Selenium.Edge.DevChannelEdgeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Edge",
"RemoteCapabilities": "MicrosoftEdge"
"RemoteCapabilities": "MicrosoftEdge",
"Logging": false
},

"Firefox": {
"DriverTypeName": "OpenQA.Selenium.Firefox.StableChannelFirefoxDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Firefox",
"RemoteCapabilities": "firefox"
"RemoteCapabilities": "firefox",
"Logging": false
},

"FirefoxNightly": {
"DriverTypeName": "OpenQA.Selenium.Firefox.NightlyChannelFirefoxDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Firefox",
"RemoteCapabilities": "firefox"
"RemoteCapabilities": "firefox",
"Logging": false
},

"Safari": {
"DriverTypeName": "OpenQA.Selenium.Safari.DefaultSafariDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Safari",
"RemoteCapabilities": "safari"
"RemoteCapabilities": "safari",
"Logging": false
},

"SafariTechPreview": {
"DriverTypeName": "OpenQA.Selenium.Safari.SafariTechnologyPreviewDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Safari",
"RemoteCapabilities": "safari"
"RemoteCapabilities": "safari",
"Logging": false
},

"Remote": {
"DriverTypeName": "OpenQA.Selenium.Remote.StableChannelRemoteChromeDriver",
"AssemblyName": "WebDriver.Common.Tests",
"BrowserValue": "Remote",
"RemoteCapabilities": "chrome",
"AutoStartRemoteServer": true
"AutoStartRemoteServer": true,
"Logging": false
}
}
}

0 comments on commit 3778d9d

Please sign in to comment.