Skip to content

Commit 0dbec9d

Browse files
authored
Putting the logic to verify driver service path in a single place (#11992)
* [dotnet] Putting the logic to verify driver service path in a single place * Moving tests to CDP 113 * Simplifying DriverFinder code
1 parent 000cb08 commit 0dbec9d

11 files changed

Lines changed: 142 additions & 168 deletions

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using System;
2020
using System.Collections.Generic;
2121
using System.Collections.ObjectModel;
22-
using System.IO;
2322
using OpenQA.Selenium.DevTools;
2423
using OpenQA.Selenium.Remote;
2524

@@ -126,7 +125,7 @@ public class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
126125
/// <param name="options">The <see cref="ChromiumOptions"/> to be used with the ChromiumDriver.</param>
127126
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
128127
protected ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
129-
: base(new DriverServiceCommandExecutor(VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
128+
: base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
130129
{
131130
this.optionsCapabilityName = options.CapabilityName;
132131
}
@@ -432,15 +431,6 @@ protected override void Dispose(bool disposing)
432431
base.Dispose(disposing);
433432
}
434433

435-
private static ChromiumDriverService VerifyDriverServicePath(ChromiumDriverService service, ChromiumOptions options)
436-
{
437-
string driverFullPath = DriverFinder.GetPath(service, options);
438-
service.DriverServicePath = Path.GetDirectoryName(driverFullPath);
439-
service.DriverServiceExecutableName = Path.GetFileName(driverFullPath);
440-
441-
return service;
442-
}
443-
444434
private static ICapabilities ConvertOptionsToCapabilities(ChromiumOptions options)
445435
{
446436
if (options == null)

dotnet/src/webdriver/DriverFinder.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ public static class DriverFinder
3333
/// <param name="service">DriverService with the current path.</param>
3434
/// <param name="options">DriverOptions with the current browser options.</param>
3535
/// <returns>
36-
/// The path of the driver.
36+
/// The service with a verified driver executable path.
3737
/// </returns>
38-
public static string GetPath(DriverService service, DriverOptions options)
38+
public static DriverService VerifyDriverServicePath(DriverService service, DriverOptions options)
3939
{
4040
string executablePath = Path.Combine(service.DriverServicePath, service.DriverServiceExecutableName);
41-
if (File.Exists(executablePath)) return executablePath;
41+
if (File.Exists(executablePath)) return service;
4242
try
4343
{
44-
return SeleniumManager.DriverPath(options);
44+
string driverFullPath = SeleniumManager.DriverPath(options);
45+
service.DriverServicePath = Path.GetDirectoryName(driverFullPath);
46+
service.DriverServiceExecutableName = Path.GetFileName(driverFullPath);
47+
return service;
4548
}
4649
catch (Exception e)
4750
{

dotnet/src/webdriver/Firefox/FirefoxDriver.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
186186
/// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
187187
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
188188
public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
189-
: base(new DriverServiceCommandExecutor(VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
189+
: base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
190190
{
191191
// Add the custom commands unique to Firefox
192192
this.AddCustomFirefoxCommands();
@@ -439,15 +439,6 @@ private static FirefoxDriverService CreateService(FirefoxOptions options)
439439
return FirefoxDriverService.CreateDefaultService();
440440
}
441441

442-
private static FirefoxDriverService VerifyDriverServicePath(FirefoxDriverService service, FirefoxOptions options)
443-
{
444-
string driverFullPath = DriverFinder.GetPath(service, options);
445-
service.DriverServicePath = Path.GetDirectoryName(driverFullPath);
446-
service.DriverServiceExecutableName = Path.GetFileName(driverFullPath);
447-
448-
return service;
449-
}
450-
451442
private void AddCustomFirefoxCommands()
452443
{
453444
foreach (KeyValuePair<string, CommandInfo> entry in CustomCommandDefinitions)

dotnet/src/webdriver/IE/InternetExplorerDriver.cs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
// </copyright>
1818

1919
using System;
20-
using System.IO;
2120
using OpenQA.Selenium.Remote;
2221

2322
namespace OpenQA.Selenium.IE
@@ -141,7 +140,7 @@ public InternetExplorerDriver(InternetExplorerDriverService service, InternetExp
141140
/// <param name="options">The <see cref="InternetExplorerOptions"/> used to initialize the driver.</param>
142141
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
143142
public InternetExplorerDriver(InternetExplorerDriverService service, InternetExplorerOptions options, TimeSpan commandTimeout)
144-
: base(new DriverServiceCommandExecutor(VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
143+
: base(new DriverServiceCommandExecutor(DriverFinder.VerifyDriverServicePath(service, options), commandTimeout), ConvertOptionsToCapabilities(options))
145144
{
146145
}
147146

@@ -161,15 +160,6 @@ public override IFileDetector FileDetector
161160
set { }
162161
}
163162

164-
private static InternetExplorerDriverService VerifyDriverServicePath(InternetExplorerDriverService service, InternetExplorerOptions options)
165-
{
166-
string driverFullPath = DriverFinder.GetPath(service, options);
167-
service.DriverServicePath = Path.GetDirectoryName(driverFullPath);
168-
service.DriverServiceExecutableName = Path.GetFileName(driverFullPath);
169-
170-
return service;
171-
}
172-
173163
private static ICapabilities ConvertOptionsToCapabilities(InternetExplorerOptions options)
174164
{
175165
if (options == null)

dotnet/test/common/DevTools/DevToolsConsoleTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public class DevToolsConsoleTest : DevToolsTestFixture
1818
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
1919
public async Task VerifyMessageAdded()
2020
{
21-
var domains = session.GetVersionSpecificDomains<V112.DevToolsSessionDomains>();
21+
var domains = session.GetVersionSpecificDomains<V113.DevToolsSessionDomains>();
2222
string consoleMessage = "Hello Selenium";
2323

2424
ManualResetEventSlim sync = new ManualResetEventSlim(false);
25-
EventHandler<V112.Console.MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
25+
EventHandler<V113.Console.MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
2626
{
2727
Assert.That(e.Message.Text, Is.EqualTo(consoleMessage));
2828
sync.Set();

dotnet/test/common/DevTools/DevToolsLogTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ public class DevToolsLogTest : DevToolsTestFixture
1919
[IgnoreBrowser(Selenium.Browser.Safari, "Safari does not support Chrome DevTools Protocol")]
2020
public async Task VerifyEntryAddedAndClearLog()
2121
{
22-
var domains = session.GetVersionSpecificDomains<V112.DevToolsSessionDomains>();
22+
var domains = session.GetVersionSpecificDomains<V113.DevToolsSessionDomains>();
2323
ManualResetEventSlim sync = new ManualResetEventSlim(false);
24-
EventHandler<V112.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
24+
EventHandler<V113.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
2525
{
2626
Assert.That(e.Entry.Text.Contains("404"));
27-
Assert.That(e.Entry.Level == V112.Log.LogEntryLevelValues.Error);
27+
Assert.That(e.Entry.Level == V113.Log.LogEntryLevelValues.Error);
2828
sync.Set();
2929
};
3030

0 commit comments

Comments
 (0)