Skip to content

Commit 283a2b8

Browse files
committed
Updating finding of test web server for .NET tests
1 parent 005a942 commit 283a2b8

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

dotnet/test/common/Environment/EnvironmentManager.cs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.IO;
44
using Newtonsoft.Json;
55
using NUnit.Framework;
6+
using System.Collections.Generic;
67

78
namespace OpenQA.Selenium.Environment
89
{
@@ -21,8 +22,9 @@ public class EnvironmentManager
2122
private EnvironmentManager()
2223
{
2324
string currentDirectory = this.CurrentDirectory;
24-
string configFile = Path.Combine(currentDirectory, "appconfig.json");
25-
25+
string defaultConfigFile = Path.Combine(currentDirectory, "appconfig.json");
26+
string configFile = TestContext.Parameters.Get<string>("ConfigFile", defaultConfigFile).Replace('/', Path.DirectorySeparatorChar);
27+
2628
string content = File.ReadAllText(configFile);
2729
TestEnvironment env = JsonConvert.DeserializeObject<TestEnvironment>(content);
2830

@@ -48,14 +50,57 @@ private EnvironmentManager()
4850
string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR");
4951
if (string.IsNullOrEmpty(projectRoot))
5052
{
53+
// Walk up the directory tree until we find ourselves in a directory
54+
// where the path to the Java web server can be determined.
55+
bool continueTraversal = true;
5156
DirectoryInfo info = new DirectoryInfo(currentDirectory);
52-
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)
57+
while (continueTraversal)
5358
{
54-
info = info.Parent;
59+
if (info == info.Root)
60+
{
61+
break;
62+
}
63+
64+
foreach (var childDir in info.EnumerateDirectories())
65+
{
66+
// Case 1: The current directory of this assembly is in the
67+
// same direct sub-tree as the Java targets (usually meaning
68+
// executing tests from the same build system as that which
69+
// builds the Java targets).
70+
// If we find a child directory named "java", then the web
71+
// server should be able to be found under there.
72+
if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0)
73+
{
74+
continueTraversal = false;
75+
break;
76+
}
77+
78+
// Case 2: The current directory of this assembly is a different
79+
// sub-tree as the Java targets (usually meaning executing tests
80+
// from a different build system as that which builds the Java
81+
// targets).
82+
// If we travel to a place in the tree where there is a child
83+
// directory named "bazel-bin", the web server should be found
84+
// in the "java" subdirectory of that directory.
85+
if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0)
86+
{
87+
string javaOutDirectory = Path.Combine(childDir.FullName, "java");
88+
if (Directory.Exists(javaOutDirectory))
89+
{
90+
info = new DirectoryInfo(javaOutDirectory);
91+
continueTraversal = false;
92+
break;
93+
}
94+
}
95+
}
96+
97+
if (continueTraversal)
98+
{
99+
info = info.Parent;
100+
}
55101
}
56102

57-
info = info.Parent;
58-
projectRoot = Path.Combine(info.FullName, "bazel-bin");
103+
projectRoot = info.FullName;
59104
}
60105
else
61106
{

dotnet/test/common/Environment/TestWebServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public void Start()
105105
string error = "'CaptureWebServerOutput' parameter is false. Web server output not being captured.";
106106
if (captureWebServerOutput)
107107
{
108-
webserverProcess.StandardError.ReadToEnd();
109-
webserverProcess.StandardOutput.ReadToEnd();
108+
error = webserverProcess.StandardError.ReadToEnd();
109+
output = webserverProcess.StandardOutput.ReadToEnd();
110110
}
111111

112112
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);

0 commit comments

Comments
 (0)