Last active
August 29, 2015 14:18
-
-
Save davidwhitney/6d9134103bc68bb5409b to your computer and use it in GitHub Desktop.
Passenger webdriver example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TestFixture] | |
public class PassengerExample | |
{ | |
private PassengerConfiguration _testConfig; | |
private PageObjectTestContext<AmazonHomepage> _ctx; | |
[SetUp] | |
public void Setup() | |
{ | |
_testConfig = new PassengerConfiguration {WebRoot = "http://www.amazon.co.uk"} | |
.WithDriver(new PhantomJSDriver()); | |
} | |
[TearDown] | |
public void Teardown() | |
{ | |
_ctx.Dispose(); | |
} | |
[Test] | |
public void SearchForChuck() | |
{ | |
_ctx = _testConfig.StartTestAt<AmazonHomepage>(); | |
_ctx.Page<AmazonHomepage>().Navbar.SearchFor("game of thrones"); | |
Assert.That(_ctx.Page<SearchPage>().SearchResults.Any(x => x.Text.Contains("Game of Thrones - Season 4"))); | |
} | |
[Test] | |
public void SearchForGameOfThrones() | |
{ | |
_ctx = _testConfig.StartTestAt<AmazonHomepage>(); | |
_ctx.Page<AmazonHomepage>().Navbar.SearchFor("Chuck"); | |
Assert.That(_ctx.Page<SearchPage>().SearchResults.Any(x => x.Text.Contains("Chuck - Season 1-5 Complete"))); | |
} | |
[TestCase("game of thrones", "Game of Thrones - Season 4")] | |
[TestCase("Chuck", "Chuck - Season 1-5 Complete")] | |
public void TestCasesAreBetter(string term, string item) | |
{ | |
_ctx = _testConfig.StartTestAt<AmazonHomepage>(); | |
_ctx.Page<AmazonHomepage>().Navbar.SearchFor(term); | |
Assert.That(_ctx.Page<SearchPage>().SearchResults.Any(x => x.Text.Contains(item))); | |
} | |
} | |
[Uri("/")] | |
public class AmazonHomepage | |
{ | |
public virtual NavigationBar Navbar { get; set; } | |
} | |
[PageComponent] | |
public class NavigationBar | |
{ | |
protected virtual RemoteWebDriver Driver { get; set; } | |
[Id("twotabsearchtextbox")] | |
public virtual IWebElement SearchBox { get; set; } | |
[CssSelector(".nav-submit-button input")] | |
public virtual IWebElement SearchSubmit { get; set; } | |
public void SearchFor(string text) | |
{ | |
SearchBox.Click(); | |
Driver.Keyboard.SendKeys(text); | |
SearchSubmit.Click(); | |
} | |
} | |
[Uri("/Blog")] | |
public class SearchPage | |
{ | |
[CssSelector("#s-results-list-atf")] | |
public virtual IEnumerable<IWebElement> SearchResults { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment