From 283a2b8e9ed20550948c9463034e3d10130f2b5f Mon Sep 17 00:00:00 2001 From: Jim Evans Date: Sun, 30 Jun 2019 14:31:53 -0700 Subject: [PATCH] Updating finding of test web server for .NET tests --- .../common/Environment/EnvironmentManager.cs | 57 +++++++++++++++++-- .../test/common/Environment/TestWebServer.cs | 4 +- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/dotnet/test/common/Environment/EnvironmentManager.cs b/dotnet/test/common/Environment/EnvironmentManager.cs index ce6e63d1eb6e0..0427d26e2edb7 100644 --- a/dotnet/test/common/Environment/EnvironmentManager.cs +++ b/dotnet/test/common/Environment/EnvironmentManager.cs @@ -3,6 +3,7 @@ using System.IO; using Newtonsoft.Json; using NUnit.Framework; +using System.Collections.Generic; namespace OpenQA.Selenium.Environment { @@ -21,8 +22,9 @@ public class EnvironmentManager private EnvironmentManager() { string currentDirectory = this.CurrentDirectory; - string configFile = Path.Combine(currentDirectory, "appconfig.json"); - + string defaultConfigFile = Path.Combine(currentDirectory, "appconfig.json"); + string configFile = TestContext.Parameters.Get("ConfigFile", defaultConfigFile).Replace('/', Path.DirectorySeparatorChar); + string content = File.ReadAllText(configFile); TestEnvironment env = JsonConvert.DeserializeObject(content); @@ -48,14 +50,57 @@ private EnvironmentManager() string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR"); if (string.IsNullOrEmpty(projectRoot)) { + // Walk up the directory tree until we find ourselves in a directory + // where the path to the Java web server can be determined. + bool continueTraversal = true; DirectoryInfo info = new DirectoryInfo(currentDirectory); - while (info != info.Root && string.Compare(info.Name, "bazel-out", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(info.Name, "buck-out", StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(info.Name, "build", StringComparison.OrdinalIgnoreCase) != 0) + while (continueTraversal) { - info = info.Parent; + if (info == info.Root) + { + break; + } + + foreach (var childDir in info.EnumerateDirectories()) + { + // Case 1: The current directory of this assembly is in the + // same direct sub-tree as the Java targets (usually meaning + // executing tests from the same build system as that which + // builds the Java targets). + // If we find a child directory named "java", then the web + // server should be able to be found under there. + if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0) + { + continueTraversal = false; + break; + } + + // Case 2: The current directory of this assembly is a different + // sub-tree as the Java targets (usually meaning executing tests + // from a different build system as that which builds the Java + // targets). + // If we travel to a place in the tree where there is a child + // directory named "bazel-bin", the web server should be found + // in the "java" subdirectory of that directory. + if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0) + { + string javaOutDirectory = Path.Combine(childDir.FullName, "java"); + if (Directory.Exists(javaOutDirectory)) + { + info = new DirectoryInfo(javaOutDirectory); + continueTraversal = false; + break; + } + } + } + + if (continueTraversal) + { + info = info.Parent; + } } - info = info.Parent; - projectRoot = Path.Combine(info.FullName, "bazel-bin"); + projectRoot = info.FullName; } else { diff --git a/dotnet/test/common/Environment/TestWebServer.cs b/dotnet/test/common/Environment/TestWebServer.cs index d9ee66d248743..549384fefed3d 100644 --- a/dotnet/test/common/Environment/TestWebServer.cs +++ b/dotnet/test/common/Environment/TestWebServer.cs @@ -105,8 +105,8 @@ public void Start() string error = "'CaptureWebServerOutput' parameter is false. Web server output not being captured."; if (captureWebServerOutput) { - webserverProcess.StandardError.ReadToEnd(); - webserverProcess.StandardOutput.ReadToEnd(); + error = webserverProcess.StandardError.ReadToEnd(); + output = 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);