简体   繁体   中英

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. I have recorded some coded UI tests. 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.

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. The inheritance hierarchy is like

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

The C# syntax would be

   public virtual string Value { get; set;}

ASP.NET

   <asp:HiddenField Value="String"/>

You can use the Value property to specify the value of the HiddenField control.

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.

or

Use control.EnsureClickable()

Then get the value using control.GetProperty("Value")

Thanks, Karthik KK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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