From 8fb8fd791af21772937eeface92da1fe3455a003 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Sun, 27 Nov 2022 19:52:41 -0600 Subject: [PATCH] [dotnet] toggle Selenium Manager execution output on exit code --- dotnet/src/webdriver/SeleniumManager.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/dotnet/src/webdriver/SeleniumManager.cs b/dotnet/src/webdriver/SeleniumManager.cs index 931df06c6390d..edbd023ff3667 100644 --- a/dotnet/src/webdriver/SeleniumManager.cs +++ b/dotnet/src/webdriver/SeleniumManager.cs @@ -60,8 +60,7 @@ public static string DriverPath(string driverName) if (binaryFile == null) return null; var arguments = "--driver " + driverName; - var output = RunCommand(binaryFile, arguments); - return output.Replace("INFO\t", "").TrimEnd(); + return RunCommand(binaryFile, arguments); } /// @@ -117,14 +116,15 @@ private static string RunCommand(string fileName, string arguments) process.StartInfo.RedirectStandardError = true; StringBuilder outputBuilder = new StringBuilder(); - + int processExitCode; + DataReceivedEventHandler outputHandler = (sender, e) => outputBuilder.AppendLine(e.Data); try { process.OutputDataReceived += outputHandler; process.ErrorDataReceived += outputHandler; - + process.Start(); process.BeginOutputReadLine(); @@ -138,17 +138,19 @@ private static string RunCommand(string fileName, string arguments) } finally { + processExitCode = process.ExitCode; process.OutputDataReceived -= outputHandler; process.ErrorDataReceived -= outputHandler; } - string output = outputBuilder.ToString(); + string output = outputBuilder.ToString().Trim(); - if (!output.StartsWith("INFO")) { + if (processExitCode > 0) + { throw new WebDriverException($"Invalid response from process: {fileName} {arguments}\n{output}"); } - return output; + return output.Replace("INFO\t", ""); } } }