xUnit
Selenium WebDriver
PhantomJsDriver
GhostDriver
PhantomJs
drives
implemented by
binds to
implements
[Fact]
public void CanConnectToGoogle()
{
using (var driver = new PhantomJSDriver())
{
driver.Navigate()
.GoToUrl("https://www.google.com");
Assert.Contains("//www.google.com", driver.Url);
}
}
[Fact]
public void CanRenderSearchButton()
{
using (var driver = new PhantomJSDriver())
{
driver.Navigate()
.GoToUrl("https://www.google.com");
var wait = new WebDriverWait(
driver,
TimeSpan.FromSeconds(60));
var input = wait.Until(
ExpectedConditions.ElementExists(
By.CssSelector(
"[type=submit]")));
input.Click();
Assert.True(/*...*/);
}
}xUnit's TheoryAttribute allows parameterized tests
[Fact]
public void CanConnectToGoogle()
{
using (var driver = new PhantomJSDriver())
{
driver.Navigate()
.GoToUrl("https://www.google.com");
Assert.Contains("//www.google.com", driver.Url);
}
}
[Theory]
[InlineData("www.google.com")]
[InlineData("www.microsoft.com")]
[InlineData("www.google.co.uk")]
public void CanConnectTo(string url)
{
using (var driver = new PhantomJSDriver())
{
driver.Navigate()
.GoToUrl("http://" + url);
Assert.Contains("//" + url, driver.Url);
}
}Touch the IWebDriver
Maybe, maybe not. Browser testing needs to find a balance between different goals:
BrowserTestBase, persistent login sessions, and driver encapsulation are evolving strategies to find the right balance. If they turn out to be more cumbersome than they're worth, we'll move beyond them.