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

Wait for RadGridView to fully load before proceeding to next step?

6 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nick
Top achievements
Rank 1
Nick asked on 24 Mar 2014, 08:14 PM
I am working on a project that is requiring lots of coded steps for various reason.  The coded steps are failing intermittently because they are processing too quickly.  I have added numerous wait.forexists() and wait.fornomotion() throughout, but they don't seem to do what I need.  If I add sleeps throughout, it works, but this is a bad solution.  

The specific scenario I'm having trouble with is after logging in, a grid is created with dynamic header values.  I'm selecting a value from the grid based on a value in one of the dynamic columns.  First step is to find location of the proper column by searching through all headercells to find the matching column index.  The issue I'm running into is the following lines of code executing before the radgridview is fully loaded resulting in a zero column count being returned:

public int globalTimeout = 10000;

public void login()
{
Pages.TestPage.SilverlightApp.LoginButton.User.Click();
Pages.TestPage.SilverlightApp.LoginPage.Wait.ForExistsNot(globalTimeout);
Pages.TestPage.SilverlightApp.HomePage.Wait.ForExists(globalTimeout);
Pages.TestPage.SilverlightApp.HomePage.Wait.ForNoMotion(globalTimeout);
}
public int findColumn(string value)
{
RadGridView grid = new RadGridView();
//if I add a System.Threading.Thread.Sleep(10000) before this grid is initialized, it works every time, if I don't, I randomly get a zero count of headerCells even though they exist
grid = Pages.TestPage.SilverLightApp.Test_RadGridView;

//If I add a grid.Wait.ForExists(10000) here, it still moves to the next line almost instantly as the grid exists but the data doesn't necessarily exist yet
 //If I add a grid.Wait.ForNoMotion(10000) here, it still doesn't seem to matter

int cols = grid.HeaderRow.HeaderCells.Count;

Assert.IsTrue(cols != 0, "No header columns were found.");
//code code code
return columnNumber;
}

Any suggestions on how to better handle (through code!) the wait for radgridview to populate/ready for indexing? 

6 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 27 Mar 2014, 07:33 PM
Hi Nick,

I would add a Wait.For to wait for data to show up in the grid like this:
// Get a a local variable for the grid
RadGridView grid = Pages.TestPage.SilverLightApp.Test_RadGridView;
// Wait for more than 1 row to be present in the grid
Wait.For<RadGridView>(rgv => rgv.Rows.Count > 1, grid, 10000);
// Wait for the header column count to be more than 1
Wait.For<RadGridView>(rgv => rgv.HeaderRow.HeaderCells.Count > 1, grid, 10000);

I would use either of the above Wait.For. It should not be necessary to use both.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nick
Top achievements
Rank 1
answered on 28 Mar 2014, 12:23 AM
Thanks Cody, the concept is exactly what I'm looking for but I believe my execution of it is off.

When I use the following code (note that line 684 is the line beginning in "Wait.For..."):
public void sandbox()
{
Pages.TestPageWeb.SilverlightApp.Login_TextBox_Username.User.TypeText("demouser", 50);
Pages.TestPageWeb.SilverlightApp.Login_TextBox_Password.User.TypeText("password1", 50);
Pages.TestPageWeb.SilverlightApp.Login_Button_Login.User.Click();
Wait.For<RadGridView>(rgv => rgv.HeaderRow.HeaderCells.Count > 0, Pages.TestPageWeb.SilverlightApp.Worklist_GridView, 10000);
}

I get the following error:
System.NullReferenceException: Object reference not set to an instance of an object.
   at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_Wait()
   at CIS.TestStudio.WebAccess.Common.sandbox() in c:\tfs\CoreCM\Root\CIS.TestStudio.WebAccess\Common.cs:line 684

Did I miss something?

Thanks,
Nick
0
Cody
Telerik team
answered on 31 Mar 2014, 04:52 PM
Hi Nick,

That small snippet of code looks correct. The stack trace "at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_Wait()" shows the problem is deep inside of our framework, which implies some sort of initialization problem. I need to see the entire code so I can see how you're initializing the test.

Would you put the entire project into a .zip folder and attach that for me to review please.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Nick
Top achievements
Rank 1
answered on 01 Apr 2014, 11:25 AM
I will create a sample project with the same scenario and send it over.

Thanks,
Nick
0
Nick
Top achievements
Rank 1
answered on 01 Apr 2014, 06:27 PM
I've attached an example of the problem I'm having.  Quick Execute the test named "WaitForGridToLoad.tstest" located in the folder "WaitForGridToLoadIssue".  It uses the telerik silverlight radgridview demo page.  Executing that test will display the following error:

Exception thrown executing coded step: 'Get column count'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.
   at ArtOfTest.WebAii.Design.BaseWebAiiTest.get_Wait()
   at Telerik_Troubleshooting.Common.colCount() in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\Common.cs:line 55
   at Telerik_Troubleshooting.Common.gridViewIssue() in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\Common.cs:line 64
   at Telerik_Troubleshooting.WaitForGridViewToLoadIssue.WaitForGridToLoad.ParentGrid_CodedStep() in c:\Test Studio Projects\Telerik Troubleshooting\Telerik Troubleshooting\WaitForGridViewToLoadIssue\WaitForGridToLoad.tstest.cs:line 89
0
Cody
Telerik team
answered on 02 Apr 2014, 08:03 PM
Hello Nick,

Thank you for the sample project. I see the problem (without even running the code). Your common.cs must not use BaseWebAiiTest. This base class only gets properly initialized when its the code behind file for a test.

The problem you're running into is that the Wait object hasn't been initialized when you execute:
Wait.For<RadGridView>(rgv => rgv.HeaderRow.HeaderCells.Count > 1, grid, 15000);

Instead you could pass in "this" as a parameter to the constructor for Common and use that throughout your methods. You should also eliminate the Pages property in your Common class. It does not belong there.

Regards,
Cody
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Nick
Top achievements
Rank 1
Answers by
Cody
Telerik team
Nick
Top achievements
Rank 1
Share this question
or