Skip to content

Commit e86c3cf

Browse files
titusfortnerdiemol
andauthored
[dotnet] add browser output from selenium manager to options (#12405)
* [dotnet] add browser output from selenium manager to options * [dotnet] get tests passing by switching back to V114 since that is what is on CI --------- Co-authored-by: Diego Molina <[email protected]>
1 parent fa1506f commit e86c3cf

11 files changed

Lines changed: 167 additions & 157 deletions

dotnet/src/webdriver/Chromium/ChromiumOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private string LoggingPreferencesChromeOption
105105
/// <summary>
106106
/// Gets or sets the location of the Chromium browser's binary executable file.
107107
/// </summary>
108-
public string BinaryLocation
108+
public override string BinaryLocation
109109
{
110110
get { return this.binaryLocation; }
111111
set { this.binaryLocation = value; }

dotnet/src/webdriver/DriverOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@ public bool UseStrictFileInteractability
208208
set { this.useStrictFileInteractability = value; }
209209
}
210210

211+
/// <summary>
212+
/// Set or Get the location of the browser
213+
/// Override in subclass
214+
/// </summary>
215+
public virtual string BinaryLocation
216+
{
217+
get { return null; }
218+
set { throw new NotImplementedException(); }
219+
}
220+
211221
/// <summary>
212222
/// Provides a means to add additional capabilities not yet added as type safe options
213223
/// for the specific browser driver.

dotnet/src/webdriver/Firefox/FirefoxOptions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ public FirefoxProfile Profile
101101
set { this.profile = value; }
102102
}
103103

104+
/// <summary>
105+
/// Gets or sets the path and file name of the Firefox browser executable.
106+
/// </summary>
107+
public override string BinaryLocation
108+
{
109+
get { return this.browserBinaryLocation; }
110+
set { this.browserBinaryLocation = value; }
111+
}
112+
104113
/// <summary>
105114
/// Gets or sets the path and file name of the Firefox browser executable.
106115
/// </summary>

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static string DriverPath(DriverOptions options)
9797
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-version {0}", options.BrowserVersion);
9898
}
9999

100-
string browserBinary = BrowserBinary(options);
100+
string browserBinary = options.BinaryLocation;
101101
if (!string.IsNullOrEmpty(browserBinary))
102102
{
103103
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --browser-path \"{0}\"", browserBinary);
@@ -112,31 +112,23 @@ public static string DriverPath(DriverOptions options)
112112
}
113113
}
114114

115-
return RunCommand(binaryFullPath, argsBuilder.ToString());
116-
}
117-
115+
Dictionary<string, object> output = RunCommand(binaryFullPath, argsBuilder.ToString());
116+
string browserPath = (string)output["browser_path"];
117+
string driverPath = (string)output["driver_path"];
118118

119-
/// <summary>
120-
/// Extracts the browser binary location from the vendor options when present. Only Chrome, Firefox, and Edge.
121-
/// </summary>
122-
private static string BrowserBinary(DriverOptions options)
123-
{
124-
ICapabilities capabilities = options.ToCapabilities();
125-
string[] vendorOptionsCapabilities = { "moz:firefoxOptions", "goog:chromeOptions", "ms:edgeOptions" };
126-
foreach (string vendorOptionsCapability in vendorOptionsCapabilities)
119+
try
127120
{
128-
IDictionary<string, object> vendorOptions = capabilities.GetCapability(vendorOptionsCapability) as IDictionary<string, object>;
129-
130-
if (vendorOptions != null && vendorOptions.TryGetValue("binary", out object browserBinaryPath))
131-
{
132-
return browserBinaryPath as string;
133-
}
121+
options.BinaryLocation = browserPath;
122+
options.BrowserVersion = null;
123+
}
124+
catch (NotImplementedException e)
125+
{
126+
// Cannot set Browser Location for this driver and that is ok
134127
}
135128

136-
return null;
129+
return driverPath;
137130
}
138131

139-
140132
/// <summary>
141133
/// Executes a process with the given arguments.
142134
/// </summary>
@@ -145,7 +137,7 @@ private static string BrowserBinary(DriverOptions options)
145137
/// <returns>
146138
/// the standard output of the execution.
147139
/// </returns>
148-
private static string RunCommand(string fileName, string arguments)
140+
private static Dictionary<string, object> RunCommand(string fileName, string arguments)
149141
{
150142
Process process = new Process();
151143
process.StartInfo.FileName = binaryFullPath;
@@ -187,12 +179,11 @@ private static string RunCommand(string fileName, string arguments)
187179
}
188180

189181
string output = outputBuilder.ToString().Trim();
190-
string result;
182+
Dictionary<string, object> result;
191183
try
192184
{
193185
Dictionary<string, object> deserializedOutput = JsonConvert.DeserializeObject<Dictionary<string, object>>(output, new ResponseValueJsonConverter());
194-
Dictionary<string, object> deserializedResult = deserializedOutput["result"] as Dictionary<string, object>;
195-
result = deserializedResult["message"] as string;
186+
result = deserializedOutput["result"] as Dictionary<string, object>;
196187
}
197188
catch (Exception ex)
198189
{

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<V115.DevToolsSessionDomains>();
21+
var domains = session.GetVersionSpecificDomains<V114.DevToolsSessionDomains>();
2222
string consoleMessage = "Hello Selenium";
2323

2424
ManualResetEventSlim sync = new ManualResetEventSlim(false);
25-
EventHandler<V115.Console.MessageAddedEventArgs> messageAddedHandler = (sender, e) =>
25+
EventHandler<V114.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<V115.DevToolsSessionDomains>();
22+
var domains = session.GetVersionSpecificDomains<V114.DevToolsSessionDomains>();
2323
ManualResetEventSlim sync = new ManualResetEventSlim(false);
24-
EventHandler<V115.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
24+
EventHandler<V114.Log.EntryAddedEventArgs> entryAddedHandler = (sender, e) =>
2525
{
2626
Assert.That(e.Entry.Text.Contains("404"));
27-
Assert.That(e.Entry.Level == V115.Log.LogEntryLevelValues.Error);
27+
Assert.That(e.Entry.Level == V114.Log.LogEntryLevelValues.Error);
2828
sync.Set();
2929
};
3030

0 commit comments

Comments
 (0)