Skip to content

Commit 0ea5e3e

Browse files
authored
[dotnet] Capture error output from selenium manager (#11320)
* Capture error output from selenium manager * Revert DriverService back to hide exceptions
1 parent 854dd5f commit 0ea5e3e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
using System.Runtime.InteropServices;
2525
#endif
2626

27+
using System.Text;
28+
2729
namespace OpenQA.Selenium
2830
{
2931
/// <summary>
@@ -112,22 +114,38 @@ private static string RunCommand(string fileName, string arguments)
112114
process.StartInfo.Arguments = arguments;
113115
process.StartInfo.UseShellExecute = false;
114116
process.StartInfo.RedirectStandardOutput = true;
117+
process.StartInfo.RedirectStandardError = true;
115118

116-
string output;
119+
StringBuilder outputBuilder = new StringBuilder();
120+
121+
DataReceivedEventHandler outputHandler = (sender, e) => outputBuilder.AppendLine(e.Data);
117122

118123
try
119124
{
125+
process.OutputDataReceived += outputHandler;
126+
process.ErrorDataReceived += outputHandler;
127+
120128
process.Start();
121-
output = process.StandardOutput.ReadToEnd();
129+
130+
process.BeginOutputReadLine();
131+
process.BeginErrorReadLine();
132+
122133
process.WaitForExit();
123134
}
124135
catch (Exception ex)
125136
{
126137
throw new WebDriverException($"Error starting process: {fileName} {arguments}", ex);
127138
}
139+
finally
140+
{
141+
process.OutputDataReceived -= outputHandler;
142+
process.ErrorDataReceived -= outputHandler;
143+
}
144+
145+
string output = outputBuilder.ToString();
128146

129147
if (!output.StartsWith("INFO")) {
130-
throw new WebDriverException($"Invalid response from process: {fileName} {arguments}");
148+
throw new WebDriverException($"Invalid response from process: {fileName} {arguments}\n{output}");
131149
}
132150

133151
return output;

0 commit comments

Comments
 (0)