This is a migrated thread and some comments may be shown as answers.

Refreshing control on popup window doesn't work

6 Answers 140 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 13 Nov 2011, 01:08 PM
Using: ArtOfTest.WebAii.dll 2011.2.1108.0.
Windows 7 x64 / VS2010 / Mstest / Silverlight 4.

Calling FrameworkElement.Refresh() according to doco is meant to 'refresh this framework element within the visualtree'.  This works fine when the element is part of the main application's visual tree, however seems not to work when the element is part of a popup / child window visual tree. 

Attached is a minimal test project to repro the issue.  It has two unit tests, 1 passes (for a control on the main visual tree) and 1 fails (for the same control on a child window). 

Can you please confirm if this is a bug, or otherwise what I am doing wrong?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 17 Nov 2011, 10:57 AM
Hello Peter,

Thank you for the provided sample application. I was able to reproduce the issue and confirm it as a bug. You can track the PITS Item here: Public URL. It seems that even if we call the Combobox.Refresh() method, the items are still not presented in the Visual Tree.

I have added 1000 Telerik Points to your account for discovering this bug for us.

We'll try to find a workaround for this issue and we will provide an answer ASAP!  

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Plamen
Telerik team
answered on 21 Nov 2011, 04:42 PM
Hi Peter,

Here is a temporary workaround until the main problem is fixed.
private SilverlightApp app
{
    get
    {
        return ActiveBrowser.SilverlightApps()[0];
    }
}
 
private ComboBox popupCombo
{
    get
    {
        return app.Popups[0].VisualTree.Find.ByType<ComboBox>();
    }
}
 
// This test fails. 
[TestMethod]
public void GetComboBoxItems_ChildVisualTree()
{
    Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
    ActiveBrowser.NavigateTo("http://localhost:16696/SilverlightApplication1TestPage.aspx");
    SilverlightApp app = ActiveBrowser.SilverlightApps()[0];
 
    var openButton = app.Find.ByTextContent("Open Child Window");
    openButton.User.Click();
    Thread.Sleep(2000); // Wait for popup dialog to appear.
    app.RefreshVisualTrees();
 
    Assert.IsNotNull(popupCombo);
           // OpenDropDown updates all the application popups, we can't use the old ComboBox instance though, so get it again
    popupCombo.OpenDropDown(true);
 
    Assert.AreEqual<int>(3, popupCombo.Items.Count);
}
Check the logged PITS Item for more information.

Regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peter
Top achievements
Rank 1
answered on 22 Nov 2011, 08:01 AM
Thanks, here's a more generic workaround which is working for us:

        /// <summary>
        /// Refreshes the given element (replaces the FrameworkElement.Refresh() method for cases where the control is on a child window.)
        /// </summary>
        /// <param name="comboBox">The combo box.</param>
        /// <param name="value">The value.</param>
        /// <remarks>
        /// This method exists to workaround an issue that I have reported to Telerik here:
        /// http://www.telerik.com/automated-testing-tools/community/forums/test-studio-express/automation-framework/refreshing-control-on-popup-window-doesn-t-work.aspx
        /// </remarks>
        public T GetRefreshedElement<T>(T element) where T : FrameworkElement
        {
            var parent = element.Parent<Popup>();
            if (parent != null)
            {
                FrameworkElement originalParent = null;
 
                ActiveBrowser.SilverlightApps()[0].RefreshVisualTrees();
                foreach (var popup in ActiveBrowser.SilverlightApps()[0].Popups)
                {
                    if (popup.VisualTree.Root.Uid == parent.Uid)
                    {
                        originalParent = popup.VisualTree.Root;
                        break;
                    }
                }
 
                Assert.IsNotNull(originalParent);
 
                int originalUid = element.Uid;
                element = null;
 
                foreach (var newElement in originalParent.Find.AllByType<T>())
                {
                    if (newElement.Uid == originalUid)
                    {
                        element = newElement;
                        break;
                    }
                }
 
                Assert.IsNotNull(element);
            }
            else
            {
                element.Refresh();
            }
 
            return element;
        }

As you can see, it relies on the FrameworkElement.Uid property to find the control again on the popup.  I couldn't find any documentation on what this property was, but it seemed to be an auto-generated string that changed each run of the application - can you confirm if this is a valid assumption?

Thanks.  
0
Plamen
Telerik team
answered on 22 Nov 2011, 01:52 PM
Hi Peter,

Excellent! The assumption is correct. The FrameworkElement.Uid property is getting the auto-generated Unique Id of the controls from their attributes. It can be different on each run of the application. 

Thank you for sharing your approach with us. It is a good alternative.

Best wishes,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Peter
Top achievements
Rank 1
answered on 17 Jan 2012, 02:11 AM
Any progress on this issue?  Unfortunately, it looks like this work-around no longer works in the latest build (2011.2.1305.0), as it appears that the ComboBox.OpenDropDown() can't be called a second time (first time is successful).  This could just be the way our test is written, but I'm wondering if you can point out how to diagnose the root cause based on the exception information, because I can't create a reproducible test project.  The exception information is:

Test method MyTestMethod threw exception:
System.Exception: Was not able to match a segment within the path. Expected:silverlightdialog , Found:FrameworkElement , Path:/popup:-1:9132882/silverlightdialog:0:15087078/grid:0:57367087/grid:1:51113363/border:4:35505424/border:0:41227749/grid:0:12037401/border:1:46076731/contentpresenter:0:46541742/grid:0:48172185/stackpanel:2:36948161/timescheduledetailsview:0:19672999/grid:0:57049196/recurringtimesview:1:19572825/grid:0:7868661/entitydatagrid:1:42592467/grid:0:38378011/dockpanel:0:11720763/grid:1:46041549/datagrid:3:5034184/grid:0:11877685/border:0:60972066/grid:0:6774674/datagridrowspresenter:4:27765811/datagridrow:0:53268321/datagridfrozengrid:0:57600065/datagridcellspresenter:3:19766715/datagridcell:2:47408069

Stack trace:

ArtOfTest.WebAii.Silverlight.VisualFind.ByReference(AutomationReference reference, Boolean throwIfNotFound)
ArtOfTest.WebAii.Silverlight.FrameworkElement.Refresh()
ArtOfTest.WebAii.Silverlight.FrameworkElement.Refresh()
ArtOfTest.WebAii.Silverlight.UI.ComboBox.OpenDropDown(Boolean simulateRealUser)
AcceptanceTests.ControlHelpers.ComboBoxHelper.SelectComboBoxValue(ComboBox comboBox, String value)
[etc]

The test is attempting to select a value from a combobox which exists within a datagridcell on a childwindow (silverlightdialog).  The first time a value is selected, it works, the second time, the above exception occurs.  This was working fine in 2011.2.1108.0.  Any help is appreciated, thanks.
0
Plamen
Telerik team
answered on 17 Jan 2012, 04:21 PM
Hello Peter,

The issue has been approved. However, it hasn't been implemented yet and probably it won't make its way into the next internal build.

As for the exception you are getting, it sounds like the Visual Tree structure of your Silverlight application changed after the first time you called ComboBox.OpenDropDown() and the path is no longer the same. As a result, instead finding the silverlightdialog it finds a FrameworkElement on the same path. One thing you can try is to call the RefreshVisualTrees() method of the SilverlightApp right before the second ComboBox.OpenDropDown() method. If there are no changes in the app this will refresh all popups and you should be able to find the correct element.  
 
Kind regards,
Plamen
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Peter
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Peter
Top achievements
Rank 1
Share this question
or