What if the recorded step is not quite right?
Is it possible for me to fine tune it?
For example, I have this "LeftClick on x...Textblock", with the following Find logic:
Expression:
XamlTag=datagrid,automationid=DataGrid,|,XamlPath=/grid[0]/border[0]/grid[name=Root]/datagridrowspresenter[automationid=RowsPresenter]/datagridrow[0]/datagridfrozengrid[name=Root]/datagridcellspresenter[name=CellsPresenter]/datagridcell[3]/grid[name=Root]/contentpresenter[0]/stackpanel[0]/textblock[0]
FindLogic:
[automationid 'Exact' DataGrid] AND [XamlTag 'Exact' datagrid][XamlPath 'Exact' /grid[0]/border[0]/grid[name=Root]/datagridrowspresenter[automationid=RowsPresenter]/datagridrow[0]/datagridfrozengrid[name=Root]/datagridcellspresenter[name=CellsPresenter]/datagridcell[3]/grid[name=Root]/contentpresenter[0]/stackpanel[0]/textblock[0]]
How to interpret it?
17 Answers, 1 is accepted
http://www.telerik.com/automated-testing-tools/blog/12-03-05/4-5-tips-for-working-with-tests-in-tables.aspx
Actually, I've read it before, but didn't make any clicks until now...
Thanks Jim.
The Expression and FindLogic in your example are the same, just written differently. It's using a "Chained" Find Expression. That means locate the parent element first (DataGrid), then from there use a XamlPath to locate the target element (TextBlock). See here and here for more information.
See the attached screen shots. The first shows the standard Find Settings for a TextBlock. The DataGrid is found first, and then the target TextBlock within the DataGrid is located based in its TextContent. Instead of "is exactly," you can changed it to "contains," "starts with," etc.
The second shows the advanced find expression. Note the "|" separator than indicates "Then." In other words, locate the DataGrid, then locate the TextBlock within the grid with a TextContent of "Jill".
Anthony
the Telerik team
Test Studio Trainings
Really appreciate it.
Now further onto Jim's blog, in which he says:
RadGrid grid = Pages.DemoPage.Contacts_Table;
I know what Contacts_Table is, but how about Pages, DemoPage & RadGrid? Should I used them as is?
I know he's using a Telerik RadGrid for AJAX in this example, but I'm using Silverlight data grid.
Thanks
That syntax is only applicable to coded steps. See here for how to reference an element in code.
You should not use them as is. Your page and element names will differ. Your beginning variable will be DataGrid. See the attached screen shot for an example.
Anthony
the Telerik team
Test Studio Trainings
HtmlTableRow jayne = grid.Find.TableRow("Cobb");
Alright, moving forward. I found that my DataGrid is of type ArtOfTest.WebAii.Silverlight.UI.DataGrid.
It does not have the Find.TableRow method. So,
How can I find a row with ArtOfTest.WebAii.Silverlight.UI.DataGrid?
Again, the celling I'm accessing is,
/grid[0]/border[0]/grid[name=Root]/datagridrowspresenter[automationid=RowsPresenter]/datagridrow[0]/datagridfrozengrid[name=Root]/datagridcellspresenter[name=CellsPresenter]/datagridcell[3]/grid[name=Root]/contentpresenter[0]/stackpanel[0]/textblock[0]
(see the attached DOM element).
But actually any cell in the row will do.
Moreover, if the Click() method is obsolete for ArtOfTest.WebAii.Silverlight.UI.DataGrid,
http://www.telerik.com/automated-testing-tools/support/documentation/online-api-reference/html/AllMembers_T_ArtOfTest_WebAii_Silverlight_UI_DataGrid.htm
after I've found it, how can I "click" it?
Thanks
You can access the rows and cells of a Silverlight DataGrid in much the same way as an HTML Grid. Here's an example that searches each cell of each row for a specific string, and clicks if found:
SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
DataGrid grid = app.Find.ByAutomationId<DataGrid>(
"dataGrid"
);
Assert.IsNotNull(grid);
int
r = grid.Rows.Count;
for
(
int
i = 0; i < r; i++)
{
DataGridRow row = grid.Rows[i];
foreach
(DataGridCell cell
in
row.Cells)
{
if
(cell.TextBlockContent ==
"Jill"
)
{
cell.User.Click();
break
;
}
}
}
You'll just need to add logic as to what you'd like to happen if the string isn't found.
Noticed I've used .User.Click() as real mouse clicks are always recommended in Silverlight.
Kind regards,
Anthony
the Telerik team
Test Studio Trainings
I got the following error:
DataGrid grid = Pages.SilverlightToolkitSamples.SilverlightApp.DataGrid1;
DataGridCell cell1 = row.Cells[1];
Please help.
The issue is that your project is named DataGrid, and this is confusing the compiler. Rename the project, and ensure the Assembly Name and Namespace match the new project name in Project Settings > Script Options.
Anthony
the Telerik team
Test Studio Trainings
One more question,
given this Silverlight demo example (after navigating there, click DataGrid in the left-hand menu), could you show me how to use Find.ByExpression to find by XPath please?
I want to locate to the cell that
Complaint = "closed" and
Firstname = "Joe".
You can start from here, where I'm stuck:
DataGridRow myDGR = grid.Find.ByExpression(new XamlFindExpression("Name=patientSearchScroller", "|", "XamlTag=ScrollViewer")).As<DataGridRow>();
Thanks
Oh, one more question,
My next recorded rule was,
Test "JoeTextBlock" text Same "Joe"
How can I tell it to use the cell/TextBlock that I picked just now?
Thanks
If the grid is dynamic, then I recommend my original approach that searches each row's cell for the desired text.
If the grid is static, then you can reference a specific row and cell by index (which is easier than XPath):
DataGridRow row = grid.Rows[2];
row.User.Click();
DataGridCell complaintCell = row.Cells[1];
DataGridCell firstNameCell = row.Cells[2];
Assert.IsTrue(complaintCell.TextBlockContent ==
"Closed"
);
Assert.IsTrue(firstNameCell.TextBlockContent ==
"Joe"
);
You can still identify the row by XPath if you wish:
DataGridRow row = grid.Find.ByExpression(
new
XamlFindExpression(
"XamlTag=datagridrowspresenter"
,
"automationid=RowsPresenter"
,
"|"
,
"XamlPath=/datagridrow[2]"
)).As<DataGridRow>();
Kind regards,
Anthony
the Telerik team
Test Studio Trainings
Oh, one more question,
My next recorded rule was,
Test "JoeTextBlock" text Same "Joe"
How can I tell it to use the cell/TextBlock that I picked just now?
I was trying to answer the above question myself but failed.
Having followed the
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/knowledge-base/data-driven-testing/pass-a-variable.aspx
I still can't figure out how to setup the InheritParentDataSource in code.
because I can't convert the extract rule as code to see how it does.
Further, when I tried to apply the method to this Silverlight demo example, I bumped into a new problem that I can't even do content extraction. Take a look at the attached picture, the "Extract - text contains..." menu is simply not there.
Can anyone help please?
To recap, two questions,
- how to setup the InheritParentDataSource with C# code in parent test.
- how to do content extraction for my given example.
Thanks a lot!
The article you followed was written against an HTML site. You're attempting an Extraction against a Silverlight site. The Extract is there, the wording is just slightly different (verify text content matches). See the attached screen shot.
Once you add that to the test, you won't be able to convert that step to code. That option is disabled.
Why are you trying to set InheritParentDataSource in code? This is a test property and it cannot be applied to individual test steps. In the example article, it is turned on for the Child test, which is called via a Test as Step in the Parent test. That way, the extracted variable created in the Parent test can be passed along to and used in the Child test.
Anthony
the Telerik team
Test Studio Trainings
Suppose that I've done data binding so that my test is now a data-driven test, and my data source is SQL DB.
Now if I want to save some variables, where and how should I save them (in MS Test, I can save them as Session Parameters) using C# code.
Hope that I've made myself clear this time.
Thanks
If you've Added a SQL Database to your project as a data source, you can attach columns from it to Input Value steps and Verifications just like any other data source.
If you'd like to access your SQL Database directly in code and retrieve values from it, here is a code sample. Once you have the desired values, you can Set them to Extracted Variables in code, and then use those variables later in the test on standard action and verification steps.
For more efficient issue tracking for both parties, please log a separate ticket or forum post when a new issue or question arises.
Anthony
the Telerik team
Test Studio Trainings
Assert.AreEqual(ArtOfTest.WebAii.Silverlight.UI.Visibility.Visible, Pages.ScottSafetyAdministration.SilverlightApp.UserDataGridDatagrid.ComputedVisibility,
"Element visibility does not match expected value"
);
DataGrid grid =Pages.ScottSafetyAdministration.SilverlightApp.Find.ByName<DataGrid>(
"UserDataGriddatagrid"
);
if
(grid !=
null
)
{
int
r = grid.Rows.Count;
for
(
int
i = 0; i < r; i++)
{
DataGridRow row = grid.Rows[i];
foreach
(DataGridCell cell
in
row.Cells)
{
string
txt =cell.TextBlockContent;
}
}
}
:\ScottSafetyBlue\ScottSafety_QATest\ScottSafety.Accountability\Automation_Test_cases\AdminApplication\AdminScreen\AT_Validate_InactiveUsers_shouldNotLogin.tstest.cs: Line 94: (CS1061) 'ArtOfTest.WebAii.Silverlight.UI.DataGrid' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'ArtOfTest.WebAii.Silverlight.UI.DataGrid' could be found (are you missing a using directive or an assembly reference?)c:\ScottSafetyBlue\ScottSafety_QATest\ScottSafety.Accountability\Automation_Test_cases\AdminApplication\AdminScreen\AT_Validate_InactiveUsers_shouldNotLogin.tstest.cs: Line 98: (CS1061) 'ArtOfTest.WebAii.Silverlight.UI.DataGrid' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'ArtOfTest.WebAii.Silverlight.UI.DataGrid' could be found (are you missing a using directive or an assembly reference?)c:\ScottSafetyBlue\ScottSafety_QATest\ScottSafety.Accountability\Automation_Test_cases\AdminApplication\AdminScreen\AT_Validate_InactiveUsers_shouldNotLogin.tstest.cs: Line 99: (CS1061) 'ArtOfTest.WebAii.Silverlight.UI.DataGridRow' does not contain a definition for 'Cells' and no extension method 'Cells' accepting a first argument of type 'ArtOfTest.WebAii.Silverlight.UI.DataGridRow' could be found (are you missing a using directive or an assembly reference?)
Thanks & regards,
Soujanya
you're hitting some compilation errors it seems.
It seems you're trying to access DataGrid and its Rows. Unfortunately DataGrid has no "Rows" member. Instead the member you probably need is dg.RowElements. So you can edit the code to look like this:
int r = grid.RowElements.Count;
I hope this helps. In the future please open separate posts for questions like this - that will assure that you get a response more quickly.
Regards,
Stoich
the Telerik team
Test Studio Trainings