Skip to content

Commit ee41e9a

Browse files
committed
fix whitespace
1 parent 5b2f4e9 commit ee41e9a

File tree

1 file changed

+136
-136
lines changed

1 file changed

+136
-136
lines changed

dotnet/test/common/Environment/EnvironmentManager.cs

Lines changed: 136 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -35,151 +35,151 @@ public class EnvironmentManager
3535
private IWebDriver driver;
3636
private readonly DriverFactory driverFactory;
3737

38-
private EnvironmentManager()
39-
{
40-
string dataFilePath;
41-
Runfiles runfiles = null;
42-
try
43-
{
44-
runfiles = Runfiles.Create();
45-
dataFilePath = runfiles.Rlocation("_main/dotnet/test/common/appconfig.json");
46-
}
47-
catch (FileNotFoundException)
38+
private EnvironmentManager()
4839
{
49-
dataFilePath = "appconfig.json";
50-
}
51-
string currentDirectory = this.CurrentDirectory;
40+
string dataFilePath;
41+
Runfiles runfiles = null;
42+
try
43+
{
44+
runfiles = Runfiles.Create();
45+
dataFilePath = runfiles.Rlocation("_main/dotnet/test/common/appconfig.json");
46+
}
47+
catch (FileNotFoundException)
48+
{
49+
dataFilePath = "appconfig.json";
50+
}
51+
string currentDirectory = this.CurrentDirectory;
5252

53-
string content = File.ReadAllText(dataFilePath);
54-
TestEnvironment env = JsonConvert.DeserializeObject<TestEnvironment>(content);
53+
string content = File.ReadAllText(dataFilePath);
54+
TestEnvironment env = JsonConvert.DeserializeObject<TestEnvironment>(content);
5555

56-
string activeDriverConfig = System.Environment.GetEnvironmentVariable("ACTIVE_DRIVER_CONFIG") ?? TestContext.Parameters.Get("ActiveDriverConfig", env.ActiveDriverConfig);
57-
string driverServiceLocation = System.Environment.GetEnvironmentVariable("DRIVER_SERVICE_LOCATION") ?? TestContext.Parameters.Get("DriverServiceLocation", env.DriverServiceLocation);
56+
string activeDriverConfig = System.Environment.GetEnvironmentVariable("ACTIVE_DRIVER_CONFIG") ?? TestContext.Parameters.Get("ActiveDriverConfig", env.ActiveDriverConfig);
57+
string driverServiceLocation = System.Environment.GetEnvironmentVariable("DRIVER_SERVICE_LOCATION") ?? TestContext.Parameters.Get("DriverServiceLocation", env.DriverServiceLocation);
5858

59-
string browserLocation = System.Environment.GetEnvironmentVariable("BROWSER_LOCATION") ?? TestContext.Parameters.Get("BrowserLocation", string.Empty);
59+
string browserLocation = System.Environment.GetEnvironmentVariable("BROWSER_LOCATION") ?? TestContext.Parameters.Get("BrowserLocation", string.Empty);
6060

61-
string activeWebsiteConfig = TestContext.Parameters.Get("ActiveWebsiteConfig", env.ActiveWebsiteConfig);
62-
DriverConfig driverConfig = env.DriverConfigs[activeDriverConfig];
63-
WebsiteConfig websiteConfig = env.WebSiteConfigs[activeWebsiteConfig];
61+
string activeWebsiteConfig = TestContext.Parameters.Get("ActiveWebsiteConfig", env.ActiveWebsiteConfig);
62+
DriverConfig driverConfig = env.DriverConfigs[activeDriverConfig];
63+
WebsiteConfig websiteConfig = env.WebSiteConfigs[activeWebsiteConfig];
6464

65-
int port = PortUtilities.FindFreePort();
66-
websiteConfig.Port = port.ToString();
65+
int port = PortUtilities.FindFreePort();
66+
websiteConfig.Port = port.ToString();
6767

68-
TestWebServerConfig webServerConfig = env.TestWebServerConfig;
69-
webServerConfig.CaptureConsoleOutput = TestContext.Parameters.Get<bool>("CaptureWebServerOutput", env.TestWebServerConfig.CaptureConsoleOutput);
70-
webServerConfig.HideCommandPromptWindow = TestContext.Parameters.Get<bool>("HideWebServerCommandPrompt", env.TestWebServerConfig.HideCommandPromptWindow);
71-
webServerConfig.JavaHomeDirectory = TestContext.Parameters.Get("WebServerJavaHome", env.TestWebServerConfig.JavaHomeDirectory);
72-
webServerConfig.Port = websiteConfig.Port;
68+
TestWebServerConfig webServerConfig = env.TestWebServerConfig;
69+
webServerConfig.CaptureConsoleOutput = TestContext.Parameters.Get<bool>("CaptureWebServerOutput", env.TestWebServerConfig.CaptureConsoleOutput);
70+
webServerConfig.HideCommandPromptWindow = TestContext.Parameters.Get<bool>("HideWebServerCommandPrompt", env.TestWebServerConfig.HideCommandPromptWindow);
71+
webServerConfig.JavaHomeDirectory = TestContext.Parameters.Get("WebServerJavaHome", env.TestWebServerConfig.JavaHomeDirectory);
72+
webServerConfig.Port = websiteConfig.Port;
7373

74-
this.driverFactory = new DriverFactory(driverServiceLocation, browserLocation);
75-
this.driverFactory.DriverStarting += OnDriverStarting;
74+
this.driverFactory = new DriverFactory(driverServiceLocation, browserLocation);
75+
this.driverFactory.DriverStarting += OnDriverStarting;
7676

77-
// Search for the driver type in the all assemblies,
78-
// bazel uses unpredictable assembly names to execute tests
79-
driverType = AppDomain.CurrentDomain.GetAssemblies()
80-
.Reverse()
81-
.Select(assembly => assembly.GetType(driverConfig.DriverTypeName))
82-
.FirstOrDefault(t => t != null);
77+
// Search for the driver type in the all assemblies,
78+
// bazel uses unpredictable assembly names to execute tests
79+
driverType = AppDomain.CurrentDomain.GetAssemblies()
80+
.Reverse()
81+
.Select(assembly => assembly.GetType(driverConfig.DriverTypeName))
82+
.FirstOrDefault(t => t != null);
8383

84-
if (driverType == null)
85-
{
86-
throw new ArgumentOutOfRangeException($"Unable to find driver type {driverConfig.DriverTypeName}");
87-
}
84+
if (driverType == null)
85+
{
86+
throw new ArgumentOutOfRangeException($"Unable to find driver type {driverConfig.DriverTypeName}");
87+
}
8888

8989
Browser = driverConfig.BrowserValue;
9090
RemoteCapabilities = driverConfig.RemoteCapabilities;
9191

9292
UrlBuilder = new UrlBuilder(websiteConfig);
9393

94-
// When run using the `bazel test` command, the following environment
95-
// variable will be set. If not set, we're running from a build system
96-
// outside Bazel, and need to locate the directory containing the jar.
97-
string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR");
98-
if (string.IsNullOrEmpty(projectRoot))
99-
{
100-
// Walk up the directory tree until we find ourselves in a directory
101-
// where the path to the Java web server can be determined.
102-
bool continueTraversal = true;
103-
DirectoryInfo info = new DirectoryInfo(currentDirectory);
104-
while (continueTraversal)
94+
// When run using the `bazel test` command, the following environment
95+
// variable will be set. If not set, we're running from a build system
96+
// outside Bazel, and need to locate the directory containing the jar.
97+
string projectRoot = System.Environment.GetEnvironmentVariable("TEST_SRCDIR");
98+
if (string.IsNullOrEmpty(projectRoot))
10599
{
106-
if (info == info.Root)
107-
{
108-
break;
109-
}
110-
111-
foreach (var childDir in info.EnumerateDirectories())
100+
// Walk up the directory tree until we find ourselves in a directory
101+
// where the path to the Java web server can be determined.
102+
bool continueTraversal = true;
103+
DirectoryInfo info = new DirectoryInfo(currentDirectory);
104+
while (continueTraversal)
112105
{
113-
// Case 1: The current directory of this assembly is in the
114-
// same direct sub-tree as the Java targets (usually meaning
115-
// executing tests from the same build system as that which
116-
// builds the Java targets).
117-
// If we find a child directory named "java", then the web
118-
// server should be able to be found under there.
119-
if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0)
106+
if (info == info.Root)
120107
{
121-
continueTraversal = false;
122108
break;
123109
}
124110

125-
// Case 2: The current directory of this assembly is a different
126-
// sub-tree as the Java targets (usually meaning executing tests
127-
// from a different build system as that which builds the Java
128-
// targets).
129-
// If we travel to a place in the tree where there is a child
130-
// directory named "bazel-bin", the web server should be found
131-
// in the "java" subdirectory of that directory.
132-
if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0)
111+
foreach (var childDir in info.EnumerateDirectories())
133112
{
134-
string javaOutDirectory = Path.Combine(childDir.FullName, "java");
135-
if (Directory.Exists(javaOutDirectory))
113+
// Case 1: The current directory of this assembly is in the
114+
// same direct sub-tree as the Java targets (usually meaning
115+
// executing tests from the same build system as that which
116+
// builds the Java targets).
117+
// If we find a child directory named "java", then the web
118+
// server should be able to be found under there.
119+
if (string.Compare(childDir.Name, "java", StringComparison.OrdinalIgnoreCase) == 0)
136120
{
137-
info = childDir;
138121
continueTraversal = false;
139122
break;
140123
}
124+
125+
// Case 2: The current directory of this assembly is a different
126+
// sub-tree as the Java targets (usually meaning executing tests
127+
// from a different build system as that which builds the Java
128+
// targets).
129+
// If we travel to a place in the tree where there is a child
130+
// directory named "bazel-bin", the web server should be found
131+
// in the "java" subdirectory of that directory.
132+
if (string.Compare(childDir.Name, "bazel-bin", StringComparison.OrdinalIgnoreCase) == 0)
133+
{
134+
string javaOutDirectory = Path.Combine(childDir.FullName, "java");
135+
if (Directory.Exists(javaOutDirectory))
136+
{
137+
info = childDir;
138+
continueTraversal = false;
139+
break;
140+
}
141+
}
141142
}
142-
}
143143

144-
if (continueTraversal)
145-
{
146-
info = info.Parent;
144+
if (continueTraversal)
145+
{
146+
info = info.Parent;
147+
}
147148
}
148-
}
149149

