2323using System . IO ;
2424using System . Net ;
2525using System . Net . Http ;
26- using System . Runtime . InteropServices ;
2726using System . Text ;
2827using System . Threading . Tasks ;
2928
@@ -33,21 +32,17 @@ public class TestWebServer
3332 {
3433 private Process webserverProcess ;
3534
36- private string standaloneAppserverPath = @"_main/java/test/org/openqa/selenium/environment/appserver" ;
35+ private string standaloneAppserverPath ;
3736 private string projectRootPath ;
3837 private bool captureWebServerOutput ;
3938 private bool hideCommandPrompt ;
40- private string javaHomeDirectory ;
4139 private string port ;
4240
43- private StringBuilder outputData = new StringBuilder ( ) ;
44-
4541 public TestWebServer ( string projectRoot , TestWebServerConfig config )
4642 {
4743 this . projectRootPath = projectRoot ;
4844 this . captureWebServerOutput = config . CaptureConsoleOutput ;
4945 this . hideCommandPrompt = config . HideCommandPromptWindow ;
50- this . javaHomeDirectory = config . JavaHomeDirectory ;
5146 this . port = config . Port ;
5247 }
5348
@@ -58,41 +53,30 @@ public async Task StartAsync()
5853 try
5954 {
6055 var runfiles = Runfiles . Create ( ) ;
61- standaloneAppserverPath = runfiles . Rlocation ( standaloneAppserverPath ) ;
56+ standaloneAppserverPath = runfiles . Rlocation ( @"_main/java/test/org/openqa/selenium/environment/appserver" ) ;
6257 }
58+ // means we are NOT running under bazel runtime
59+ // most likely in IDE
6360 catch ( FileNotFoundException )
6461 {
65- var baseDirectory = AppContext . BaseDirectory ;
66- standaloneAppserverPath = Path . Combine ( baseDirectory , "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver" ) ;
62+ // var baseDirectory = AppContext.BaseDirectory;
63+ // standaloneAppserverPath = Path.Combine(baseDirectory, "../../../../../../bazel-bin/java/test/org/openqa/selenium/environment/appserver");
6764 }
6865
69- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
70- {
71- standaloneAppserverPath += ".exe" ;
72- }
66+ var processFileName = standaloneAppserverPath ?? "bazel" ;
7367
74- Console . Write ( "Test Appserver is " + standaloneAppserverPath ) ;
68+ string processArguments = $ " { port } " ;
7569
76- if ( ! File . Exists ( standaloneAppserverPath ) )
70+ if ( standaloneAppserverPath is null )
7771 {
78- throw new FileNotFoundException (
79- string . Format (
80- "Test Appserver at {0} didn't exist. Project root is {2}. Please build it using something like {1}." ,
81- standaloneAppserverPath ,
82- "bazel build //java/test/org/openqa/selenium/environment:appserver" ,
83- projectRootPath ) ) ;
72+ processArguments = $ "run //java/test/org/openqa/selenium/environment:appserver { processArguments } ";
73+ projectRootPath = Path . Combine ( AppContext . BaseDirectory , "../../../../../.." ) ;
8474 }
8575
86- StringBuilder processArgsBuilder = new StringBuilder ( ) ;
87-
88- processArgsBuilder . AppendFormat ( " {0}" , this . port ) ;
89-
90- Console . Write ( processArgsBuilder . ToString ( ) ) ;
91-
9276 webserverProcess = new Process ( ) ;
93- webserverProcess . StartInfo . FileName = standaloneAppserverPath ;
9477
95- webserverProcess . StartInfo . Arguments = processArgsBuilder . ToString ( ) ;
78+ webserverProcess . StartInfo . FileName = processFileName ;
79+ webserverProcess . StartInfo . Arguments = processArguments ;
9680 webserverProcess . StartInfo . WorkingDirectory = projectRootPath ;
9781 webserverProcess . StartInfo . UseShellExecute = ! ( hideCommandPrompt || captureWebServerOutput ) ;
9882 webserverProcess . StartInfo . CreateNoWindow = hideCommandPrompt ;
@@ -140,7 +124,8 @@ public async Task StartAsync()
140124 output = webserverProcess . StandardOutput . ReadToEnd ( ) ;
141125 }
142126
143- string errorMessage = string . Format ( "Could not start the test web server in {0} seconds.\n Working directory: {1}\n Process Args: {2}\n stdout: {3}\n stderr: {4}" , timeout . TotalSeconds , projectRootPath , processArgsBuilder , output , error ) ;
127+ string errorMessage = string . Format ( "Could not start the test web server in {0} seconds.\n Working directory: {1}\n Process Args: {2}\n stdout: {3}\n stderr: {4}" , timeout . TotalSeconds , projectRootPath , processArguments , output , error ) ;
128+
144129 throw new TimeoutException ( errorMessage ) ;
145130 }
146131 }
0 commit comments