Permalink
Browse files

SpikeSeleniumwebdriver

  • Loading branch information...
1 parent 69e51e4 commit c2f6cbafa72bb12b7fc9517b2a8d41826652f50d @gimmi committed Nov 1, 2011
@@ -25,10 +25,10 @@ public void TearDown()
[Test]
public void Tt()
{
- driver.Navigate().GoToUrl("http://www.google.com");
- IWebElement query = driver.FindElement(By.Name("q"));
- query.SendKeys("Cheese");
- Assert.That(driver.Title, Is.EqualTo("Google"));
+ driver.Url = "http://www.google.com";
+ driver.WaitScript("return !!window.Aplication;");
+
+ Assert.That(driver.ExecuteScript<string>("return document.title;"), Is.EqualTo("Google"));
}
}
}
@@ -56,6 +56,7 @@
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebDriverHelpers.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@@ -0,0 +1,29 @@
+using System;
+using System.Threading;
+using OpenQA.Selenium;
+
+namespace SpikeSeleniumWebdriver
+{
+ public static class WebDriverHelpers
+ {
+ public static void WaitScript(this IWebDriver driver, string script, int timeoutSeconds = 5, params object[] args)
+ {
+ var endTime = DateTime.Now.AddSeconds(timeoutSeconds);
+ while (DateTime.Now < endTime)
+ {
+ var ret = driver.ExecuteScript<object>(script, args);
+ if(ret != null && !false.Equals(ret))
+ {
+ return;
+ }
+ Thread.Sleep(500);
+ }
+ throw new TimeoutException(string.Format("Waiting for script '{0}' timed out after {1} seconds", script, timeoutSeconds));
+ }
+
+ public static T ExecuteScript<T>(this IWebDriver driver, string script, params object[] args)
+ {
+ return (T)((IJavaScriptExecutor)driver).ExecuteScript(script, args);
+ }
+ }
+}

0 comments on commit c2f6cba

Please sign in to comment.