Created
May 6, 2015 19:58
-
-
Save mauricedb/8b3a418eb15f0d469cb6 to your computer and use it in GitHub Desktop.
CodedUIWithPageObjectModel
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
using Microsoft.VisualStudio.TestTools.UITesting; | |
using Microsoft.VisualStudio.TestTools.UITesting.HtmlControls; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
namespace CodedUITestProject1 | |
{ | |
[CodedUITest] | |
public class CodedUIWithPageObjectModel | |
{ | |
[TestMethod] | |
public void DAMP_Searching_for_kill_bill_and_clicking_should_open_editor() | |
{ | |
var moviesAdminEdit = Browser | |
.MoviesAdminList() | |
.SearchForAndClickOn("Kill Bill, Volume 2"); | |
Assert.AreEqual("89", moviesAdminEdit.GetAudienceScore()); | |
Assert.AreEqual("84", moviesAdminEdit.GetCriticsScore()); | |
} | |
[TestMethod] | |
public void DAMP_Searching_for_alien_and_clicking_should_open_editor() | |
{ | |
var moviesAdminEdit = Browser | |
.MoviesAdminList() | |
.SearchForAndClickOn("alien"); | |
Assert.AreEqual("94", moviesAdminEdit.GetAudienceScore()); | |
Assert.AreEqual("97", moviesAdminEdit.GetCriticsScore()); | |
} | |
} | |
class Browser | |
{ | |
public static MoviesAdminList MoviesAdminList() | |
{ | |
BrowserWindow.CurrentBrowser = "Chrome"; | |
var browser = BrowserWindow.Launch("http://rawstack.azurewebsites.net/MoviesAdmin"); | |
//browser.CloseOnPlaybackCleanup = false; | |
return new MoviesAdminList(browser); | |
} | |
} | |
class MoviesAdminList | |
{ | |
private readonly BrowserWindow _browser; | |
public MoviesAdminList(BrowserWindow browser) | |
{ | |
_browser = browser; | |
var ajaxBusyIndicator = new HtmlControl(_browser); | |
//Playback.PlaybackSettings.WaitForReadyLevel = WaitForReadyLevel.Disabled; | |
//Playback.Wait(100); | |
//ajaxBusyIndicator.SearchProperties.Add(HtmlControl.PropertyNames.Class, "ajax-busy-indicator"); | |
//ajaxBusyIndicator.WaitForControlNotExist(); | |
} | |
public MoviesAdminEdit SearchForAndClickOn(string title) | |
{ | |
var search = new HtmlEdit(_browser); | |
//search.FilterProperties.Add("ng-model", "filterOptions.filterText"); | |
Keyboard.SendKeys(search, title); | |
var row = new HtmlControl(_browser); | |
row.SearchProperties.Add(HtmlControl.PropertyNames.Class, "ngCellText ng-scope col0 colt0"); | |
Mouse.Click(row); | |
return new MoviesAdminEdit(_browser); | |
} | |
} | |
class MoviesAdminEdit | |
{ | |
private readonly BrowserWindow _browser; | |
public MoviesAdminEdit(BrowserWindow browser) | |
{ | |
_browser = browser; | |
} | |
public string GetAudienceScore() | |
{ | |
var audienceScore = new HtmlEdit(_browser); | |
audienceScore.SearchProperties.Add(HtmlControl.PropertyNames.Id, "audienceScore"); | |
return audienceScore.Text; | |
} | |
public string GetCriticsScore() | |
{ | |
var audienceScore = new HtmlEdit(_browser); | |
audienceScore.SearchProperties.Add(HtmlControl.PropertyNames.Id, "criticsScore"); | |
return audienceScore.Text; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment