Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SpikeSeleniumwebdriver

  • Loading branch information...
commit c2f6cbafa72bb12b7fc9517b2a8d41826652f50d 1 parent 69e51e4
@gimmi authored
View
8 dotnet/SpikeSeleniumWebdriver/Class1.cs
@@ -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"));
}
}
}
View
1  dotnet/SpikeSeleniumWebdriver/SpikeSeleniumWebdriver.csproj
@@ -56,6 +56,7 @@
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
+ <Compile Include="WebDriverHelpers.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
View
29 dotnet/SpikeSeleniumWebdriver/WebDriverHelpers.cs
@@ -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);
+ }
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.