コード例 #1
0
        /// <summary>
        /// Waits for message to appear.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="message">The message.</param>
        public static void WaitForMessageToAppear(this SilverlightApp instance, string message)
        {
            instance.Find.Strategy = FindStrategy.AlwaysWaitForElementsVisible;
            var tryCount = 0;

            //Get all of the loading messages on the page
            while (tryCount < 3)
            {
                try
                {
                    instance.Find.AllByTextContent("~" + message);
                }
                catch (FindElementException)
                {
                    tryCount++;
                    Thread.Sleep(1000);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Tries to find item.
        /// </summary>
        /// <param name="instance">The instance.</param>
        /// <param name="searchFunction">The search function.</param>
        /// <param name="MaxTryCount">The maximum try count.</param>
        /// <param name="TryInterval">The try interval.</param>
        /// <returns></returns>
        /// <exception cref="System.Exception">Element can not be found</exception>
        public static IList <FrameworkElement> TryFindItem(this SilverlightApp instance,
                                                           Func <IList <FrameworkElement> > searchFunction,
                                                           int MaxTryCount = 5, int TryInterval = 1000)
        {
            var OriginalStrategy = instance.Find.Strategy;
            IList <FrameworkElement> elements = null;
            var tryCount = 0;
            var blnFound = false;

            while (tryCount < MaxTryCount && !blnFound)
            {
                try
                {
                    var originalStrategy = instance.Find.Strategy;
                    instance.Find.Strategy = FindStrategy.WhenNotVisibleThrowException;
                    instance.RefreshVisualTrees();
                    elements = searchFunction.Invoke();
                    blnFound = true;
                    instance.Find.Strategy = originalStrategy;
                }
                catch (Exception)
                {
                    //do nothing
                }
                finally
                {
                    Thread.Sleep(TryInterval);
                    tryCount++;
                }
            }
            if (!blnFound)
            {
                throw new Exception("Element can not be found");
            }
            instance.Find.Strategy = OriginalStrategy;
            return(elements);
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationBase"/> class.
 /// </summary>
 public ApplicationBase()
 {
     Application = Driver.Browser.SilverlightApps()[0];
 }
コード例 #4
0
        private static void FilterQuantity(SilverlightApp slApp, Manager myManager, string targetQuantity)
        {
            var andBtn = slApp.Find.ByTextContent("And");
            Assert.AreNotEqual(null, andBtn);

            var addFilterBtn = slApp.FindName("PART_AddFilterButton");
            Assert.AreNotEqual(null, addFilterBtn);
            addFilterBtn.User.Click();

            Thread.Sleep(500);

            var quantitySelect = slApp.Find.ByTextContent("Quantity");
            Assert.AreNotEqual(null, quantitySelect);

            var isEqualToSelect = slApp.Find.ByTextContent("Is equal to");
            Assert.AreNotEqual(null, isEqualToSelect);

            var filterInput = slApp.Find.AllByAutomationId("FilterEditor");
            filterInput[1].User.Click();
            myManager.Desktop.KeyBoard.TypeText(targetQuantity);
            myManager.Desktop.KeyBoard.KeyPress(System.Windows.Forms.Keys.Enter);
            Assert.AreNotEqual(null, filterInput);
        }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ApplicationBase"/> class.
 /// </summary>
 public ApplicationBase()
 {
     Application = Driver.Browser.SilverlightApps()[0];
 }
        public void HealthCareDemo()
        {
            #region ## Launch the application ##

            Manager.Settings.ExecutionDelay = 10;

            Manager.LaunchNewBrowser(BrowserType.InternetExplorer);
            System.Drawing.Point loc = ActiveBrowser.Window.Location;
            ActiveBrowser.NavigateTo("http://pjd.mscui.net/PrimaryCareAdmin.htm");


            ActiveBrowser.Window.Move(new System.Drawing.Rectangle(loc, new System.Drawing.Size(1024, 768)), true);
            // Get an instance of the running Silverlight Application.
            SilverlightApp app = ActiveBrowser.SilverlightApps()[0];

            #endregion

            #region ## Guide Testing ##

            //
            // Verify Show/Hide of the Guide works
            //

            // Click the ShowGuide button
            app.FindName("guideButton").User.Click();


            // Right click the ShowGuide button
            app.FindName("guideButton").User.Click(MouseClickType.RightClick,
                                                   new System.Drawing.Point(5, 5), OffsetReference.AbsoluteCenter);

            //
            // Wait for the guidance to be fully visible.
            //
            // In this application they use the Opacity of the
            // "GuidanceCanvas" to show/hide the guidance.
            Canvas guidanceCanvas = app.FindName <Canvas>("GuidanceCanvas");
            guidanceCanvas.Wait.For(canvas => canvas.Opacity == 1);

            guidanceCanvas.Refresh();

            // Make sure we got the correct # of guidance popups
            // The application pops 15 overlays on top
            IList <FrameworkElement> guidanceOverlays = guidanceCanvas.Find.AllByType("GuidanceOverlay");
            Assert.IsTrue(guidanceOverlays.Count == 15);

            // Now hide the guidance
            app.FindName("guideButton").User.Click();
            // Wait for the guidance to be hidden
            guidanceCanvas.Wait.For(canvas => canvas.Opacity == 0);

            #endregion

            #region ## Test Search ##

            //
            // Let's test the search functionality
            //

            app.VisualTree.Refresh();

            // Find the Patient Search TextBox
            TextBox searchText = app.FindName <TextBox>("searchText");

            // Move the mouse over the search box until we have an IBeam.
            searchText.User.DetectHotSpot(100, System.Windows.Forms.Cursors.IBeam);

            // Make sure the navigation bar is hidden before trying to type.
            // Currently it hides half the text box.

            // The Grid uses a TranslateTransform to hide/show the top bit
            app.FindName <Grid>("navBarGrid").Wait.For(r => (r.RenderTransform as TranslateTransform).Y == -50);

            // Now we can start typing.
            searchText.User.TypeText("A", 100);

            // Refresh the Visual Tree given the search changes.
            app.VisualTree.Refresh();

            string xml = app.VisualTree.Root.ToXml();

            ///
            /// Validate the search results.
            ///

            // Get the search lists.
            ItemsControl searchList = app.FindName <ItemsControl>("patientSearchList");

            // Get the number of results in the search.
            //
            // OBSERVER: WebAii can search custom types too not available
            // in ArtOfTest.WebAii.Silverlight.UI namespace. All the Find.xx methods have a non-generic
            // overload too that takes in a control name.
            //
            IList <FrameworkElement> foundPatients = searchList.Find.AllByType("patientsearchitem").Where(fx => fx.Visibility == Visibility.Visible).ToList();

            // Validate the search
            Assert.IsTrue(CompareUtils.NumberCompareRange(foundPatients.Count, 93, 105, NumberRangeCompareType.InRange),
                          string.Format("Actual patiends found:{0}", foundPatients.Count));

            #endregion

            #region ## Test Zoom Data ##

            ///
            /// Verify the zoom in/zoom out functionality.
            ///
            FrameworkElement zoomBox = app.FindName("zoomBox");

            // Inside of it, find the plus part
            Button plusButton = zoomBox.Find.ByName <Button>("~PlusButton");

            // Let's grab one of the patients to verify the zoom functionality on.
            FrameworkElement patientSearchItem = foundPatients.First();

            // Level 0 - Address & ContactDetails are not visible
            Assert.IsTrue(patientSearchItem.Find.ByName("Address").Visibility == Visibility.Collapsed);
            Assert.IsTrue(patientSearchItem.Find.ByName("ContactDetailsIcons").Visibility == Visibility.Collapsed);
            Assert.IsTrue(patientSearchItem.Find.ByName("AdditionalInfo").Visibility == Visibility.Collapsed);

            // Zoom level #1
            plusButton.User.Click();

            // Level 1 - ContactDetails only are visible
            Assert.IsTrue(patientSearchItem.Find.ByName("Address").Visibility == Visibility.Visible);
            Assert.IsTrue(patientSearchItem.Find.ByName("ContactDetailsIcons").Visibility == Visibility.Visible);
            Assert.IsTrue(patientSearchItem.Find.ByName("AdditionalInfo").Visibility == Visibility.Collapsed);

            // Zoom level #2
            plusButton.User.Click();

            // Level 2 - Address only is visible
            Assert.IsTrue(patientSearchItem.Find.ByName("Address").Visibility == Visibility.Visible);
            Assert.IsTrue(patientSearchItem.Find.ByName("ContactDetailsIcons").Visibility == Visibility.Collapsed);
            Assert.IsTrue(patientSearchItem.Find.ByName("AdditionalInfo").Visibility == Visibility.Visible);

            #endregion

            #region ## Test Scrolling ##

            //
            // Scroll the search results
            //

            // Find the scroll viewer
            ScrollViewer searchScroll = app.FindName("patientSearchScroller").Find.ByType <ScrollViewer>();


            AutomationMethod scrollVert = new AutomationMethod("ScrollToVerticalOffset", typeof(void));
            searchScroll.InvokeMethod(scrollVert, 2000);

            // Assert scrolling position.
            Assert.IsTrue(searchScroll.VerticalOffset == 2000);

            //
            // Close search results
            //
            app.FindName("clearSearch").User.Click();

            #endregion

            #region ## Test UI Drag/Drop ##

            //
            // Re-arrange admins UI
            //
            Grid adminsPanels = app.FindName <Grid>("adminPanels");

            IList <FrameworkElement> admins = adminsPanels.Find.AllByName("~adminDockPanel");

            FrameworkElement admin1 = admins.Where(adm => adm.Name.Equals("adminDockPanel1")).First();
            FrameworkElement admin2 = admins.Where(adm => adm.Name.Equals("adminDockPanel2")).First();
            FrameworkElement admin3 = admins.Where(adm => adm.Name.Equals("adminDockPanel3")).First();

            // Get locations before the move
            System.Drawing.Rectangle admin1Loc = admin1.GetScreenRectangle();
            System.Drawing.Rectangle admin2Loc = admin2.GetScreenRectangle();
            System.Drawing.Rectangle admin3Loc = admin3.GetScreenRectangle();

            // Now perform the drag/drop
            admin1.Find.ByType("Thumb").User.DragTo(admin2.Find.ByType("Thumb"));
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin1.Name).GetScreenRectangle(), admin2Loc);
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin2.Name).GetScreenRectangle(), admin1Loc);
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin3.Name).GetScreenRectangle(), admin3Loc);

            admin2.Find.ByType("Thumb").User.DragTo(admin3.Find.ByType("Thumb"));
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin1.Name).GetScreenRectangle(), admin1Loc);
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin2.Name).GetScreenRectangle(), admin3Loc);
            Assert.AreEqual <System.Drawing.Rectangle>(adminsPanels.Find.ByName(admin3.Name).GetScreenRectangle(), admin2Loc);

            admin1.User.HoverOver();
            admin1.User.MouseEnter(OffsetReference.LeftCenter);
            admin1.User.MouseLeave(OffsetReference.RightCenter);

            ScrollViewer admin1Scroll = app.FindName("adminDockPanel1").Find.ByType <ScrollViewer>();
            Assert.AreEqual(0, admin1Scroll.VerticalOffset);
            admin1.User.TurnMouseWheel(5, MouseWheelTurnDirection.Backward, false);
            // Scrolling is not instantaneous. Wait for the browser to do its fancy scrolling.
            admin1Scroll.Wait.For(elem => elem.As <ScrollViewer>().VerticalOffset == 50);
            Assert.AreEqual(50, admin1Scroll.VerticalOffset);

            //
            // Expand Admin1 information
            //

            admin1.Find.ByName("maximiseButton").User.Click();
            admin1.Wait.ForNoMotion(100); // Wait until the animation is complete.
            System.Drawing.Rectangle r1 = admin1.GetScreenRectangle();
            Assert.AreEqual <System.Drawing.Rectangle>(new System.Drawing.Rectangle(280, 188, 774, 568), r1);

            #endregion
        }
コード例 #7
0
 /// <summary>
 /// Gets the root element.
 /// </summary>
 /// <param name="instance">The instance.</param>
 /// <returns></returns>
 public static FrameworkElement GetRootElement(this SilverlightApp instance)
 {
     return(instance.Find.ByName <Grid>("LayoutRoot").Parent());
 }