Skip to content

Repository files navigation

NPageObject

A page object framework for .NET. Page objects promote locality of reference, DRY-up your acceptance tests and reduce brittleness. It makes your code more maintainable.

If you like NPageObject, please let others know by sending a tweet (opens a form in a new window to send a tweet).

Example of use:

publicclassLoginPage:PageObject<LoginPage>{publicoverrideUriExpectationUriExpectation{get{returnnewUriExpectation{UriContentsRelativeToRoot="/",Match=UriMatch.Exact};}}publicoverridestringIdentifyingText{get{return"Example identifying text"}}publicIElementOn<LoginPage>UsernameTextField{get{returnnewElementOn<LoginPage>(Context,selector:"#username");}}publicIElementOn<LoginPage>PasswordTextField{get{returnnewElementOn<LoginPage>(Context,selector:"#password");}}publicIElementOn<LoginPage>LoginButton{get{returnnewElementOn<LoginPage>(Context,selector:"#loginButton");}}}[TestClass]publicclassExampleTest{privateSeleniumUITestContext<LoginPage>_context;[SetUp]publicvoidSetup(){/* ... */}[TestMethod]publicvoidGivenAValidUser_WhenIEnterCredentialsAndClickLogin_ThenIAmLoggedIn(){varpage=_context.NavigateTo<LoginPage>().UsernameTextField.InputText("username").PasswordTextField.InputText("password").LoginButton.ClickWithNavigation<HomePage>();Assert.That(page.MatchesActualBrowserLocation());}}

If NPageObject helps you or your team develop great software please let me know! It will help motivate me to develop and improve NPageObject.

How to use:

-1. Check the target framework of your application

It must be .NET Framework 4 (not the Client Profile version - or you might get strange compilation errors.)

0. Get it

	nuget install npageobject	

1. Define a page object

For example:

publicclassLoginPage:PageObject<LoginPage>{publicoverrideUriExpectationUriExpectation{get{returnnewUriExpectation{UriContentsRelativeToRoot="/",Match=UriMatch.Exact};}}publicoverridestringIdentifyingText{get{return"Example identifying text"}}publicIElementOn<LoginPage>UsernameTextField{get{returnnewElementOn<LoginPage>(Context,selector:"#username");}}publicIElementOn<LoginPage>PasswordTextField{get{returnnewElementOn<LoginPage>(Context,selector:"#password");}}publicIElementOn<LoginPage>LoginButton{get{returnnewElementOn<LoginPage>(Context,selector:"#loginButton");}}}

2. Initialize NPageObject in your test setup

For example:

[TestClass]publicclassExampleTest{privateSeleniumUITestContext<LoginPage>_context;[SetUp]publicvoidSetup(){vardriver=newChromeDriver();vardomChecker=newSeleniumDomChecker(driver,5.Seconds());varbrowserActionPerformer=newSeleniumBrowserActionPerformer(driver,domChecker,isInDemonstrationMode:false,//slows down UI actions for demonstrationsuriRoot:"www.example.com",elementSelectionTimeout:5.Seconds());_context=newSeleniumUITestContext<LoginPage>(driver,browserActionPerformer,domChecker,uriRoot:"www.example.com");}}

3. Write your test

For example:

[Test]publicvoidGivenAValidUser_WhenIEnterCredentialsAndClickLogin_ThenIAmLoggedIn(){varpage=_context.BrowseTo<LoginPage>().UsernameTextField.InputText("sdkubdf").PasswordTextField.InputText("password").LoginButton.ClickWithNavigation<HomePage>();Assert.That(page.MatchesActualBrowserLocation());}

How to build and/or run the tests:

  1. Run /build/build.bat
  2. Type in the desired option
  3. Hit return

Alt text

License & Copyright

This software is released under the GNU Lesser GPL. It is Copyright 2013, Ben Aston. I may be contacted at ben@bj.ma.

How to Contribute

Pull requests including bug fixes, new features and improved test coverage are welcomed. Please do your best, where possible, to follow the style of code found in the existing codebase.

Bitdeli Badge

About

A simple UI test wrapper and DSL.

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages