Skip to content

Instantly share code, notes, and snippets.

@stirno
Last active October 5, 2016 11:47
Show Gist options
  • Save stirno/8339678 to your computer and use it in GitHub Desktop.
Save stirno/8339678 to your computer and use it in GitHub Desktop.
Sample of FluentAutomation page objects, round 1
namespace FluentAutomation.Tests
{
public class BingSearchPage : PageObject<BingSearchPage>
{
public BingSearchPage(FluentTest test)
: base(test)
{
Url = "http://bing.com/";
At = () => I.Expect.Exists(SearchInput);
}
public BingSearchResultsPage Search(string searchText)
{
I.Enter(searchText).In(SearchInput);
I.Press("{ENTER}");
return this.Switch<BingSearchResultsPage>();
}
private const string SearchInput = "input[title='Enter your search term']";
}
public class BingSearchResultsPage : PageObject<BingSearchResultsPage>
{
public BingSearchResultsPage(FluentTest test)
: base(test)
{
At = () => I.Expect.Exists(SearchResultsContainer);
}
public BingSearchResultsPage FindResultUrl(string url)
{
I.Expect.Exists(string.Format(ResultUrlLink, url));
return this;
}
private const string SearchResultsContainer = "#b_results";
private const string ResultUrlLink = "a[href='{0}']";
}
[TestClass]
public class SampleTest : FluentTest
{
public SampleTest()
{
FluentAutomation.Settings.DefaultWaitUntilTimeout = TimeSpan.FromMilliseconds(1500);
SeleniumWebDriver.Bootstrap(SeleniumWebDriver.Browser.Chrome);
}
[TestMethod]
public void SearchForFluentAutomation()
{
new BingSearchPage(this)
.Go()
.Search("FluentAutomation")
.FindResultUrl("http://fluent.stirno.com/blog/FluentAutomation-scriptcs/");
}
}
}
@stirno
Copy link
Author

stirno commented Jan 10, 2014

At/Url are intended to be optional (and on the base class, yes). By setting URL, the Go() function can navigate the browser instance to the page. If At is set, it will automatically verify you've reached the page otherwise the test continues. It basically works by checking that no exception throws so its expected that either an action or expect is done inside the func.

@marcusoftnet
Copy link

Ah - nice! Press on with this! I think it looks very promising and useful.
Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment