This is a migrated thread and some comments may be shown as answers.

System.Nullrefence exception

5 Answers 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Siva
Top achievements
Rank 1
Siva asked on 14 Aug 2012, 08:34 PM
Here is my Table on the webpage

<table border="0" cellpadding="1">
    <tr bgcolor="#aaddff">
        <th>Utility </th>
        <th>Program Name </th>
        <th>Description </th>
        <th>Valid From </th>
        <th>Valid To </th>
        <th>Actions </th>
    </tr>
    <tr bgcolor="#ebfae8">
        <td><strong>Test_Utility </strong></td>
        <td><strong>CBP_With_Bidding </strong></td>
        <td>CBP_DR </td>
        <td>8/14/2012 </td>
        <td>8/21/2012 </td>
        <td align="center">
        <div class="actionButton">
            <a href="/OpenADR/EditDRProgram/2">Edit</a><a href="/OpenADR/DisplayDRProgram/2">Details</a><a href="/OpenADR/DeleteDRProgram/2">Delete</a></div>
        </td>
    </tr>
    <tr>
        <td colspan="5"></td>
        <td align="center">
        <div class="actionButton">
            <a href="/OpenADR/CreateDRProgram">Add New DR Program</a></div>
        </td>
    </tr>
</table>

I want to make a click in edit button

[CodedStep(@"Click 'EditLink'")]
public void CodedStep1()
{
    HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex = table:0", "TagName=table");
    HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=~Test_utility", "tagname=tr");
    HtmlTableCell cell = row.Cells[5];
    HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~Edit", "tagname=a");
    a.Click();
    // Click 'EditLink'
    // Pages.HttpLocalhost8080OpenADR5.EditLink.Click(false);
}

When I do the Quick Execute, It Passed and I can see the Corresponding Page
If I run From TestList

I'm getting this error

Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[SWR123_Edit_DR_Program_CodedStep2] : @"Click 'Edit DR Program ''.
InnerException:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.ThrowHelper.ThrowArgumentOutOfRangeException()
at System.Collections.Generic.List`1.get_Item(Int32 index) 

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 17 Aug 2012, 09:07 PM
Hi,

I apologize for the delay getting back to you.

I took your sample table, put it into a test page then created a test and test list using it. I am not able to reproduce this problem. This leads me to believe it must be something unique to your application. It could be a timing issue i.e. the data is not yet fully populated in that table at the time you are trying to interact with it. We can wait for the cell count to be 6 like this:

[CodedStep(@"Click 'EditLink'")]
        public void CodedStep1()
        {
            HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex=table:0", "TagName=table");
            HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=~Test_utility", "tagname=tr");
            Manager.Wait.For<HtmlTableRow>(r => r.Cells.Count == 6, row, 10000);
            HtmlTableCell cell = row.Cells[5];
            HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~Edit", "tagname=a");
            a.Click();
            // Click 'EditLink'
            // Pages.HttpLocalhost8080OpenADR5.EditLink.Click(false);
        }

If that doesn't help can we get direct access to your application so we can reproduce this problem?

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Siva
Top achievements
Rank 1
answered on 22 Aug 2012, 03:18 PM
Hi Codi
Thank you for your Reply

Manager.Wait.For<HtmlTableRow>(r => r.Cells.Count == 6, row, 10000);

This line worked for in some places, also did not worked in other "Edit" click

I just used the Wait for exists element on that page, and then Made a "Edit" click this one works all the place.

MAy I know, If i want wait.for.htmaltable, what should i use in predicate
Manager.Wait.For<HtmlTable>(predicate, table, 10000);
what is predicate here, i used "TagIndex=Table:1", Whats is the correct way to use it

I want to try to find the table in that page instead of wait for element

Thanks in Advance
0
Cody
Telerik team
answered on 26 Aug 2012, 10:26 PM
Hi Siva,

Instead of Wait.For you would probably be better off using our FInd object like this:

HtmlTable myTable = ActiveBrowser.Find.ByTagIndex<HtmlTable>("table", 1);

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Siva
Top achievements
Rank 1
answered on 27 Aug 2012, 08:20 PM
Hi Cody

 I still have this null reference exception.
 I have Test1. with this following code

 
  HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex=table:0", "TagName=table");
            // Assert.IsNotNull(table);
            HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=~Test_Utility", "tagname=tr");
            // HtmlTableCell ce = row.Cells[1];
            HtmlTableCell cell = row.Cells[3];
            HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~Details", "tagname=a");
            a.Click();


If I execute this test, I don have Error, at the sametime i need tpo call this test as a step in Test2. If I do the Quick execute , its passed. But in TestList Editor, If i run the Test I'm getting this error.
Failure Information:
~~~~~~~~~~~~~~~
Exception thrown executing coded step: '[SWR119_Create_Utility_CodedStep1] : @"Details Utility'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.
   at com.REGEN.Apps.EnviroGridPortal.IT.Open_ADR.SWR119CreateUtility.SWR119_Create_Utility_CodedStep1() in C:\SVN\Software_trunk\com\REGEN\Apps\EnviroGridPortal\IT\com.REGEN.Apps.EnviroGridPortal.IT\Open_ADR\SWR119_Create_Utility.tstest.cs:line 90
------------------------------------------------------------
'8/27/2012 4:03:52 PM' - Detected a failure. Step is marked 'ContinueOnFailure=False' aborting test execution.


Please give a complete solution for this kind of coded step errors.
0
Cody
Telerik team
answered on 28 Aug 2012, 04:05 PM
Hi Siva,

Until I can see and reproduce this problem i'm not able to offer a ready made guaranteed solution. The error message references line 90, but I have no idea which line of code is line 90, can you point this out to me?

To really investigate the root cause can I directly access your application you are testing? Can you send me a test I can execute from here that reproduces this problem? I need the .tstest and matching .resx and .cs/.vb files, including any subtests the main test relies upon.

Greetings,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Siva
Top achievements
Rank 1
Answers by
Cody
Telerik team
Siva
Top achievements
Rank 1
Share this question
or