Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion dotnet/test/common/Environment/EnvironmentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class EnvironmentManager
private EnvironmentManager()
{
string dataFilePath;
var runfiles = Runfiles.Create();
Runfiles runfiles = null;
try
{
runfiles = Runfiles.Create();
dataFilePath = runfiles.Rlocation("_main/dotnet/test/common/appconfig.json");
}
catch (FileNotFoundException)
Expand Down Expand Up @@ -143,6 +144,8 @@ private EnvironmentManager()
try
{
string managerFilePath = "";
runfiles ??= Runfiles.Create();

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/windows/selenium-manager.exe");
Expand Down
107 changes: 53 additions & 54 deletions dotnet/test/common/Environment/TestWebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ public class TestWebServer
private string javaHomeDirectory;
private string port;

private StringBuilder outputData = new StringBuilder();

public TestWebServer(string projectRoot, TestWebServerConfig config)
{
this.projectRootPath = projectRoot;
this.captureWebServerOutput = config.CaptureConsoleOutput;
this.hideCommandPrompt = config.HideCommandPromptWindow;
this.javaHomeDirectory = config.JavaHomeDirectory;
if (string.IsNullOrEmpty(this.javaHomeDirectory))
{
this.javaHomeDirectory = System.Environment.GetEnvironmentVariable("JAVA_HOME");
}
this.port = config.Port;
}

Expand All @@ -39,16 +41,22 @@ public void Start()
{
var runfiles = Runfiles.Create();
standaloneTestJar = runfiles.Rlocation(standaloneTestJar);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
standaloneTestJar += ".exe";
}
}
catch (FileNotFoundException)
{
var baseDirectory = AppContext.BaseDirectory;
standaloneTestJar = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver");
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
standaloneTestJar += ".exe";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
standaloneTestJar = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver.exe");
}
else
{
standaloneTestJar = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver_deploy.jar");
}
}

Console.Write("Standalone jar is " + standaloneTestJar);
Expand All @@ -59,65 +67,49 @@ public void Start()
string.Format(
"Test webserver jar at {0} didn't exist. Project root is {2}. Please build it using something like {1}.",
standaloneTestJar,
"bazel build //java/test/org/openqa/selenium/environment:appserver_deploy.jar",
"bazel build //java/test/org/openqa/selenium/environment:appserver",
projectRootPath));
}

//List<string> javaSystemProperties = new List<string>();

StringBuilder processArgsBuilder = new StringBuilder();
// foreach (string systemProperty in javaSystemProperties)
// {
// if (processArgsBuilder.Length > 0)
// {
// processArgsBuilder.Append(" ");
// }
//
// processArgsBuilder.AppendFormat("-D{0}", systemProperty);
// }
//
// if (processArgsBuilder.Length > 0)
// {
// processArgsBuilder.Append(" ");
// }
//
// processArgsBuilder.AppendFormat("-jar {0}", standaloneTestJar);
processArgsBuilder.AppendFormat(" {0}", this.port);

Console.Write(processArgsBuilder.ToString());
ProcessStartInfo startInfo = new ProcessStartInfo
{
WorkingDirectory = projectRootPath,
UseShellExecute = !(hideCommandPrompt || captureWebServerOutput),
CreateNoWindow = hideCommandPrompt,
RedirectStandardOutput = captureWebServerOutput,
RedirectStandardError = captureWebServerOutput
};

if (standaloneTestJar != null && standaloneTestJar.EndsWith(".jar"))
{
processArgsBuilder.AppendFormat("-jar \"{0}\" {1}", standaloneTestJar, this.port);
string javaExecutable = Path.Combine(javaHomeDirectory, "bin", "java");
if (!File.Exists(javaExecutable))
{
throw new FileNotFoundException($"Java executable not found at {javaExecutable}");
}

webserverProcess = new Process();
webserverProcess.StartInfo.FileName = standaloneTestJar;
// if (!string.IsNullOrEmpty(javaExecutablePath))
// {
// webserverProcess.StartInfo.FileName = Path.Combine(javaExecutablePath, javaExecutableName);
// }
// else
// {
// webserverProcess.StartInfo.FileName = javaExecutableName;
// }

webserverProcess.StartInfo.Arguments = processArgsBuilder.ToString();
webserverProcess.StartInfo.WorkingDirectory = projectRootPath;
webserverProcess.StartInfo.UseShellExecute = !(hideCommandPrompt || captureWebServerOutput);
webserverProcess.StartInfo.CreateNoWindow = hideCommandPrompt;
if (!string.IsNullOrEmpty(this.javaHomeDirectory))
startInfo.FileName = javaExecutable;
}
else
{
webserverProcess.StartInfo.EnvironmentVariables["JAVA_HOME"] = this.javaHomeDirectory;
processArgsBuilder.AppendFormat(" {0}", this.port);
startInfo.FileName = standaloneTestJar;
}

captureWebServerOutput = true;

if (captureWebServerOutput)
Console.Write(processArgsBuilder.ToString());
startInfo.Arguments = processArgsBuilder.ToString();
if (!string.IsNullOrEmpty(this.javaHomeDirectory))
{
webserverProcess.StartInfo.RedirectStandardOutput = true;
webserverProcess.StartInfo.RedirectStandardError = true;
startInfo.EnvironmentVariables["JAVA_HOME"] = this.javaHomeDirectory;
}

webserverProcess = new Process { StartInfo = startInfo };
webserverProcess.Start();

TimeSpan timeout = TimeSpan.FromSeconds(30);
DateTime endTime = DateTime.Now.Add(TimeSpan.FromSeconds(30));
DateTime endTime = DateTime.Now.Add(timeout);
bool isRunning = false;

// Poll until the webserver is correctly serving pages.
Expand Down Expand Up @@ -161,7 +153,14 @@ public void Stop()
{
using (var httpClient = new HttpClient())
{
using (var quitResponse = httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")).GetAwaiter().GetResult())
try
{
using (httpClient.GetAsync(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("quitquitquit")).GetAwaiter().GetResult())
{

}
}
catch (HttpRequestException)
{

}
Expand Down