diff --git a/common/src/web/BUILD.bazel b/common/src/web/BUILD.bazel index da3d905863333..0289a6466c73b 100644 --- a/common/src/web/BUILD.bazel +++ b/common/src/web/BUILD.bazel @@ -4,5 +4,8 @@ filegroup( "*", "**/*", ]), - visibility = ["//java/client/test/org/openqa/selenium/environment:__pkg__"], + visibility = [ + "//java/client/test/org/openqa/selenium/environment:__pkg__", + "//dotnet/test/common:__pkg__" + ], ) diff --git a/dotnet/test/common/BUILD.bazel b/dotnet/test/common/BUILD.bazel new file mode 100644 index 0000000000000..dc70e94ce2451 --- /dev/null +++ b/dotnet/test/common/BUILD.bazel @@ -0,0 +1,40 @@ +load("@io_bazel_rules_dotnet//dotnet:defs.bzl", "net_nunit3_test") + +net_nunit3_test( + name = "chrome", + srcs = glob([ + "*.cs", + "CustomTestAttributes/*.cs", + "Environment/*.cs", + "HTML5/*.cs", + "Interactions/*.cs", + ]), + deps = [ + "@io_bazel_rules_dotnet//dotnet/stdlib.net:system.dll", + "@io_bazel_rules_dotnet//dotnet/stdlib.net:system.core.dll", + "@io_bazel_rules_dotnet//dotnet/stdlib.net:system.data.dll", + "@io_bazel_rules_dotnet//dotnet/stdlib.net:system.drawing.dll", + "@io_bazel_rules_dotnet//dotnet/stdlib.net:system.xml.dll", + "//dotnet/src/webdriver:net47assembly", + "@json.net//:net45", + "@moq//:net45", + "@nunit//:net45", + "@benderproxy//:net47", + ], + data = [ + "appconfig.json", + "//java/client/test/org/openqa/selenium/environment:WebServer", + "//java/client/test/org/openqa/selenium/environment:WebServer_deploy.jar", + "//common/src/web", + ], + size = "enormous", + args = [ + "--agents=1", + "--params=ConfigFile=$(location appconfig.json)", + "--params=ActiveWebsiteConfig=HostsFileRedirect", + "--params=ActiveDriverConfig=Chrome", + ], + visibility = ["//visibility:public"], + out = "WebDriver.Common.Tests.dll", + dotnet_context_data = "@io_bazel_rules_dotnet//:net_context_data_net47" +) diff --git a/dotnet/test/common/Environment/EnvironmentManager.cs b/dotnet/test/common/Environment/EnvironmentManager.cs index 1d2d04c5e3233..da0ab29584e59 100644 --- a/dotnet/test/common/Environment/EnvironmentManager.cs +++ b/dotnet/test/common/Environment/EnvironmentManager.cs @@ -21,11 +21,7 @@ public class EnvironmentManager private EnvironmentManager() { string currentDirectory = this.CurrentDirectory; - string configFile = TestContext.Parameters.Get("ConfigFile", string.Empty); - if (string.IsNullOrEmpty(configFile)) - { - configFile = Path.Combine(currentDirectory, "appconfig.json"); - } + string configFile = Path.Combine(currentDirectory, "appconfig.json"); string content = File.ReadAllText(configFile); TestEnvironment env = JsonConvert.DeserializeObject(content); @@ -45,7 +41,10 @@ private EnvironmentManager() urlBuilder = new UrlBuilder(websiteConfig); - string projectRoot = TestContext.Parameters.Get("RootPath", string.Empty); + // When run using the `bazel test` command, the following environment + // variable will be set. If not set, we're running from a build system + // outside Bazel, and need to locate the directory containing the jar. + string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR"); if (string.IsNullOrEmpty(projectRoot)) { DirectoryInfo info = new DirectoryInfo(currentDirectory); @@ -55,7 +54,11 @@ private EnvironmentManager() } info = info.Parent; - projectRoot = info.FullName; + projectRoot = Path.Combine(info.FullName, "bazel-bin"); + } + else + { + projectRoot += "/selenium"; } webServer = new TestWebServer(projectRoot); diff --git a/dotnet/test/common/Environment/TestWebServer.cs b/dotnet/test/common/Environment/TestWebServer.cs index 3284c6533dee6..5da06e6f8f8e0 100644 --- a/dotnet/test/common/Environment/TestWebServer.cs +++ b/dotnet/test/common/Environment/TestWebServer.cs @@ -1,7 +1,9 @@ using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Diagnostics; +using System.Text; namespace OpenQA.Selenium.Environment { @@ -9,10 +11,11 @@ public class TestWebServer { private Process webserverProcess; - private string standaloneTestJar = @"buck-out/gen/java/client/test/org/openqa/selenium/environment/webserver.jar"; - private string webserverClassName = "org.openqa.selenium.environment.webserver.JettyAppServer"; + private string standaloneTestJar = @"java/client/test/org/openqa/selenium/environment/WebServer_deploy.jar"; private string projectRootPath; + private StringBuilder outputData = new StringBuilder(); + public TestWebServer(string projectRoot) { projectRootPath = projectRoot; @@ -29,7 +32,7 @@ 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, - "go //java/client/test/org/openqa/selenium/environment:webserver", + "bazel build //java/client/test/org/openqa/selenium/environment:WebServer_deploy.jar", projectRootPath)); } @@ -39,16 +42,37 @@ public void Start() javaExecutableName = javaExecutableName + ".exe"; } - string processArgs = string.Format("-Duser.dir={0} -cp {1} {2}", projectRootPath, standaloneTestJar, webserverClassName); + List javaSystemProperties = new List(); + javaSystemProperties.Add("org.openqa.selenium.environment.webserver.ignoreMissingJsRoots=true"); + + 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); webserverProcess = new Process(); webserverProcess.StartInfo.FileName = javaExecutableName; - webserverProcess.StartInfo.Arguments = processArgs; + webserverProcess.StartInfo.Arguments = processArgsBuilder.ToString(); webserverProcess.StartInfo.WorkingDirectory = projectRootPath; webserverProcess.Start(); - DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(30)); + + TimeSpan timeout = TimeSpan.FromSeconds(30); + DateTime endTime = DateTime.Now.Add(TimeSpan.FromSeconds(30)); bool isRunning = false; - while (!isRunning && DateTime.Now < timeout) + while (!isRunning && DateTime.Now < endTime) { // Poll until the webserver is correctly serving pages. HttpWebRequest request = WebRequest.Create(EnvironmentManager.Instance.UrlBuilder.LocalWhereIs("simpleTest.html")) as HttpWebRequest; @@ -67,7 +91,8 @@ public void Start() if (!isRunning) { - throw new TimeoutException("Could not start the test web server in 15 seconds"); + string errorMessage = string.Format("Could not start the test web server in {0} seconds. Process Args: {1}", timeout.TotalSeconds, processArgsBuilder); + throw new TimeoutException(errorMessage); } } }