Skip to content

Instantly share code, notes, and snippets.

@rippo
Created November 7, 2013 15:29
Show Gist options
  • Save rippo/7356507 to your computer and use it in GitHub Desktop.
Save rippo/7356507 to your computer and use it in GitHub Desktop.
Ugly hack to try and stop KeepAliveFailure exceptions
public class BaseClass
{
public SessionConfiguration sessionConfiguration;
public static string Host = "http://localhost";
public static string PhantomPath;
public static int Port = 53222;
public BaseClass()
{
PhantomPath = ConfigurationManager.AppSettings[Environment.MachineName + "-BinPhysicalPath"];
sessionConfiguration = new SessionConfiguration
{
AppHost = Host,
Port = Port,
Driver = typeof(CustomPhantomJsDriver),
Browser = Browser.PhantomJS,
};
}
}
public class CustomPhantomJsDriver : SeleniumWebDriver
{
public CustomPhantomJsDriver(Browser browser)
: base(CustomProfileDriver(), browser)
{
}
private static RemoteWebDriver CustomProfileDriver()
{
var phantomPath = ConfigurationManager.AppSettings[Environment.MachineName + "-BinPhysicalPath"];
var service = PhantomJSDriverService.CreateDefaultService(phantomPath);
//service.LoadImages = false;
//Ugly Hack start
RemoteWebDriver Instance = null;
const int maxRetries = 40;
const int postRetryWaitms = 100;
var retries = 0;
while (Instance == null && retries++ < maxRetries)
{
try
{
Instance = new PhantomJSDriver(service);
}
catch (Exception)
{
if (retries == maxRetries) throw;
Thread.Sleep(postRetryWaitms);
}
}
return Instance;
//Ugly Hack end
//return new PhantomJSDriver(service);
}
}
[TestClass]
public class when_testing_the_logged_out_pages_then : BaseClass
{
[TestMethod]
public void test_visitor_cant_make_meeting_with_please_invite_me_to_another_meeting_checked()
{
using (var browser = new BrowserSession(sessionConfiguration))
{
browser.Visit("/someurl/12");
browser.Check("InviteMeToAnotherClub");
browser.FindId("btnNext").Click();
Assert.IsTrue(browser.HasContent("Apology logged"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment