3
3
using System . IO ;
4
4
using Newtonsoft . Json ;
5
5
using NUnit . Framework ;
6
+ using System . Collections . Generic ;
6
7
7
8
namespace OpenQA . Selenium . Environment
8
9
{
@@ -21,8 +22,9 @@ public class EnvironmentManager
21
22
private EnvironmentManager ( )
22
23
{
23
24
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
+
26
28
string content = File . ReadAllText ( configFile ) ;
27
29
TestEnvironment env = JsonConvert . DeserializeObject < TestEnvironment > ( content ) ;
28
30
@@ -48,14 +50,57 @@ private EnvironmentManager()
48
50
string projectRoot = System . Environment . GetEnvironmentVariable ( "TEST_SRCDIR" ) ;
49
51
if ( string . IsNullOrEmpty ( projectRoot ) )
50
52
{
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 ;
51
56
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 )
53
58
{
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
+ }
55
101
}
56
102
57
- info = info . Parent ;
58
- projectRoot = Path . Combine ( info . FullName , "bazel-bin" ) ;
103
+ projectRoot = info . FullName ;
59
104
}
60
105
else
61
106
{
0 commit comments