Skip to content

Commit c8814ae

Browse files
nvborisenkodiemol
andauthored
[dotnet] Show output from selenium manager error stream (#12677)
Show output from selenium manager error stream Co-authored-by: Diego Molina <[email protected]>
1 parent 0178bb1 commit c8814ae

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

dotnet/src/webdriver/SeleniumManager.cs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,12 @@ public static string DriverPath(DriverOptions options)
9292

9393
if (options.Proxy != null)
9494
{
95-
if (options.Proxy.SslProxy != null) {
95+
if (options.Proxy.SslProxy != null)
96+
{
9697
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --proxy \"{0}\"", options.Proxy.SslProxy);
97-
} else if (options.Proxy.HttpProxy != null) {
98+
}
99+
else if (options.Proxy.HttpProxy != null)
100+
{
98101
argsBuilder.AppendFormat(CultureInfo.InvariantCulture, " --proxy \"{0}\"", options.Proxy.HttpProxy);
99102
}
100103
}
@@ -137,24 +140,46 @@ private static Dictionary<string, object> RunCommand(string fileName, string arg
137140
process.StartInfo.RedirectStandardError = true;
138141

139142
StringBuilder outputBuilder = new StringBuilder();
143+
StringBuilder errorOutputBuilder = new StringBuilder();
140144

141145
DataReceivedEventHandler outputHandler = (sender, e) => outputBuilder.AppendLine(e.Data);
146+
DataReceivedEventHandler errorOutputHandler = (sender, e) => errorOutputBuilder.AppendLine(e.Data);
142147

143148
try
144149
{
145150
process.OutputDataReceived += outputHandler;
151+
process.ErrorDataReceived += errorOutputHandler;
146152

147153
process.Start();
148154

149155
process.BeginOutputReadLine();
156+
process.BeginErrorReadLine();
150157

151158
process.WaitForExit();
152159

153160
if (process.ExitCode != 0)
154161
{
155162
// 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
156163

157-
throw new WebDriverException($"Selenium Manager process exited abnormally with {process.ExitCode} code: {fileName} {arguments}\n{outputBuilder}");
164+
var exceptionMessageBuilder = new StringBuilder($"Selenium Manager process exited abnormally with {process.ExitCode} code: {fileName} {arguments}");
165+
166+
if (!string.IsNullOrEmpty(errorOutputBuilder.ToString()))
167+
{
168+
exceptionMessageBuilder.AppendLine();
169+
exceptionMessageBuilder.Append("Error Output >>");
170+
exceptionMessageBuilder.AppendLine();
171+
exceptionMessageBuilder.Append(errorOutputBuilder);
172+
}
173+
174+
if (!string.IsNullOrEmpty(outputBuilder.ToString()))
175+
{
176+
exceptionMessageBuilder.AppendLine();
177+
exceptionMessageBuilder.Append("Standard Output >>");
178+
exceptionMessageBuilder.AppendLine();
179+
exceptionMessageBuilder.Append(outputBuilder);
180+
}
181+
182+
throw new WebDriverException(exceptionMessageBuilder.ToString());
158183
}
159184
}
160185
catch (Exception ex)
@@ -164,6 +189,7 @@ private static Dictionary<string, object> RunCommand(string fileName, string arg
164189
finally
165190
{
166191
process.OutputDataReceived -= outputHandler;
192+
process.ErrorDataReceived -= errorOutputHandler;
167193
}
168194

169195
string output = outputBuilder.ToString().Trim();

0 commit comments

Comments
 (0)