|
17 | 17 | // </copyright>
|
18 | 18 |
|
19 | 19 | using System;
|
20 |
| -using System.Collections.Generic; |
21 | 20 | using System.Diagnostics;
|
22 | 21 | using System.Globalization;
|
23 | 22 | using System.IO;
|
24 | 23 | using System.Net;
|
25 |
| -using System.Net.Sockets; |
26 | 24 | using System.Security.Permissions;
|
27 |
| -using System.Text; |
28 | 25 | using OpenQA.Selenium.Internal;
|
29 | 26 | using OpenQA.Selenium.Remote;
|
30 | 27 |
|
@@ -181,23 +178,40 @@ public void Start()
|
181 | 178 | this.driverServiceProcess.StartInfo.UseShellExecute = false;
|
182 | 179 | this.driverServiceProcess.StartInfo.CreateNoWindow = this.hideCommandPromptWindow;
|
183 | 180 | this.driverServiceProcess.Start();
|
184 |
| - Uri serviceHealthUri = new Uri(this.ServiceUrl, new Uri("status", UriKind.Relative)); |
| 181 | + Uri serviceHealthUri = new Uri(this.ServiceUrl, new Uri(DriverCommand.Status, UriKind.Relative)); |
185 | 182 | bool processStarted = false;
|
186 | 183 | DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(20));
|
187 | 184 | while (!processStarted && DateTime.Now < timeout)
|
188 | 185 | {
|
189 | 186 | try
|
190 | 187 | {
|
| 188 | + // If the driver service process has exited, we can exit early. |
| 189 | + if (this.driverServiceProcess.HasExited) |
| 190 | + { |
| 191 | + break; |
| 192 | + } |
| 193 | + |
191 | 194 | HttpWebRequest request = HttpWebRequest.Create(serviceHealthUri) as HttpWebRequest;
|
192 | 195 | request.KeepAlive = false;
|
193 | 196 | HttpWebResponse response = request.GetResponse() as HttpWebResponse;
|
| 197 | + |
| 198 | + // Checking the response from the 'status' end point. Note that we are simply checking |
| 199 | + // that the HTTP status returned is a 200 status, and that the resposne has the correct |
| 200 | + // Content-Type header. A more sophisticated check would parse the JSON response and |
| 201 | + // validate its values. At the moment we do not do this more sophisticated check. |
| 202 | + processStarted = response.StatusCode == HttpStatusCode.OK && response.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase); |
194 | 203 | response.Close();
|
195 |
| - processStarted = true; |
196 | 204 | }
|
197 | 205 | catch (WebException)
|
198 | 206 | {
|
199 | 207 | }
|
200 | 208 | }
|
| 209 | + |
| 210 | + if (!processStarted) |
| 211 | + { |
| 212 | + string msg = "Cannot start the driver service on " + this.ServiceUrl; |
| 213 | + throw new WebDriverException(msg); |
| 214 | + } |
201 | 215 | }
|
202 | 216 |
|
203 | 217 | /// <summary>
|
|
0 commit comments