150-
projectRoot = info.FullName;
151-
}
152-
else
153-
{
154-
projectRoot += "/_main";
155-
}
156-
157-
// Find selenium-manager binary.
158-
try
159-
{
160-
string managerFilePath = "";
161-
runfiles ??= Runfiles.Create();
162-
163-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
150+
projectRoot = info.FullName;
151+
}
152+
else
164153
{
165-
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/windows/selenium-manager.exe");
154+
projectRoot += "/_main";
166155
}
167-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
156+
157+
// Find selenium-manager binary.
158+
try
168159
{
169-
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/linux/selenium-manager");
160+
string managerFilePath = "";
161+
runfiles ??= Runfiles.Create();
162+
163+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
164+
{
165+
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/windows/selenium-manager.exe");
166+
}
167+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
168+
{
169+
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/linux/selenium-manager");
170+
}
171+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
172+
{
173+
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/macos/selenium-manager");
174+
}
175+
176+
System.Environment.SetEnvironmentVariable("SE_MANAGER_PATH", managerFilePath);
170177
}
171-
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
178+
catch (FileNotFoundException)
172179
{
173-
managerFilePath = runfiles.Rlocation("_main/dotnet/src/webdriver/manager/macos/selenium-manager");
180+
// Use the default one.
174181
}
175182

