Is it possible to traverse on diffrent webpage and pick data from webtable without mentioning the webpage in code?

1 Answer 83 Views
Coded Steps Coded Tests
amit
Top achievements
Rank 1
amit asked on 22 Aug 2022, 05:39 AM

hello,

I want to make a common code which pick some data from webtable from different webpages. Here the webpages consist identical table .

This is an example in which I am picking data from ReportingReportTable . And the table present on RoleAssignment page.

So I want to use this code for different pages where table is identical . Is it possible without mentioning page we can traverse on any page and pick data?

 

 [CodedStep(@"Verify element 'ReportingReportTable' 'is' visible.")]
        public void check_CodedStep()
        {
     
            foreach (HtmlTableRow row in Pages.RoleAssignment.ReportingReportTable.AllRows)
                {
                    
                    if (row.Cells[1].InnerText.Equals("test, hr"))
                        {
         
                        row.Cells[1].AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Contains,"test, hr");
                        row.Cells[2].AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Contains,"hr1");
                        row.Cells[3].AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Contains,"NFCEXAMPLE");
                        row.Cells[4].AssertContent().InnerText(ArtOfTest.Common.StringCompareType.Contains,"NFCEXAMPLE - NFCExample-Description");    
                            break;
                           
                            
                        }
                        else
                        {
                         
                              Pages.RoleAssignment.NextPageSubmit.Click(false);
                 
                        }
                        
            
        }
               
        }

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 24 Aug 2022, 09:23 AM

Hello Amit,

Thank you for providing a sample code and details about the test scenario that you want to automate. 

It is certainly possible to find a table in a coded step, without relying on the Pages object. It is even recommended to use the approach below in some cases, because it makes the code independent of the project and the elements in the Elements Explorer.

The idea is to replace the HtmlTable object - Pages.RoleAssignment.ReportingReportTable, with another object that is created by the coded step itself. So, every time you execute this code, it will look for the table based on the provided logic in the current page's DOM tree. Please refer to the different methods in the Find class and see which one is the most suitable for your. Here is a sample code snippet that you can add to your code.

HtmlTable table = Find.ByExpression<HtmlTable>("tagname=table", "id=tableid"); //adjust the find expression based on the table's attributes foreach (HtmlTableRow row in table.AllRows) { if (row.Cells[1].InnerText.Equals("test, hr"))

....

I hope the above information and suggestion will be helpful to you. Let me know if you need further assistance.

Regards,
Plamen Mitrev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Test Studio course! Check it out at https://learn.telerik.com/.
Tags
Coded Steps Coded Tests
Asked by
amit
Top achievements
Rank 1
Answers by
Plamen Mitrev
Telerik team
Share this question
or