public void CaptureScreenShot_ElementWithBoundingRectangle_ScreenShotCreated() { using (var dm = new DataManager()) { A11yElement element = new A11yElement { UniqueId = 42, }; SetBoundingRectangle(element, new Rectangle(0, 0, 10, 10)); var dc = new ElementDataContext(element, 1); var elementContext = new ElementContext(element) { DataContext = dc, }; dm.AddElementContext(elementContext); ScreenShotAction.GetDataManager = () => dm; ScreenShotAction.CopyFromScreen = (g, x, y, s) => { }; ScreenShotAction.CaptureScreenShot(elementContext.Id); Assert.IsNotNull(dc.Screenshot); Assert.AreEqual(element.UniqueId, dc.ScreenshotElementId); } }
public void CaptureScreenShot_ElementWithoutBoundingRectangle_NoScreenShot() { using (var dm = new DataManager()) { // no bounding rectangle. A11yElement element = new A11yElement { UniqueId = 42, }; var dc = new ElementDataContext(element, 1); var elementContext = new ElementContext(element) { DataContext = dc, }; dm.AddElementContext(elementContext); ScreenShotAction.GetDataManager = () => dm; ScreenShotAction.CaptureScreenShot(elementContext.Id); Assert.IsNull(dc.Screenshot); Assert.AreEqual(default(int), dc.ScreenshotElementId); } }
public void CaptureScreenShotOnWCOS_ElementWithBoundingRectangle_NoScreenShot() { using (var dm = new DataManager()) { A11yElement element = new A11yElement { UniqueId = 42, }; SetBoundingRectangle(element, new Rectangle(0, 0, 10, 10)); var dc = new ElementDataContext(element, 1); var elementContext = new ElementContext(element) { DataContext = dc, }; dm.AddElementContext(elementContext); ScreenShotAction.GetDataManager = () => dm; ScreenShotAction.CreateBitmap = (w, h) => throw new TypeInitializationException("Bitmap", null); ScreenShotAction.CaptureScreenShot(elementContext.Id); Assert.IsNull(dc.Screenshot); Assert.AreEqual(default(int), dc.ScreenshotElementId); } }
public void CaptureScreenShot_ElementWithBoundingRectangle_ScreenShotCreated() { using (ShimsContext.Create()) { bool bitmapsetcalled = false; // bounding rectangle exists. A11yElement element = new ShimA11yElement { ParentGet = () => null, BoundingRectangleGet = () => new Rectangle(0, 0, 10, 10), UniqueIdGet = () => 1, }; ElementDataContext dc = new ShimElementDataContext() { ScreenshotSetBitmap = (_) => bitmapsetcalled = true, }; ElementContext elementContext = new ShimElementContext { ElementGet = () => element, DataContextGet = () => dc, }; ShimDataManager.GetDefaultInstance = () => new ShimDataManager { GetElementContextGuid = (_) => elementContext, }; Graphics g = new ShimGraphics(); ShimGraphics.FromImageImage = (_) => g; ScreenShotAction.CaptureScreenShot(Guid.NewGuid()); // bitmap is set Assert.IsTrue(bitmapsetcalled); } }
public void CaptureScreenShotOnWCOS_ElementWithBoundingRectangle_NoScreenShot() { using (ShimsContext.Create()) { bool bitmapsetcalled = false; // bounding rectangle exists. A11yElement element = new ShimA11yElement { ParentGet = () => null, BoundingRectangleGet = () => new Rectangle(0, 0, 10, 10), UniqueIdGet = () => 1, }; ElementDataContext dc = new ShimElementDataContext() { ScreenshotSetBitmap = (_) => bitmapsetcalled = true, }; ElementContext elementContext = new ShimElementContext { ElementGet = () => element, DataContextGet = () => dc, }; ShimDataManager.GetDefaultInstance = () => new ShimDataManager { GetElementContextGuid = (_) => elementContext, }; ShimBitmap.ConstructorInt32Int32 = (_, w, h) => throw new TypeInitializationException("Bitmap", null); ScreenShotAction.CaptureScreenShot(Guid.NewGuid()); // screenshot is not set(null) Assert.IsNull(dc.Screenshot); // ScreenShotSet was not called. Assert.IsFalse(bitmapsetcalled); } }
public void CaptureScreenShot_ElementWithoutBoundingRectangle_NoScreenShot() { using (ShimsContext.Create()) { bool bitmapsetcalled = false; // no bounding rectangle. A11yElement element = new ShimA11yElement { ParentGet = () => null, BoundingRectangleGet = () => Rectangle.Empty, }; ElementDataContext dc = new ShimElementDataContext() { ScreenshotSetBitmap = (_) => bitmapsetcalled = true, }; ElementContext elementContext = new ShimElementContext { ElementGet = () => element, DataContextGet = () => dc, }; ShimDataManager.GetDefaultInstance = () => new ShimDataManager { GetElementContextGuid = (_) => elementContext, }; ScreenShotAction.CaptureScreenShot(Guid.NewGuid()); // screenshot is not set(null) Assert.IsNull(dc.Screenshot); // ScreenShotSet was not called. Assert.IsFalse(bitmapsetcalled); } }
/// <summary> /// Update Element Info UI(Properties/Patterns/Tests) /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { this.ctrlProgressRing.Activate(); EnableMenuButtons(this.DataContextMode != DataContextMode.Load); bool selectionFailure = false; try { this.ctrlHierarchy.IsEnabled = false; ElementContext ec = null; await Task.Run(() => { CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode); ec = GetDataAction.GetElementContext(ecId); // send telemetry of scan results. var dc = GetDataAction.GetElementDataContext(ecId); dc.PublishScanResults(); }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { if (ec != null && ec.DataContext != null) { this.ElementContext = ec; this.ctrlTabs.Clear(); if (!SelectAction.GetDefaultInstance().IsPaused) { this.ctrlHierarchy.CleanUpTreeView(); } this.ctrlHierarchy.SetElement(ec); this.ctrlTabs.SetElement(ec.Element, false, ec.Id); if (ec.DataContext.Screenshot == null && ec.DataContext.Mode != DataContextMode.Load) { Application.Current.MainWindow.WindowStyle = WindowStyle.ToolWindow; Application.Current.MainWindow.Visibility = Visibility.Hidden; HollowHighlightDriver.GetDefaultInstance().IsEnabled = false; this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { ScreenShotAction.CaptureScreenShot(ecId); Application.Current.MainWindow.Visibility = Visibility.Visible; Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow; })).Wait(); } var imageOverlay = ImageOverlayDriver.GetDefaultInstance(); imageOverlay.SetImageElement(ecId); //disable button on highlighter. imageOverlay.SetHighlighterButtonClickHandler(null); if (Configuration.IsHighlighterOn) { imageOverlay.Show(); } } // if it is enforced to select a specific element(like fastpass click case) if (ec.DataContext.FocusedElementUniqueId.HasValue) { this.ctrlHierarchy.SelectElement(ec.DataContext.FocusedElementUniqueId.Value); } if (!ec.DataContext.Elements.TryGetValue(ec.DataContext.FocusedElementUniqueId ?? 0, out A11yElement selectedElement)) { selectedElement = ec.DataContext.Elements[0]; } AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetElementInspectTestDetail, selectedElement.Glimpse)); FireAsyncContentLoadedEvent(AsyncContentLoadedState.Completed); // Set focus on hierarchy tree Dispatcher.InvokeAsync(() => this.ctrlHierarchy.SetFocusOnHierarchyTree(), DispatcherPriority.Input).Wait(); ec.DataContext.FocusedElementUniqueId = null; }); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Visibility = Visibility.Visible; EnableMenuButtons(false); this.ElementContext = null; selectionFailure = true; }); } #pragma warning restore CA1031 // Do not catch general exception types finally { Application.Current.Dispatcher.Invoke(() => { this.ctrlProgressRing.Deactivate(); this.ctrlHierarchy.IsEnabled = true; // if focus has gone to the window, we set focus to the hierarchy control. We do this because disabling the hierarchy control // will throw keyboard focus to mainwindow, where it is not very useful. if (Keyboard.FocusedElement is Window) { this.ctrlHierarchy.Focus(); } if (selectionFailure) { MainWin.HandleFailedSelectionReset(); } else { // Set the right view state : if (MainWin.CurrentView is TestView iv && iv == TestView.ElementHowToFix) { MainWin.SetCurrentViewAndUpdateUI(TestView.ElementHowToFix); }
/// <summary> /// Sets element context and updates UI /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { EnableMenuButtons(false); // first disable them to avoid any conflict. bool selectionFailure = false; if (GetDataAction.ExistElementContext(ecId)) { EnableMenuButtons(this.DataContextMode != DataContextMode.Load); this.ctrlAutomatedChecks.Visibility = Visibility.Visible; this.tbSelectElement.Visibility = Visibility.Collapsed; this.tabControl.IsEnabled = true; try { AutomationProperties.SetName(this, "Test"); this.tabControl.IsEnabled = false; this.ctrlProgressRing.Activate(); ElementContext ec = null; string warning = string.Empty; await Task.Run(() => { var updated = CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode); ec = GetDataAction.GetElementContext(ecId); // send telemetry of scan results. var dc = GetDataAction.GetElementDataContext(ecId); if (dc.ElementCounter.UpperBoundExceeded) { warning = string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetElementCultureInfoFormatMessage, dc.ElementCounter.UpperBound); IsSaveEnabled = false; } dc.PublishScanResults(); }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { if (ec.Element == null || ec.Element.Properties == null || ec.Element.Properties.Count == 0) { this.ctrlAutomatedChecks.ClearUI(); selectionFailure = true; } else { if (ec.DataContext.Screenshot == null && ec.DataContext.Mode != DataContextMode.Load) { if (ec.Element.BoundingRectangle.IsEmpty == true) { MessageDialog.Show(Properties.Resources.noScreenShotAvailableMessage); } else { Application.Current.MainWindow.WindowStyle = WindowStyle.ToolWindow; Application.Current.MainWindow.Visibility = Visibility.Hidden; HollowHighlightDriver.GetDefaultInstance().IsEnabled = false; this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { ScreenShotAction.CaptureScreenShot(ecId); Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow; // This needs to happen before the call to ctrlAutomatedChecks.SetElement. Otherwise, // ctrlAutomatedChecks's checkboxes become out of sync with the highlighter Application.Current.MainWindow.Visibility = Visibility.Visible; })).Wait(); } } this.tabControl.IsEnabled = true; this.ctrlAutomatedChecks.SetElement(ec); this.ElementContext = ec; if (ec.DataContext.Mode == DataContextMode.Test) { tbiTabStop.Visibility = Visibility.Visible; this.ctrlTabStop.SetElement(ec); } else { tbiTabStop.Visibility = Visibility.Collapsed; } var count = ec.DataContext?.GetRuleResultsViewModelList()?.Count ?? 0; AutomationProperties.SetName(this, Invariant($"{Properties.Resources.detectedFailuresMessagePart1} {this.ElementContext.Element.Glimpse}. {count} {Properties.Resources.detectedFailuresMessagePart2}")); if (!string.IsNullOrEmpty(warning)) { MessageDialog.Show(warning); } ///Set focus on automated checks tab. FireAsyncContentLoadedEvent(AsyncContentLoadedState.Completed); } }); } catch (Exception) { Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Visibility = Visibility.Visible; this.Clear(); selectionFailure = true; EnableMenuButtons(false); this.ElementContext = null; }); } finally { Application.Current.Dispatcher.Invoke(() => { this.ctrlProgressRing.Deactivate(); }); } } Application.Current.Dispatcher.Invoke(() => { // Set the right view state : if (selectionFailure) { MainWin.HandleFailedSelectionReset(); } else { MainWin.SetCurrentViewAndUpdateUI(TestView.AutomatedTestResults); } // Improves the reliability of the rendering but does not solve across the board issues seen with all WPF apps. this.Dispatcher.BeginInvoke(DispatcherPriority.Send, new Action(() => { Application.Current.MainWindow.InvalidateVisual(); Application.Current.MainWindow.Visibility = Visibility.Visible; this.tbiAutomatedChecks.Focus(); })).Wait(); }); }
public void CaptureScreenshot(Guid elementId) { ScreenShotAction.CaptureScreenShot(elementId); }