176-
System.Environment.SetEnvironmentVariable("SE_MANAGER_PATH", managerFilePath);
177-
}
178-
catch (FileNotFoundException)
179-
{
180-
// Use the default one.
181-
}
182-
183183
WebServer = new TestWebServer(projectRoot, webServerConfig);
184184
bool autoStartRemoteServer = false;
185185
if (Browser == Browser.Remote)
@@ -197,25 +197,25 @@ private EnvironmentManager()
197197
CloseCurrentDriver();
198198
}
199199

200-
public event EventHandler<DriverStartingEventArgs> DriverStarting;
200+
public event EventHandler<DriverStartingEventArgs> DriverStarting;
201201

202202
public static EnvironmentManager Instance => instance ??= new EnvironmentManager();
203203

204204
public Browser Browser { get; }
205205

206-
public string CurrentDirectory
207-
{
208-
get
206+
public string CurrentDirectory
209207
{
210-
string assemblyLocation = Path.GetDirectoryName(typeof(EnvironmentManager).Assembly.Location);
211-
string testDirectory = TestContext.CurrentContext.TestDirectory;
212-
if (assemblyLocation != testDirectory)
208+
get
213209
{
214-
return assemblyLocation;
210+
string assemblyLocation = Path.GetDirectoryName(typeof(EnvironmentManager).Assembly.Location);
211+
string testDirectory = TestContext.CurrentContext.TestDirectory;
212+
if (assemblyLocation != testDirectory)
213+
{
214+
return assemblyLocation;
215+
}
216+
return testDirectory;
215217
}
216-
return testDirectory;
217218
}
218-
}
219219

220220
public TestWebServer WebServer { get; }
221221

@@ -230,34 +230,34 @@ public IWebDriver GetCurrentDriver()
230230
return driver ?? CreateFreshDriver();
231231
}
232232

233-
public IWebDriver CreateDriverInstance()
234-
{
235-
return driverFactory.CreateDriver(driverType);
236-
}
233+
public IWebDriver CreateDriverInstance()
234+
{
235+
return driverFactory.CreateDriver(driverType);
236+
}
237237

238-
public IWebDriver CreateDriverInstance(DriverOptions options)
239-
{
240-
return driverFactory.CreateDriverWithOptions(driverType, options);
241-
}
238+
public IWebDriver CreateDriverInstance(DriverOptions options)
239+
{
240+
return driverFactory.CreateDriverWithOptions(driverType, options);
241+
}
242242

243-
public IWebDriver CreateFreshDriver()
244-
{
245-
CloseCurrentDriver();
246-
driver = CreateDriverInstance();
247-
return driver;
248-
}
243+
public IWebDriver CreateFreshDriver()
244+
{
245+
CloseCurrentDriver();
246+
driver = CreateDriverInstance();
247+
return driver;
248+
}
249249

250250
public void CloseCurrentDriver()
251251
{
252252
driver?.Quit();
253253
driver = null;
254254
}
255255

256-
protected void OnDriverStarting(object sender, DriverStartingEventArgs e)
257-
{
258-
if (this.DriverStarting != null)
256+
protected void OnDriverStarting(object sender, DriverStartingEventArgs e)
259257
{
260-
this.DriverStarting(sender, e);
258+
if (this.DriverStarting != null)
259+
{
260+
this.DriverStarting(sender, e);
261+
}
261262
}
262263
}
263-
}

0 commit comments

Comments
 (0)