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 }
/// <summary> /// Looks for the given list name in Dynamic List Admin page. /// </summary> /// <param name="listName">Name of List</param> /// <returns></returns> private bool testDynamicListAdmin(string listName) { Console.WriteLine("testDynamicListAdmin"); //DnaTestURLRequest dnarequest = new DnaTestURLRequest("haveyoursay"); _dnarequest.SetCurrentUserEditor(); _dnarequest.UseEditorAuthentication = true; string relativePath = @"/dna/haveyoursay/DynamicListAdmin"; _dnarequest.RequestNUnitASPPage(relativePath, Browser); DataGridTester table = new DataGridTester("tblDynamicLists", CurrentWebForm); bool found = false; for (int i = 0; i < table.RowCount; ++i) { DataGridTester.Row row = table.GetRow(i); string[] cells = row.TrimmedCells; if (cells[0] == listName) { //List Created OK found = true; break; } } Assert.IsTrue(found, "DynamicList has not been created and displayed in DynamicListAdmin."); return found; }