Skip to content

Commit 4134f70

Browse files
[dotnet] Do not warn when passing in null driver paths to driver service (#15328)
* [dotnet] Do not warn when passing in null driver paths to driver service * Clarify functionality of CreateDriverService * fix XML comment for `EdgeDriverService`
1 parent 622f761 commit 4134f70

File tree

5 files changed

+51
-41
lines changed

5 files changed

+51
-41
lines changed

dotnet/src/webdriver/Chrome/ChromeDriverService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,22 @@ public static ChromeDriverService CreateDefaultService()
6363
/// </summary>
6464
/// <param name="driverPath">The path to the executable or the directory containing the ChromeDriver executable.</param>
6565
/// <returns>A ChromeDriverService using a random port.</returns>
66-
public static ChromeDriverService CreateDefaultService(string driverPath)
66+
public static ChromeDriverService CreateDefaultService(string? driverPath)
6767
{
68-
string fileName;
6968
if (File.Exists(driverPath))
7069
{
71-
fileName = Path.GetFileName(driverPath);
72-
driverPath = Path.GetDirectoryName(driverPath)!;
70+
string fileName = Path.GetFileName(driverPath);
71+
string driverFolder = Path.GetDirectoryName(driverPath)!;
72+
73+
return CreateDefaultService(driverFolder, fileName);
7374
}
7475
else
7576
{
76-
fileName = ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName);
77-
}
77+
string fileName = ChromiumDriverServiceFileName(DefaultChromeDriverServiceExecutableName);
78+
string? driverFolder = driverPath;
7879

79-
return CreateDefaultService(driverPath, fileName);
80+
return CreateDefaultService(driverFolder, fileName);
81+
}
8082
}
8183

8284
/// <summary>
@@ -85,7 +87,7 @@ public static ChromeDriverService CreateDefaultService(string driverPath)
8587
/// <param name="driverPath">The directory containing the ChromeDriver executable.</param>
8688
/// <param name="driverExecutableFileName">The name of the ChromeDriver executable file.</param>
8789
/// <returns>A ChromeDriverService using a random port.</returns>
88-
public static ChromeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
90+
public static ChromeDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName)
8991
{
9092
return new ChromeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
9193
}

dotnet/src/webdriver/Edge/EdgeDriverService.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,24 @@ public static EdgeDriverService CreateDefaultService()
7272
/// <summary>
7373
/// Creates a default instance of the EdgeDriverService using a specified path to the EdgeDriver executable.
7474
/// </summary>
75-
/// <param name="driverPath">The directory containing the EdgeDriver executable.</param>
75+
/// <param name="driverPath">The path to the executable or the directory containing the EdgeDriver executable.</param>
7676
/// <returns>An EdgeDriverService using a random port.</returns>
77-
public static EdgeDriverService CreateDefaultService(string driverPath)
77+
public static EdgeDriverService CreateDefaultService(string? driverPath)
7878
{
79-
string fileName;
8079
if (File.Exists(driverPath))
8180
{
82-
fileName = Path.GetFileName(driverPath);
83-
driverPath = Path.GetDirectoryName(driverPath)!;
81+
string fileName = Path.GetFileName(driverPath);
82+
string driverFolder = Path.GetDirectoryName(driverPath)!;
83+
84+
return CreateDefaultService(driverFolder, fileName);
8485
}
8586
else
8687
{
87-
fileName = ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName);
88-
}
88+
string fileName = ChromiumDriverServiceFileName(MSEdgeDriverServiceFileName);
89+
string? driverFolder = driverPath;
8990

90-
return CreateDefaultService(driverPath, fileName);
91+
return CreateDefaultService(driverFolder, fileName);
92+
}
9193
}
9294

9395
/// <summary>
@@ -96,7 +98,7 @@ public static EdgeDriverService CreateDefaultService(string driverPath)
9698
/// <param name="driverPath">The directory containing the EdgeDriver executable.</param>
9799
/// <param name="driverExecutableFileName">The name of the EdgeDriver executable file.</param>
98100
/// <returns>A EdgeDriverService using a random port.</returns>
99-
public static EdgeDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
101+
public static EdgeDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName)
100102
{
101103
return new EdgeDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
102104
}

dotnet/src/webdriver/Firefox/FirefoxDriverService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,22 @@ public static FirefoxDriverService CreateDefaultService()
194194
/// </summary>
195195
/// <param name="driverPath">The path to the executable or the directory containing the Firefox driver executable.</param>
196196
/// <returns>A FirefoxDriverService using a random port.</returns>
197-
public static FirefoxDriverService CreateDefaultService(string driverPath)
197+
public static FirefoxDriverService CreateDefaultService(string? driverPath)
198198
{
199-
string fileName;
200199
if (File.Exists(driverPath))
201200
{
202-
fileName = Path.GetFileName(driverPath);
203-
driverPath = Path.GetDirectoryName(driverPath)!;
201+
string fileName = Path.GetFileName(driverPath);
202+
string driverFolder = Path.GetDirectoryName(driverPath)!;
203+
204+
return CreateDefaultService(driverFolder, fileName);
204205
}
205206
else
206207
{
207-
fileName = FirefoxDriverServiceFileName();
208-
}
208+
string fileName = FirefoxDriverServiceFileName();
209+
string? driverFolder = driverPath;
209210

210-
return CreateDefaultService(driverPath, fileName);
211+
return CreateDefaultService(driverFolder, fileName);
212+
}
211213
}
212214

