Telerik blogs

The default behavior of the WebAii Testing Framework (and WebUI Test Studio respectively) searching for the application visual elements is to timeout after a certain period of time if the element is not found.

        [TestMethod()]
        public void TelerikComSLTest1()
        {
            // Enable Silverlight testing
            Manager.Settings.EnableSilverlight = true;

            // Launch an instance of the browser
            Manager.LaunchNewBrowser();

            // Navigate to : 'http://www.telerik.com/'
            ActiveBrowser.NavigateTo("http://www.telerik.com/");

            SilverlightApp app = this.ActiveBrowser.SilverlightApps()[0];

            Image titleImage = app.Find.ByName<Image>("Title"); // will timeout if the image name is changed // Wait for visible 'TitleImage'
            titleImage.Wait.ForVisible();

            // do whatever else is needed
        }

This is pretty helpful in Silverlight application animations for example but one may need to avoid the TimeoutException. That is currently easy in Silverlight by changing the exposed SilverlightApp or any FrameworkElement VisualFind.Strategy value. I’d recommend setting back the original strategy in a finally block as well:

        [TestMethod()]
        public void TelerikComSLTest()
        {
            // initialize test part
            Manager.Settings.EnableSilverlight = true;
            Manager.LaunchNewBrowser();
            ActiveBrowser.NavigateTo("http://www.telerik.com/");
            SilverlightApp app = this.ActiveBrowser.SilverlightApps()[0];

            // save the original strategy to set it back at test end
            FindStrategy originalStrategy = app.Find.Strategy;

            try
            {
                // reset the find strategy
                app.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;

                string imageName = "Title";
                Image titleImage = app.Find.ByName<Image>(imageName); // will return 'null' if the image name is changed // now we can check if null if (titleImage != null)
                {
                    titleImage.Wait.ForVisible();
                }
                else
                {
                    throw new ArgumentException(string.Format("Unable to find the SL image named '{0}'!", imageName));
                }

                // do whatever the test else needs
            }
            finally 
            {
                // set back the original find strategy
                app.Find.Strategy = originalStrategy;
            }
        }

I hope this helps! Enjoy our Automated Testing Tools and let us know if you have any feedback!

Yours,

-Konstantin


Comments

Comments are disabled in preview mode.