Skip to content

Instantly share code, notes, and snippets.

@stirno
Last active October 5, 2016 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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/");
}
}
}
@marcusoftnet
Copy link

I like the fluent nature of the code in the test. Especially nice when you chain stuff together like this.

When it comes to programming the PageObject objects themselves it looks really nice but I have a bit of a hard time make stuff out without having my studio up and get a feel for it.

What about the At() and the Url-properties... They are on the base class, right? Do they always need to be set? The assertion done at the At() => ... is that always needed?

I think this looks great and will help users of FluentAutomation to write even more robust and clean code.

@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