public void CreateAccount() { // use the ViewAccounts page to create a new account. // This shows how to interact with the asp form, but also // that testing the ASPX page doesn't have as much value // as you might think. #region some constants const string newName = "Testing Account"; const string newBalance = "1234"; #endregion #region set up the page LoadPage("viewaccounts.aspx"); TextBoxTester txtName = new TextBoxTester("txtName", CurrentWebForm); TextBoxTester txtBalance = new TextBoxTester("txtBalance", CurrentWebForm); ButtonTester btnCreate = new ButtonTester("btnCreate", CurrentWebForm); #endregion #region fill in some data & submit form txtName.Text = newName; txtBalance.Text = newBalance; btnCreate.Click(); #endregion #region Datagrid - did it work? // the page has refreshed -- // see if our new account is in the grid. DataGridTester grdAccounts = new DataGridTester( "grdAccounts", CurrentWebForm); // the last row is the newest one: DataGridTester.Row newRow = grdAccounts.GetRow(grdAccounts.RowCount - 1); // first cell is account id, 2nd is account name // name should be the same as the value we just saved... Assert("New account wasn't last in the grid", newRow.TrimmedCells[1] == newName); #endregion #region teardown // delete the account we just created. AccountFactory.DeleteAccount(int.Parse(newRow.TrimmedCells[0])); #endregion }
public void TestGoToPageIndex() { // First, instantiate "Tester" objects: ButtonTester buttonLogin = new ButtonTester("ButtonLogin", CurrentWebForm); ButtonTester button= new ButtonTester("Button", CurrentWebForm); Browser.GetPage("http://localhost/Castle.MVC.Test.Web/Views/index.aspx"); string loginPage = this.Browser.CurrentUrl.AbsoluteUri.ToString(); buttonLogin.Click(); button.Click(); string currentPage = this.Browser.CurrentUrl.AbsoluteUri.ToString(); Assert(currentPage, loginPage.ToLower() == currentPage.ToLower()); }
public void TestGoToPage2WithButtonLogin() { // First, instantiate "Tester" objects: ButtonTester buttonLogin = new ButtonTester("ButtonLogin", CurrentWebForm); LabelTester labelTester = new LabelTester("LabelPreviousView", CurrentWebForm); // Second, visit the page being tested: Browser.GetPage("http://localhost/Castle.MVC.Test.Web/Views/index.aspx"); string loginPage = this.Browser.CurrentUrl.AbsoluteUri.ToString(); buttonLogin.Click(); string currentPage = this.Browser.CurrentUrl.AbsoluteUri.ToString(); Assert(currentPage, loginPage != currentPage); AssertEquals("index", labelTester.Text); }
public void TestButtonClickInRepeater() { ButtonTester button1 = new ButtonTester("Button1", CurrentWebForm); LabelTester label1 = new LabelTester("Label1", CurrentWebForm); button1.Click(); ButtonTester innerButton1 = new ButtonTester("btnInner", repeater3.Item(0)); ButtonTester innerButton2 = new ButtonTester("btnInner", repeater3.Item(1)); innerButton1.Click(); Assert.AreEqual("Thing 1", label1.Text); innerButton2.Click(); Assert.AreEqual("Thing 2", label1.Text); }
public void Test01MemberListPage() { Console.WriteLine("Before Test01MemberListPage"); _dnarequest.SetCurrentUserEditor(); _dnarequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/MemberList"; _dnarequest.RequestNUnitASPPage(relativePath, Browser); TextBoxTester entry = new TextBoxTester("txtEntry", CurrentWebForm); Assert.AreEqual(entry.Visible, true); entry.Text = "1090558354"; RadioButtonListTester radiolist = new RadioButtonListTester("rdSearchType"); Assert.AreEqual(radiolist.Visible, true); radiolist.SelectedIndex = 0; ButtonTester search = new ButtonTester("Search", CurrentWebForm); search.Click(); LabelTester err = new LabelTester("lblError",CurrentWebForm); Assert.AreNotEqual("Insufficient permissions - Editor Status Required", err.Text); Console.WriteLine("After Test01MemberListPage"); }
public void Test08MemberListSearchByBBCUIDPage() { Console.WriteLine("Before Test08MemberListSearchByBBCUIDPage"); _dnarequest.SetCurrentUserEditor(); _dnarequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/MemberList"; _dnarequest.RequestNUnitASPPage(relativePath, Browser); TextBoxTester entry = new TextBoxTester("txtEntry", CurrentWebForm); Assert.AreEqual(entry.Visible, true); entry.Text = "47C7CDBE-9D79-1517-50CA-0003BA0B17ED"; RadioButtonListTester radiolist = new RadioButtonListTester("rdSearchType", CurrentWebForm); Assert.AreEqual(radiolist.Visible, true); int index = GetSelectedIndex(radiolist, "BBCUID"); radiolist.SelectedIndex = index; ButtonTester search = new ButtonTester("Search", CurrentWebForm); search.Click(); Console.WriteLine("After Test08MemberListSearchByBBCUIDPage"); }
public void Test05MemberListSearchByEmailPage() { Console.WriteLine("Before Test05MemberListSearchByEmailPage"); _dnarequest.SetCurrentUserEditor(); _dnarequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/MemberList"; _dnarequest.RequestNUnitASPPage(relativePath, Browser); CurrentWebForm.Variables.Add("d_identityuserid", "dotneteditor"); TextBoxTester entry = new TextBoxTester("txtEntry", CurrentWebForm); Assert.AreEqual(entry.Visible, true); entry.Text = "*****@*****.**"; RadioButtonListTester radiolist = new RadioButtonListTester("rdSearchType", CurrentWebForm); Assert.AreEqual(radiolist.Visible, true); int index = GetSelectedIndex(radiolist, "Email"); radiolist.SelectedIndex = index; ButtonTester search = new ButtonTester("Search", CurrentWebForm); search.Click(); HtmlTableTester table = new HtmlTableTester("tblResults"); bool found = false; if (table.BodyNoTags != "No data for those details") { for (int i = 1; i < table.Rows.Length; i++) { HtmlTagTester htmltag = (HtmlTagTester)table.Rows[i].Children("td").GetValue(1); string userID = htmltag.InnerHtml; string testSuperUserIDLink = "<a href=\"/dna/moderation/MemberDetails?userid=" + testSuperUserID.ToString() + "\">U" + testSuperUserID.ToString() + "</a>"; if (userID == testSuperUserIDLink) { found = true; } } Assert.IsTrue(found, "User " + testSuperUserID.ToString() + ": Not returned and displayed in Member List Page."); } else { Assert.IsTrue(false, "Error no results returned."); } Console.WriteLine("After Test05MemberListSearchByEmailPage"); }
public void Test05RestrictedUsersListSearchByMostRecentPage() { try { DnaTestURLRequest dnaRequest = new DnaTestURLRequest("haveyoursay"); Console.WriteLine("Before Test05RestrictedUsersListSearchByMostRecentPage"); dnaRequest.SetCurrentUserEditor(); dnaRequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/RestrictedUsers"; dnaRequest.RequestNUnitASPPage(relativePath, Browser); ButtonTester mostRecent = new ButtonTester("btnMostRecent", CurrentWebForm); mostRecent.Click(); HtmlTableTester table = new HtmlTableTester("tblResults"); bool isdata = true; if (table.BodyNoTags != "No data for those details") { isdata = false; } Assert.IsTrue(isdata, "No data for Most Recent accounts is returned when there should be at least one."); Console.WriteLine("After Test05RestrictedUsersListSearchByMostRecentPage"); } catch (Exception ex) { Console.WriteLine("EXCEPTION"); Console.WriteLine(ex.Message); } }
public void Test04RestrictedUserListPageSearchByBeginsWithLetterTest() { try { DnaTestURLRequest dnaRequest = new DnaTestURLRequest("h2g2"); Console.WriteLine("Before Test04RestrictedUserListPageSearchByBeginsWithLetterTest"); dnaRequest.SetCurrentUserEditor(); dnaRequest.UseEditorAuthentication = true; string relativePath = @"/dna/h2g2/RestrictedUsers"; dnaRequest.RequestNUnitASPPage(relativePath, Browser); System.Threading.Thread.Sleep(2000); DropDownListTester siteList = new DropDownListTester("SiteList"); Assert.AreEqual(siteList.Visible, true); siteList.Items.FindByText("All").Selected = true; DropDownListTester userStatusTypes = new DropDownListTester("UserStatusTypes"); Assert.AreEqual(userStatusTypes.Visible, true); userStatusTypes.Items.FindByText("Both").Selected = true; Console.WriteLine("Before Button creation"); ButtonTester btnD = new ButtonTester("btnD", CurrentWebForm); Console.WriteLine("Before Button click"); btnD.Click(); System.Threading.Thread.Sleep(2000); Console.WriteLine("Before get table"); HtmlTableTester table = new HtmlTableTester("tblResults"); bool isdata = true; if (table.BodyNoTags != "No data for those details") { isdata = false; } Console.WriteLine("After get table"); Assert.IsTrue(isdata, "No data for All accounts is returned when there should be at least one."); Console.WriteLine("After Test04RestrictedUserListPageSearchByBeginsWithLetterTest"); } catch (Exception ex) { Console.WriteLine("EXCEPTION"); Console.WriteLine(ex.Message); } }
public void TestSelectedIndexChangedEvent_WhenItemAddedToList() { ButtonTester addItem = new ButtonTester("add", CurrentWebForm); autoPostBack.Checked = true; Submit.Click(); addItem.Click(); AssertEquals("No", indexChanged.Text); }
public void TestDynamicListDefinitionForArticles() { Console.WriteLine("TestDynamicListDefinitionForArticles"); //DnaTestURLRequest dnarequest = new DnaTestURLRequest("haveyoursay"); _dnarequest.SetCurrentUserEditor(); _dnarequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/EditDynamicListDefinition"; _dnarequest.RequestNUnitASPPage(relativePath, Browser); TextBoxTester name = new TextBoxTester("txtName", CurrentWebForm); name.Text = "DynamicListForArticle"; DropDownListTester type = new DropDownListTester("cmbType", CurrentWebForm); ListItemTester item = type.Items.FindByValue("ARTICLES"); item.Selected = true; //Create Dynamic List Definiton by clicking update. ButtonTester update = new ButtonTester("btnUpdate", CurrentWebForm); update.Click(); testDynamicListAdmin("DynamicListForArticle"); string xml; int id = 0; getDynamicListDefinitionXML("DynamicListForArticle", out xml, out id); if (id > 0) { _dynamicLists.Add(id, "DynamicListForArticle"); } //Validate the Dynamic list Definition Xml. DnaXmlValidator validator = new DnaXmlValidator(xml, "DynamicListForArticle.xsd"); validator.Validate(); //Bring up the edit page and check it displays the list. relativePath = @"/dna/haveyoursay/EditDynamicListDefinition?id=" + id.ToString(); _dnarequest.RequestNUnitASPPage(relativePath, Browser); TextBoxTester checkname = new TextBoxTester("txtName", CurrentWebForm); string dlistname = checkname.Text; Assert.AreEqual(dlistname, "DynamicListForArticle", "Name does not match"); //Publish the Dynamic List. relativePath = @"/dna/haveyoursay/DynamicListAdmin?activateid=" + id.ToString(); _dnarequest.RequestNUnitASPPage(relativePath, Browser); }
public void TransferAfterSetResult() { TextBoxTester name = new TextBoxTester("name", CurrentWebForm); ButtonTester save = new ButtonTester("save", CurrentWebForm); Browser.GetPage("asptest://localhost/TransferAfterSetResult.aspx"); // Note, that page TransferAfterSetResultSave.aspx has 'EnableViewStateMac="false"' // otherwise ViewState validation will fail on a Server.Transfer during a Postback! save.Click(); string result = Browser.CurrentPageText; Assert.AreEqual("OK", result); }
public void CreateAccountWithBadInput() { // an example of a better test -- // Users report that if you press the Create button without // entering appropriate values, the page gives an error instead // of dealing with things gracefully. // // we fix the problem using validators and need to make sure the // problem doesn't occur in the future. Browser.GetPage("http://localhost/UnitTester/ViewAccounts.aspx"); // no input given -- should be dealt with gracefully. // (not with an error) ButtonTester btnCreate = new ButtonTester("btnCreate", CurrentWebForm); btnCreate.Click(); }
private void RunTest() { TextBoxTester textBox1 = new TextBoxTester("textBox1", CurrentWebForm); TextBoxTester textBox2 = new TextBoxTester("textBox2", CurrentWebForm); TextBoxTester textBox3 = new TextBoxTester("textBox3", CurrentWebForm); TextBoxTester textBox4 = new TextBoxTester("textBox4", CurrentWebForm); TextBoxTester textBox5 = new TextBoxTester("textBox5", CurrentWebForm); ButtonTester button = new ButtonTester("button", CurrentWebForm); Browser.GetPage(BaseUrl + "PerformanceTestPage.aspx"); AssertEquals("textBox1", "textBox1", textBox1.Text); AssertEquals("textBox2", "textBox2", textBox2.Text); AssertEquals("textBox3", "textBox3", textBox3.Text); AssertEquals("textBox4", "textBox4", textBox4.Text); AssertEquals("textBox5", "textBox5", textBox5.Text); textBox1.Text = "not 1"; textBox2.Text = "not 2"; textBox3.Text = "not 3"; textBox4.Text = "not 4"; textBox5.Text = "not 5"; button.Click(); AssertEquals("textBox1", "not 1", textBox1.Text); AssertEquals("textBox2", "not 2", textBox2.Text); AssertEquals("textBox3", "not 3", textBox3.Text); AssertEquals("textBox4", "not 4", textBox4.Text); AssertEquals("textBox5", "not 5", textBox5.Text); }