Skip to content

Commit b6f9af3

Browse files
committed
[dotnet] Using json output with Seleniun Manager
Work done for #11365
1 parent 5d26500 commit b6f9af3

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
using System;
2020
using System.Collections.Generic;
2121
using System.Diagnostics;
22+
using Newtonsoft.Json;
23+
using OpenQA.Selenium.Internal;
2224

2325
#if !NET45 && !NET46 && !NET47
2426
using System.Runtime.InteropServices;
@@ -59,7 +61,7 @@ public static string DriverPath(string driverName)
5961
var binaryFile = Binary;
6062
if (binaryFile == null) return null;
6163

62-
var arguments = "--driver " + driverName;
64+
var arguments = "--driver " + driverName + " --output json";
6365
return RunCommand(binaryFile, arguments);
6466
}
6567

@@ -144,13 +146,26 @@ private static string RunCommand(string fileName, string arguments)
144146
}
145147

146148
string output = outputBuilder.ToString().Trim();
149+
string result = "";
150+
try
151+
{
152+
Dictionary<string, object> deserializedOutput = JsonConvert.DeserializeObject<Dictionary<string, object>>(output, new ResponseValueJsonConverter());
153+
Dictionary<string, object> deserializedResult = deserializedOutput["result"] as Dictionary<string, object>;
154+
result = deserializedResult["message"] as string;
155+
}
156+
catch (Exception ex)
157+
{
158+
throw new WebDriverException($"Error deserializing Selenium Manager's response: {output}", ex);
159+
}
160+
161+
// We do not log any warnings coming from Selenium Manager like the other bindings as we don't have any logging in the .NET bindings
147162

148163
if (processExitCode != 0)
149164
{
150-
throw new WebDriverException($"Invalid response from process (code {processExitCode}): {fileName} {arguments}\n{output}");
165+
throw new WebDriverException($"Invalid response from process (code {processExitCode}): {fileName} {arguments}\n{result}");
151166
}
152167

153-
return output.Replace("INFO\t", "");
168+
return result;
154169
}
155170
}
156171
}

0 commit comments

Comments
 (0)