Fine tuning the recorded step

18 posts, 4 answers
  1. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2012 Link to this post

    Hi, My 2nd post here. 

    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? 

    What looks obvious to me is the 'XamlPath=' part in Expression. That should tell me how to locate the object in DOM. For the rest, the syntax is still unclear to me. Moreover, is the  [XamlPath 'Exact' ...] part in FindLogic the same as what's in Expression? If so, why duplicate it to two places? 

    Sorry for so many question, here is the last one. If I don't want to select a data grid by a fixed  place, but rather select a data grid according its content, say the content begins with 'Abc', how can I alter the recorded step?

    Thanks


  2. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2012 Link to this post

    Find Jim's blog that best answers my above question. 
    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.
  3. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 22 Mar 2012 Link to this post

    Hello Ohsha,

    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".

    Regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  4. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 22 Mar 2012 Link to this post

    Thanks a lot Anthony  for your detailed explanation, even it seems I've found the answer. 
    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

  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 22 Mar 2012 Link to this post

    Hello Ohsha,

    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. 

    Greetings,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  6. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 23 Mar 2012 Link to this post

    RadGrid grid = Pages.DemoPage.Contacts_Table; 
    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



  7. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 23 Mar 2012 Link to this post

    Hello Ohsha,

    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
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  8. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 23 Mar 2012 Link to this post

    Thanks, 

    I got the following error:

    DataGrid grid = Pages.SilverlightToolkitSamples.SilverlightApp.DataGrid1;
    DataGrid\Test1.tstest.cs: Line 81: (CS0118) 'DataGrid' is a 'namespace' but is used like a 'type'

    DataGridCell cell1 = row.Cells[1];
    DataGrid\Test1.tstest.cs: Line 89: (CS0618) 'ArtOfTest.WebAii.Silverlight.UI.DataGridRow.Cells' is obsolete: 'The property is deprecated. Please use .CellElements instead.'

    Please help. 
  9. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 23 Mar 2012 Link to this post

    Hello Ohsha,

    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.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  10. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 26 Mar 2012 Link to this post

    Thanks Anthony. That solved the problem. 

    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


  11. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 26 Mar 2012 Link to this post

    "Thanks Anthony. That solved the problem.  One more question ..."

    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


  12. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 26 Mar 2012 Link to this post

    Hello Ohsha,

    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
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  13. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 27 Mar 2012 Link to this post

    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? 

    Hi everyone, 

    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!


  14. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 27 Mar 2012 Link to this post

    Hello Ohsha,

    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.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  15. Ohsha
    Ohsha avatar
    57 posts
    Member since:
    Mar 2012

    Posted 27 Mar 2012 Link to this post

    Thanks for the answer Anthony. I've done further reading after my previous question. Now my question is,

    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
  16. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 27 Mar 2012 Link to this post

    Hello Ohsha,

    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.

    Kind regards,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  17. Soujanya
    Soujanya avatar
    1 posts
    Member since:
    Dec 2012

    Posted 21 Dec 2012 Link to this post

    Hello ,

    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;
                       }
                        
                     }
     
                    
                   }
                
              
    i am using the above code to access a cel value ,but am getting the following error .could you pelase help me here.

    :\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


  18. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 26 Dec 2012 Link to this post

    Hello 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
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top