简体   繁体   English

当隐藏的控件在编码的UI测试中显示在UI中时,如何使它们成为记录隐藏控件?

[英]How can I make record hidden controls when they become visible in UI in coded UI tests?

I have built a web page in .NET with C#, working in VS 2012 Premium. 我已经在VS 2012 Premium中使用C#在.NET中构建了一个网页。 I have recorded some coded UI tests. 我已经记录了一些编码的UI测试。 One of them contains a control that is firstly hidden but it becomes visible and active from another control that keeps a certain value. 其中一个包含一个控件,该控件首先被隐藏,但是从另一个具有一定值的控件中可以看到它并处于活动状态。 When I playback this, it is failing with an error: Cannot perform setproperty to a hidden field. 播放此文件时,它失败并显示错误:无法对隐藏字段执行setproperty。

Does anyone have any workaround how can I record or playback this? 有人有任何解决方法,如何录制或播放此声音?

Thanks in advance. 提前致谢。

There is a property in .Net 4.5 HiddenField.Value Property. .Net 4.5 HiddenField.Value属性中有一个属性。 The inheritance hierarchy is like 继承层次结构就像

       System.Object 
       System.Web.UI.Control
       System.Web.UI.WebControls.HiddenField

The C# syntax would be C#语法为

   public virtual string Value { get; set;}

ASP.NET ASP.NET

   <asp:HiddenField Value="String"/>

You can use the Value property to specify the value of the HiddenField control. 您可以使用Value属性来指定HiddenField控件的值。

This is a common use case, whether the field is hidden or disabled and waiting for another action to change state. 无论字段是隐藏还是禁用,并等待其他操作更改状态,这都是一个常见的用例。 The problem is determining what about the field changes, does it not exist? 问题在于确定字段更改如何,不存在吗? Does it not have a screen point? 它没有遮蔽点吗? is it notVisible? 是不是可见? Is it notEnabled? 是否未启用? Once you determine that you can proceed 一旦确定可以继续

I would handle it thusly: 我会这样处理:

            var field = new HtmlTextArea();


           if(field.WaitForControlReady(100)) //checks for control ready until waittime hit
               {
                 field.Text="Insert text here";
               }
            else
               {
                    Assert.Fail(String.Format( "Control not found in {0} seconds.", timeout*100));
               }

Please use this code as a guide only, it was created standing on one foot before i drank coffee :) 请仅将此代码用作指导,它是在我喝咖啡之前单脚站立的:)

Try using control.BoundingRectangle.Height > 0 in condition and see if the control is appearing. 尝试在有条件的情况下使用control.BoundingRectangle.Height> 0,看看控件是否出现。

or 要么

Use control.EnsureClickable() 使用control.EnsureClickable()

Then get the value using control.GetProperty("Value") 然后使用control.GetProperty(“ Value”)获得值

Thanks, Karthik KK 谢谢,Karthik KK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM