如何验证每行的单元格? [英] How to verify the cells of each row?

查看:71
本文介绍了如何验证每行的单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有网表(即HtmlTable)。首先我验证了那张桌子。在该表中有4列和9行。在第3和第4列有两个按钮。第二列有描述。


我的问题是,我想验证每个字段。第一行应该有描述名称(第2列),订阅(第3列)和视图(第4列)。


以下代码我用过。我用粗体编写了用于验证表格第二单元格的代码。



            HtmlTable表=新的HtmlTable(浏览器);

            Table.TechnologyName =" Web";&
            Table.SearchProperties.Add(QUOT;标识"," ctl00_ContentPlaceHolder1_rpt_appgrp_ctl00_v2rrl_mytable1");

            Table.SearchProperties.Add(QUOT; ControlType","表");

            Table.DrawHighlight();
$


            //获取第二行。

            HtmlRow Table_Second_Row = new HtmlRow(Table);

            Table_Second_Row.TechnologyName =" Web";&
            Table_Second_Row.SearchProperties.Add(" TagName"," TR");

            Table_Second_Row.SearchProperties.Add(" ControlType"," Row");

            Table_Second_Row.SearchProperties.Add(" RowIndex"," 1");

            Table_Second_Row.DrawHighlight();
$


            //获取div $
            HtmlDiv Table_Second_Row_Div =新HtmlDiv(Table_Second_Row);

            Table_Second_Row_Div.TechnologyName =" Web";&
            Table_Second_Row_Div.SearchProperties.Add(QUOT;标签名"," DIV");

            Table_Second_Row.DrawHighlight();
$


            //获取子表

            HtmlTable Child_Table = new HtmlTable(Table_Second_Row_Div);

            Child_Table.SearchProperties.Add(QUOT; ControlType","表");

            var tables = Child_Table.FindMatchingControls();

            var tablecell = Child_Table.CellCount;

            Child_Table.DrawHighlight();
$


            //获取所有子表的内部文本

            for(int i = 0; i< tables.Count; i ++)

            {

                HTMLTABLE表=表[I]作为HTMLTABLE;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; string content = table.InnerText;

                UITestControlCollection细胞= table.Cells;

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; string ReportNameContent = cells [0] .GetProperty(" InnerText")。ToString();

            &NBSP;&NBSP;&NBSP;&NBSP; table.DrawHighlight();

                Assert.AreEqual(ReportNameContent,cells [0] .GetProperty(" InnerText")。ToString());
$


      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;
UITestControl ReportDescContent = cells [1] .GetChildren()[0];

           &NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //MessageBox.Show("ID" + ReportDescContent.GetProperty(QUOT;标识")+"&NBSP;控制与NBSP;类型" + ReportDescContent.GetProperty(QUOT; ControlType"));

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;如果(ReportDescContent.GetProperty(QUOT;标签名"。)的ToString()等于(" TD")&安培;&安培; ReportDescContent.GetProperty(QUOT; ControlType"。)的ToString()等于("细胞")及&安培; ReportDescContent.GetProperty(QUOT;的ClassName")。。的ToString()等于(" HtmlTableCell"))

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;串ReportDesccontent =细胞[1] .GetProperty(QUOT;的innerText")。的ToString();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; ReportDescContent.DrawHighlight();

                }
               否则b $ b                {

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; Assert.Fail(QUOT;报告描述为空");

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ; }


            } b
$
请帮帮我。



谢谢&问候,

SKorla

解决方案

SKorla,


我不清楚关于你面临的问题。此外,从代码中可以看出,网页具有复杂的htmltable层次结构,如:


表 - >行 - > Div - >表格 - >单元格


您可以使用UITestingUtilities二进制来获取数据网格或一次列出并验证它。请参阅

http://blogs.msdn.com/b/gautamg/archive/2010/02/19/useful-set-of-utility-functions-for-coded-ui- test.aspx


- Tejas。


Hi All,

I have web table(i.e HtmlTable). First i verified that table. In that table is having 4 columns and 9 rows.In 3rd and 4th column has two buttons. 2nd column has description.

Here my question is,i want to verify each and every field. 1st row should have name with description(2nd column),Subscribe(3rd column) and view(4th column).

Below following code i used. In bold i have written code for verify 2nd cell of the table.


            HtmlTable Table = new HtmlTable(browser);
            Table.TechnologyName = "Web";
            Table.SearchProperties.Add("Id", "ctl00_ContentPlaceHolder1_rpt_appgrp_ctl00_v2rrl_mytable1");
            Table.SearchProperties.Add("ControlType", "Table");
            Table.DrawHighlight();

            // Get the second row.
            HtmlRow Table_Second_Row = new HtmlRow(Table);
            Table_Second_Row.TechnologyName = "Web";
            Table_Second_Row.SearchProperties.Add("TagName", "TR");
            Table_Second_Row.SearchProperties.Add("ControlType", "Row");
            Table_Second_Row.SearchProperties.Add("RowIndex", "1");
            Table_Second_Row.DrawHighlight();

            // Get the div
            HtmlDiv Table_Second_Row_Div = new HtmlDiv(Table_Second_Row);
            Table_Second_Row_Div.TechnologyName = "Web";
            Table_Second_Row_Div.SearchProperties.Add("TagName", "DIV");
            Table_Second_Row.DrawHighlight();

            // Get the child tables
            HtmlTable Child_Table = new HtmlTable(Table_Second_Row_Div);
            Child_Table.SearchProperties.Add("ControlType", "Table");
            var tables = Child_Table.FindMatchingControls();
            var tablecell = Child_Table.CellCount;
            Child_Table.DrawHighlight();

            // Get the InnerText of all the child tables
            for (int i = 0; i < tables.Count; i++)
            {
                HtmlTable table = tables[i] as HtmlTable;
                string content = table.InnerText;
                UITestControlCollection cells = table.Cells;
                string ReportNameContent = cells[0].GetProperty("InnerText").ToString();
                table.DrawHighlight();
                Assert.AreEqual(ReportNameContent, cells[0].GetProperty("InnerText").ToString());

                UITestControl ReportDescContent = cells[1].GetChildren()[0];
                //MessageBox.Show("ID" + ReportDescContent.GetProperty("Id") + "  Control  Type " + ReportDescContent.GetProperty("ControlType"));
                if (ReportDescContent.GetProperty("TagName").ToString().Equals("TD") && ReportDescContent.GetProperty("ControlType").ToString().Equals("Cell") && ReportDescContent.GetProperty("ClassName").ToString().Equals("HtmlTableCell"))
                {
                    string ReportDesccontent = cells[1].GetProperty("InnerText").ToString();
                    ReportDescContent.DrawHighlight();
                }
                else
                {
                    Assert.Fail("Report Description is empty");
                }

            }

Please help me out.

Thanks & Regards,
SKorla

解决方案

SKorla,

I am not clear about what issue you are facing. Also, It appears from the code that the web page has complex htmltable hierarchy something like:

Table -> Rows -> Div -> Tables -> Cells

You can use UITestingUtilities binary to get content of controls like Data Grid or List and validate it in one shot. See http://blogs.msdn.com/b/gautamg/archive/2010/02/19/useful-set-of-utility-functions-for-coded-ui-test.aspx

-Tejas.


这篇关于如何验证每行的单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