Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions dotnet/src/webdriver/DriverService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
// </copyright>

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Permissions;
using System.Text;
using OpenQA.Selenium.Internal;
using OpenQA.Selenium.Remote;

Expand Down Expand Up @@ -181,23 +178,39 @@ public void Start()
this.driverServiceProcess.StartInfo.UseShellExecute = false;
this.driverServiceProcess.StartInfo.CreateNoWindow = this.hideCommandPromptWindow;
this.driverServiceProcess.Start();
Uri serviceHealthUri = new Uri(this.ServiceUrl, new Uri("status", UriKind.Relative));
Uri serviceHealthUri = new Uri(this.ServiceUrl, DriverCommand.Status);
bool processStarted = false;
DateTime timeout = DateTime.Now.Add(TimeSpan.FromSeconds(20));
while (!processStarted && DateTime.Now < timeout)
while (DateTime.Now < timeout)
{
try
{
//process is already exited so we don't wait for timeout and suddently exit from loop
if (this.driverServiceProcess.HasExited ||
processStarted)
{
break;
}

HttpWebRequest request = HttpWebRequest.Create(serviceHealthUri) as HttpWebRequest;
request.KeepAlive = false;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// from JsonWireProtocol specs 'status' will return a json obj which has all the properties facultative
// se we validate the response only checking that it's json and that the status is OK
processStarted = (response.StatusCode == HttpStatusCode.OK &&
response.ContentType.StartsWith("application/json", StringComparison.OrdinalIgnoreCase));
response.Close();
processStarted = true;
}
catch (WebException)
{
}
}

if (!processStarted)
{
string msg = "Cannot start the driver service on " + this.ServiceUrl;
throw new WebDriverException(msg);
}
}

/// <summary>
Expand Down