NPageObject
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:A simple UI test wrapper and DSL.
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:

```C#

public class LoginPage : PageObject
{       
	public override UriExpectation UriExpectation {
		get { return new UriExpectation { UriContentsRelativeToRoot = "/", Match = UriMatch.Exact }; }
	}

	public override string IdentifyingText { get { return "Example identifying text" } }

	public IElementOn UsernameTextField 	{
		get { return new ElementOn(Context, selector: "#username"); }
	}

	public IElementOn PasswordTextField {
		get { return new ElementOn(Context, selector: "#password"); }
	}

	public IElementOn LoginButton {
		get { return new ElementOn(Context, selector: "#loginButton"); }
	}
}


[TestClass]
public class ExampleTest
{
	private SeleniumUITestContext _context;

	[SetUp]
	public void Setup() { /* ... */ }

	[TestMethod]
	public void GivenAValidUser_WhenIEnterCredentialsAndClickLogin_ThenIAmLoggedIn()
	{
		var page = _context.NavigateTo()
							  .UsernameTextField
							  .InputText("username")
							  .PasswordTextField
							  .InputText("password")
							  .LoginButton
							  .ClickWithNavigation();

		Assert.That(page.MatchesActualBrowserLocation());
	}
}


```

If NPageObject helps you or your team develop great software please [let me know](mailto:ben@bj.ma "Ben's email address")! 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**

```shell
	nuget install npageobject	
```

**1. Define a page object**

For example:

```C#

public class LoginPage : PageObject
{       
	public override UriExpectation UriExpectation {
		get { return new UriExpectation { UriContentsRelativeToRoot = "/", Match = UriMatch.Exact }; }
	}

	public override string IdentifyingText { get { return "Example identifying text" } }

	public IElementOn UsernameTextField 	{
		get { return new ElementOn(Context, selector: "#username"); }
	}

	public IElementOn PasswordTextField {
		get { return new ElementOn(Context, selector: "#password"); }
	}

	public IElementOn LoginButton {
		get { return new ElementOn(Context, selector: "#loginButton"); }
	}
}

```


**2. Initialize NPageObject in your test setup**

For example:

```C#

[TestClass]
public class ExampleTest
{
	private SeleniumUITestContext _context;

	[SetUp]
	public void Setup() { 
		var driver = new ChromeDriver();
		var domChecker = new SeleniumDomChecker(driver, 5.Seconds());
		var browserActionPerformer = new SeleniumBrowserActionPerformer(driver, 
																		domChecker,
																		isInDemonstrationMode: false, //slows down UI actions for demonstrations
																		uriRoot: "www.example.com", 
																		elementSelectionTimeout: 5.Seconds());
		_context = new SeleniumUITestContext(driver,
														browserActionPerformer,
														domChecker,
														uriRoot: "www.example.com");
	}
}

```


**3. Write your test**

For example:

```C#

	[Test]
	public void GivenAValidUser_WhenIEnterCredentialsAndClickLogin_ThenIAmLoggedIn()
	{
		var page = _context.BrowseTo()
							  .UsernameTextField
							  .InputText("sdkubdf")
							  .PasswordTextField
							  .InputText("password")
							  .LoginButton
							  .ClickWithNavigation();

		Assert.That(page.MatchesActualBrowserLocation());
	}
	
```

How to build and/or run the tests:
--------

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

![Alt text](./how-it-works.png "How NPageObject works")

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](https://d2weczhvl823v0.cloudfront.net/benaston/NPageObject/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。