Skip to content

Commit

Permalink
Adding ability to capture Java web server console output from .NET tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jimevans committed Jun 3, 2019
1 parent 65d4d19 commit 6a719ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion dotnet/test/common/Environment/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private EnvironmentManager()
string content = File.ReadAllText(configFile);
TestEnvironment env = JsonConvert.DeserializeObject<TestEnvironment>(content);

bool captureWebServerOutput = TestContext.Parameters.Get<bool>("CaptureWebServerOutput", false);
string activeDriverConfig = TestContext.Parameters.Get("ActiveDriverConfig", env.ActiveDriverConfig);
string activeWebsiteConfig = TestContext.Parameters.Get("ActiveWebsiteConfig", env.ActiveWebsiteConfig);
string driverServiceLocation = TestContext.Parameters.Get("DriverServiceLocation", env.DriverServiceLocation);
Expand Down Expand Up @@ -61,7 +62,7 @@ private EnvironmentManager()
projectRoot += "/selenium";
}

webServer = new TestWebServer(projectRoot);
webServer = new TestWebServer(projectRoot, captureWebServerOutput);
bool autoStartRemoteServer = false;
if (browser == Browser.Remote)
{
Expand Down
22 changes: 20 additions & 2 deletions dotnet/test/common/Environment/TestWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Net;
using System.Diagnostics;
using System.Text;
using NUnit.Framework;

namespace OpenQA.Selenium.Environment
{
Expand All @@ -13,12 +14,14 @@ public class TestWebServer

private string standaloneTestJar = @"java/client/test/org/openqa/selenium/environment/appserver_deploy.jar";
private string projectRootPath;
private bool captureWebServerOutput;

private StringBuilder outputData = new StringBuilder();

public TestWebServer(string projectRoot)
public TestWebServer(string projectRoot, bool captureWebServerOutput)
{
projectRootPath = projectRoot;
this.captureWebServerOutput = captureWebServerOutput;
}

public void Start()
Expand Down Expand Up @@ -67,6 +70,13 @@ public void Start()
webserverProcess.StartInfo.FileName = javaExecutableName;
webserverProcess.StartInfo.Arguments = processArgsBuilder.ToString();
webserverProcess.StartInfo.WorkingDirectory = projectRootPath;
if (captureWebServerOutput)
{
webserverProcess.StartInfo.RedirectStandardOutput = true;
webserverProcess.StartInfo.RedirectStandardError = true;
webserverProcess.StartInfo.UseShellExecute = false;
}

webserverProcess.Start();

TimeSpan timeout = TimeSpan.FromSeconds(30);
Expand All @@ -91,7 +101,15 @@ public void Start()

if (!isRunning)
{
string errorMessage = string.Format("Could not start the test web server in {0} seconds. Process Args: {1}", timeout.TotalSeconds, processArgsBuilder);
string output = "'CaptureWebServerOutput' parameter is false. Web server output not captured";
string error = "'CaptureWebServerOutput' parameter is false. Web server output not being captured.";
if (captureWebServerOutput)
{
webserverProcess.StandardError.ReadToEnd();
webserverProcess.StandardOutput.ReadToEnd();
}

string errorMessage = string.Format("Could not start the test web server in {0} seconds.\nWorking directory: {1}\nProcess Args: {2}\nstdout: {3}\nstderr: {4}", timeout.TotalSeconds, projectRootPath, processArgsBuilder, output, error);
throw new TimeoutException(errorMessage);
}
}
Expand Down

0 comments on commit 6a719ff

Please sign in to comment.