Skip to content

Commit

Permalink
[dotnet] toggle Selenium Manager execution output on exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Nov 29, 2022
1 parent d2838e1 commit 8fb8fd7
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions dotnet/src/webdriver/SeleniumManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down Expand Up @@ -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();
Expand All @@ -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", "");
}
}
}

0 comments on commit 8fb8fd7

Please sign in to comment.