Hello!
I first want to say that your NUnitAsp ROCKS! My staff
thought that my suggestion to go to NUnitAsp was a
waste of time until I built a random dropdown list
selector for our reporting pages.. Within 8 hours (I had
to learn the program) I had uncovered 3 bugs in our
system that no one knew about. Needless to say, we
are now adopting this as a standard. Way to go!
As a newbie, I am trying to grab a button from a
datagrid and click it. My code is:
Dim row As DataGridTester.Row
row = grd1.GetRowByCellValue(1, "Larry")
Dim btnRemove As New ButtonTester
("Remove", row)
btnRemove.Click()
When I run it, I get an exeption.
Couldn't find grd1_ct13_Remove on ' '
When I look at the source of the HTML, the remove
button is at:
<a href="javascript:__doPostBack('grd1$_ctl3$_ctl0','')"
style="color:Blue;">Remove</a>
Which is really close, but not right. What am I doing
wrong?
Larry Piegza
Logged In: YES
user_id=1295028
In addition, I keep getting the error if I try
Dim btnRemove as new buttontester('_ctl0',row)
instead.
All of the code on the web indicates that a template column
is much simper to use because you can assign an "id"
attribute to it. Are templatecolumns the only way?
larry@onlinecourseevaluations.com
Logged In: YES
user_id=499667
Larry, thanks for your glowing remarks. :-)
I think your problem is that the button you're trying to
test has no ID. To help, I'll need to see the ASP.NET code.
Can you post it?
Cheers,
Jim
Logged In: YES
user_id=1295028
Thanks for responding so quickly, Jim. Here is my NUnitAsp
code:
<Test()> Public Sub CheckToBeCCD()
Browser.GetPage
("http://larry.onlinecourseevaluations.com/ToBeCCd.aspx")
Dim grd1 As New DataGridTester("grd1",
currentwebform)
AssertVisibility(grd1, True)
Dim btnRemove As New ButtonTester("_ctl0",
grd1.GetRow(0))
btnRemove.Click()
End Sub
And here is the codebehind of the page.
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
Session("Schoolid") = 10
If Not Page.IsPostBack Then
filldatagrid()
End If
End Sub
Sub grdQuestions_OnItemDataBound(ByVal s As Object,
ByVal e As DataGridItemEventArgs)
End Sub
Sub filldatagrid()
Dim sql As String
sql = "select email from tblExtraEmailNotifications
where SchoolID = 10"
Dim sqc As New SqlClient.SqlCommand(sql)
DoSql.DataBind(grd1, sqc) ' creates a datareader and
assigns it to the datagrid.
End Sub
Private Sub btnAdd_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnAdd.Click
Dim sql As String
sql = "Insert tblExtraEmailNotifications (SchoolID,
Email) Values (10, @EmailText)"
Dim sqc As New SqlClient.SqlCommand(sql)
DoSql.addVarChar(sqc, "@EmailText", txt8.Text)
DoSql.ExecuteNonQuery(sqc)
txt8.Text = ""
filldatagrid()
End Sub
Sub eventemailClicked(ByVal sender As Object, ByVal e
As DataGridCommandEventArgs)
Dim buttonColumn As TableCell = e.Item.Cells(1)
Dim sql As String
sql = "delete tblExtraEmailNotifications where email =
@EmailID"
Dim sqc As New SqlClient.SqlCommand(sql)
DoSql.addVarChar(sqc, "@EmailID",
buttonColumn.Text)
DoSql.ExecuteNonQuery(sqc)
filldatagrid()
End Sub
Here is the HTML of the datagrid:
<asp:datagrid
id="grd1" runat="server"
OnItemCommand="eventemailClicked"
OnItemDataBound="grdQuestions_OnItemDataBound">
<Columns>
<asp:ButtonColumn Text="Remove"
CommandName="Delete">
<ItemStyle
ForeColor="Blue"></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid>
and the real application can be viewed on my test site at:
http://larry.onlinecourseevaluations.com/ToBeCCd.aspx
In advance, thanks for your help!
Logged In: YES
user_id=499667
Another case, from Cory Foy:
I am running into a problem trying to test an Edit button in
my DataGrid. I build the grid with this code:
<asp:DataGrid ID="CostCodeGrid" Runat="server"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn HeaderText="Cost Code"
DataField="Code" ReadOnly="True" />
<asp:BoundColumn HeaderText="English Description"
DataField="EnglishDescription" />
<asp:BoundColumn HeaderText="Spanish Description"
DataField="SpanishDescription" />
<asp:EditCommandColumn EditText="Edit Info"
ButtonType="PushButton" UpdateText="Update"
CancelText="Cancel" />
</Columns>
</asp:DataGrid>
and I am testing it with:
string[][] rows = costCodeGrid.TrimmedCells;
int currentRow = 1;
foreach(string[] row in rows)
{
//...
if(currentRow > 1)
{
//Check for Edit button
DataGridTester.Row editRow =
costCodeGrid.GetRow(currentRow-1);
ButtonTester editButton = new ButtonTester("_ctl0",
editRow);
AssertVisibility(editButton, true);
}
currentRow++;
}
Which is failing with:
_ctl0 control should be visible (HTML ID:
CostCodeGrid__ctl3__ctl0; ASP location: ButtonTester '_ctl0'
in Row '2' in DataGridTester 'CostCodeGrid' in web form 'Form1')
Which has to be the problem because the HTML generated looks
like (for the first row after the header):
[input name="CostCodeGrid:_ctl2:_ctl0" value="Edit Info"
type="submit"]
Any hints as to what could be going wrong here?
Cory