213215
/// <summary>
@@ -216,7 +218,7 @@ public static FirefoxDriverService CreateDefaultService(string driverPath)
216218
/// <param name="driverPath">The directory containing the Firefox driver executable.</param>
217219
/// <param name="driverExecutableFileName">The name of the Firefox driver executable file.</param>
218220
/// <returns>A FirefoxDriverService using a random port.</returns>
219-
public static FirefoxDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
221+
public static FirefoxDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName)
220222
{
221223
return new FirefoxDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
222224
}

dotnet/src/webdriver/IE/InternetExplorerDriverService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,22 @@ public static InternetExplorerDriverService CreateDefaultService()
138138
/// </summary>
139139
/// <param name="driverPath">The path to the executable or the directory containing the <c>IEDriverServer</c> executable.</param>
140140
/// <returns>A InternetExplorerDriverService using a random port.</returns>
141-
public static InternetExplorerDriverService CreateDefaultService(string driverPath)
141+
public static InternetExplorerDriverService CreateDefaultService(string? driverPath)
142142
{
143-
string fileName;
144143
if (File.Exists(driverPath))
145144
{
146-
fileName = Path.GetFileName(driverPath);
147-
driverPath = Path.GetDirectoryName(driverPath)!;
145+
string fileName = Path.GetFileName(driverPath);
146+
string driverFolder = Path.GetDirectoryName(driverPath)!;
147+
148+
return CreateDefaultService(driverFolder, fileName);
148149
}
149150
else
150151
{
151-
fileName = InternetExplorerDriverServiceFileName;
152-
}
152+
string fileName = InternetExplorerDriverServiceFileName;
153+
string? driverFolder = driverPath;
153154

154-
return CreateDefaultService(driverPath, fileName);
155+
return CreateDefaultService(driverFolder, fileName);
156+
}
155157
}
156158

157159
/// <summary>
@@ -160,7 +162,7 @@ public static InternetExplorerDriverService CreateDefaultService(string driverPa
160162
/// <param name="driverPath">The directory containing the <c>IEDriverServer</c> executable.</param>
161163
/// <param name="driverExecutableFileName">The name of the <c>IEDriverServer</c> executable file.</param>
162164
/// <returns>A InternetExplorerDriverService using a random port.</returns>
163-
public static InternetExplorerDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
165+
public static InternetExplorerDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName)
164166
{
165167
return new InternetExplorerDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
166168
}

dotnet/src/webdriver/Safari/SafariDriverService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,22 @@ public static SafariDriverService CreateDefaultService()
103103
/// </summary>
104104
/// <param name="driverPath">The path to the executable or the directory containing the SafariDriver executable.</param>
105105
/// <returns>A SafariDriverService using a random port.</returns>
106-
public static SafariDriverService CreateDefaultService(string driverPath)
106+
public static SafariDriverService CreateDefaultService(string? driverPath)
107107
{
108-
string fileName;
109108
if (File.Exists(driverPath))
110109
{
111-
fileName = Path.GetFileName(driverPath);
112-
driverPath = Path.GetDirectoryName(driverPath)!;
110+
string fileName = Path.GetFileName(driverPath);
111+
string driverFolder = Path.GetDirectoryName(driverPath)!;
112+
113+
return CreateDefaultService(driverFolder, fileName);
113114
}
114115
else
115116
{
116-
fileName = DefaultSafariDriverServiceExecutableName;
117-
}
117+
string fileName = DefaultSafariDriverServiceExecutableName;
118+
string? driverFolder = driverPath;
118119

119-
return CreateDefaultService(driverPath, fileName);
120+
return CreateDefaultService(driverFolder, fileName);
121+
}
120122
}
121123

122124
/// <summary>
@@ -125,7 +127,7 @@ public static SafariDriverService CreateDefaultService(string driverPath)
125127
/// <param name="driverPath">The directory containing the SafariDriver executable.</param>
126128
/// <param name="driverExecutableFileName">The name of the SafariDriver executable file.</param>
127129
/// <returns>A SafariDriverService using a random port.</returns>
128-
public static SafariDriverService CreateDefaultService(string driverPath, string driverExecutableFileName)
130+
public static SafariDriverService CreateDefaultService(string? driverPath, string? driverExecutableFileName)
129131
{
130132
return new SafariDriverService(driverPath, driverExecutableFileName, PortUtilities.FindFreePort());
131133
}

0 commit comments

Comments
 (0)