public void PopulateData_LoadMode_ChainsToAddElementAndChildrenIntoList_CorrectParameters() { using (ShimsContext.Create()) { const DataContextMode expectedDcMode = DataContextMode.Load; const TreeViewMode expectedTreeViewMode = TreeViewMode.Control; A11yElement expectedElement = new A11yElement(); ElementDataContext dataContext = new ElementDataContext(expectedElement, 1); A11yElement actualElement = null; BoundedCounter actualCounter = null; Dictionary <int, A11yElement> actualDictionary = null; ShimCaptureAction.AddElementAndChildrenIntoListA11yElementDictionaryOfInt32A11yElementBoundedCounter = (e, d, c) => { actualElement = e; actualDictionary = d; actualCounter = c; }; CaptureAction.PopulateData(dataContext, expectedDcMode, expectedTreeViewMode); Assert.AreEqual(expectedDcMode, dataContext.Mode); Assert.AreEqual(expectedTreeViewMode, dataContext.TreeMode); Assert.AreSame(expectedElement, actualElement); Assert.IsNotNull(actualDictionary); Assert.IsFalse(actualDictionary.Any()); Assert.AreSame(dataContext.ElementCounter, actualCounter); Assert.AreSame(dataContext.Elements, actualDictionary); } }
IHttpActionResult CaptureData(Guid id, DataContextMode dm, TreeViewMode tvm, bool force) { try { if (CaptureAction.SetTestModeDataContext(id, dm, tvm, force)) { if (dm == DataContextMode.Test) { var dc = GetDataAction.GetElementDataContext(id); dc.PublishScanResults(); } return(Ok()); } else { return(StatusCode(HttpStatusCode.NotModified)); } } catch (Exception ex) { return(BadRequest(ex.ToString())); } }
public void SetTestModeDataContext_ForLoadDataContextMode_WalksTheOriginAncestorsChildrenDirectly( bool force, bool startWithNullDataContext, DataContextMode originalDataContextMode, TreeViewMode originalDataContextTreeViewMode) { // Arrange if (startWithNullDataContext) { mockElementContext.DataContext = null; } mockDataContext.Mode = originalDataContextMode; mockDataContext.TreeMode = originalDataContextTreeViewMode; TreeViewMode treeViewMode = TreeViewMode.Raw; var mockOriginAncestor = mockElement; mockOriginAncestor.UniqueId = 1; var mockChild1 = new A11yElement(); mockChild1.UniqueId = 2; var mockChild2 = new A11yElement(); mockChild2.UniqueId = 3; var mockGrandChild1 = new A11yElement(); mockGrandChild1.UniqueId = 4; mockOriginAncestor.Children = new List <A11yElement>() { mockChild1, mockChild2 }; mockChild2.Children = new List <A11yElement>() { mockGrandChild1 }; using (new CaptureActionTestHookOverrides(() => mockDataManager, null, null)) { // Act bool retVal = CaptureAction.SetTestModeDataContext(mockElementContext.Id, DataContextMode.Load, treeViewMode, force); // Assert Assert.IsTrue(retVal); Assert.IsNotNull(mockElementContext.DataContext); Assert.AreNotSame(mockDataContext, mockElementContext.DataContext); var result = mockElementContext.DataContext; Assert.AreSame(mockElement, result.Element); Assert.AreEqual(20000, result.ElementCounter.UpperBound); Assert.AreEqual(treeViewMode, result.TreeMode); Assert.AreEqual(DataContextMode.Load, result.Mode); Assert.AreEqual(mockOriginAncestor, result.RootElment); Assert.AreEqual(4, result.Elements.Count); Assert.AreSame(mockOriginAncestor, result.Elements[mockOriginAncestor.UniqueId]); Assert.AreSame(mockChild1, result.Elements[mockChild1.UniqueId]); Assert.AreSame(mockChild2, result.Elements[mockChild2.UniqueId]); Assert.AreSame(mockGrandChild1, result.Elements[mockGrandChild1.UniqueId]); } }
public void SetLiveModeDataContext_NoopsIfElementAlreadyHasComparableDataContext() { mockDataContext.Mode = DataContextMode.Live; using (new CaptureActionTestHookOverrides(() => mockDataManager, null, null)) { CaptureAction.SetLiveModeDataContext(mockElementContext.Id, mockTreeViewMode, force: false); } Assert.AreSame(mockDataContext, mockElementContext.DataContext); }
public void AddElementAndChildrenIntoList_CounterIsFull_ReturnsWithoutAdding() { BoundedCounter counter = new BoundedCounter(1); Assert.IsFalse(counter.TryAdd(2)); Assert.AreEqual(2, counter.Attempts); // We intentionally pass in nulls here, since it's an error if they're accessed in any way CaptureAction.AddElementAndChildrenIntoList(null, null, counter); Assert.AreEqual(3, counter.Attempts); }
public void SetTestModeDataContext_NoopsIfElementDoesNotNeedTestContextUpdate(DataContextMode originalMode, TreeViewMode originalTreeMode, DataContextMode newlySetMode, TreeViewMode newlySetTreeMode) { mockDataContext.Mode = originalMode; mockDataContext.TreeMode = originalTreeMode; using (new CaptureActionTestHookOverrides(() => mockDataManager, null, null)) { bool retVal = CaptureAction.SetTestModeDataContext(mockElementContext.Id, newlySetMode, newlySetTreeMode, force: false); Assert.IsFalse(retVal); Assert.AreSame(mockDataContext, mockElementContext.DataContext); } }
public void SetTestModeDataContext_ForTestDataContextMode_UsesTreeWalkerForTestToCreateNewDataContext( bool force, bool startWithNullDataContext, DataContextMode originalDataContextMode, TreeViewMode originalDataContextTreeViewMode) { // Arrange if (startWithNullDataContext) { mockElementContext.DataContext = null; } mockDataContext.Mode = originalDataContextMode; mockDataContext.TreeMode = originalDataContextTreeViewMode; TreeViewMode treeViewMode = TreeViewMode.Raw; var mockTreeWalkerForTest = new Mock <ITreeWalkerForTest>(); var mockTopMostElement = new A11yElement(); var mockElementsItem1 = new A11yElement(); mockElementsItem1.UniqueId = 101; var mockElementsItem2 = new A11yElement(); mockElementsItem2.UniqueId = 102; mockTreeWalkerForTest.Setup(w => w.Elements).Returns(new List <A11yElement> { mockElementsItem1, mockElementsItem2 }); mockTreeWalkerForTest.Setup(w => w.TopMostElement).Returns(mockTopMostElement); using (new CaptureActionTestHookOverrides(() => mockDataManager, null, (_1, _2) => mockTreeWalkerForTest.Object)) { // Act bool retVal = CaptureAction.SetTestModeDataContext(mockElementContext.Id, DataContextMode.Test, treeViewMode, force); // Assert Assert.IsTrue(retVal); Assert.IsNotNull(mockElementContext.DataContext); Assert.AreNotSame(mockDataContext, mockElementContext.DataContext); var result = mockElementContext.DataContext; Assert.AreSame(mockElement, result.Element); Assert.AreEqual(20000, result.ElementCounter.UpperBound); Assert.AreEqual(treeViewMode, result.TreeMode); Assert.AreEqual(DataContextMode.Test, result.Mode); Assert.AreEqual(mockTopMostElement, result.RootElment); mockTreeWalkerForTest.Verify(w => w.RefreshTreeData(treeViewMode)); Assert.AreEqual(2, result.Elements.Count); Assert.AreSame(mockElementsItem1, result.Elements[mockElementsItem1.UniqueId]); Assert.AreSame(mockElementsItem2, result.Elements[mockElementsItem2.UniqueId]); } }
public void PopulateData_TestMode_ChainsToTreeWalkerRefreshTreeData_CorrectParameters() { using (ShimsContext.Create()) { const DataContextMode expectedDcMode = DataContextMode.Test; const TreeViewMode expectedTreeViewMode = TreeViewMode.Content; A11yElement expectedElement = new A11yElement(); List <A11yElement> expectedElements = null; ElementDataContext dataContext = new ElementDataContext(expectedElement, 1); BoundedCounter actualCounter = null; A11yElement actualElement = null; TreeViewMode? actualTreeMode = null; A11yElement rootElement = null; ShimTreeWalkerForTest.ConstructorA11yElementBoundedCounter = (ktw, e, c) => { actualCounter = c; actualElement = e; new ShimTreeWalkerForTest(ktw) { RefreshTreeDataTreeViewMode = (mode) => { actualTreeMode = mode; expectedElements = new List <A11yElement> { expectedElement }; rootElement = expectedElement; Assert.IsTrue(dataContext.ElementCounter.TryIncrement()); }, ElementsGet = () => expectedElements, TopMostElementGet = () => rootElement, }; }; CaptureAction.PopulateData(dataContext, expectedDcMode, expectedTreeViewMode); Assert.AreSame(dataContext.ElementCounter, actualCounter); Assert.AreSame(expectedElement, actualElement); Assert.AreEqual(expectedDcMode, dataContext.Mode); Assert.AreEqual(expectedTreeViewMode, dataContext.TreeMode); Assert.AreSame(expectedElement, dataContext.Elements.Values.First()); Assert.AreSame(expectedElement, dataContext.RootElment); } }
public ResultsT Scan <ResultsT>(A11yElement element, ScanActionCallback <ResultsT> scanCallback) { if (element == null) { throw new ArgumentNullException(nameof(element)); } if (scanCallback == null) { throw new ArgumentNullException(nameof(scanCallback)); } using (var dataManager = DataManager.GetDefaultInstance()) using (var sa = SelectAction.GetDefaultInstance()) { sa.SetCandidateElement(element); if (!sa.Select()) { throw new AxeWindowsAutomationException(DisplayStrings.ErrorUnableToSetDataContext); } using (ElementContext ec2 = sa.POIElementContext) { Stopwatch stopwatch = Stopwatch.StartNew(); GetDataAction.GetProcessAndUIFrameworkOfElementContext(ec2.Id); if (!CaptureAction.SetTestModeDataContext(ec2.Id, DataContextMode.Test, TreeViewMode.Control)) { throw new AxeWindowsAutomationException(DisplayStrings.ErrorUnableToSetDataContext); } long scanDurationInMilliseconds = stopwatch.ElapsedMilliseconds; // send telemetry of scan results. var dc = GetDataAction.GetElementDataContext(ec2.Id); dc.PublishScanResults(scanDurationInMilliseconds); if (dc.ElementCounter.UpperBoundExceeded) { throw new AxeWindowsAutomationException(string.Format(CultureInfo.InvariantCulture, DisplayStrings.ErrorTooManyElementsToSetDataContext, dc.ElementCounter.UpperBound)); } return(scanCallback(ec2.Element, ec2.Id)); } // using }// using }
public void AddElementAndChildrenIntoList_GeneralCase_BuildsCorrectDictionary() { using (ShimsContext.Create()) { const int elementCount = 7; BoundedCounter counter = new BoundedCounter(100); Dictionary <int, A11yElement> elementsOut = new Dictionary <int, A11yElement>(); // Build our tree List <ShimA11yElement> elements = new List <ShimA11yElement>(); for (int loop = 0; loop < elementCount; loop++) { int uniqueId = loop; elements.Add(new ShimA11yElement { UniqueIdGet = () => uniqueId, // Don't use loop here, since it will get the final value, not the in-loop value }); } elements[0].ChildrenGet = () => new List <A11yElement> { elements[1], elements[2] }; elements[2].ChildrenGet = () => new List <A11yElement> { elements[3] }; elements[3].ChildrenGet = () => new List <A11yElement> { elements[4], elements[5], elements[6] }; elements[6].ChildrenGet = () => new List <A11yElement>(); CaptureAction.AddElementAndChildrenIntoList(elements[0], elementsOut, counter); Assert.AreEqual(elementCount, elementsOut.Count); for (int loop = 0; loop < elementCount; loop++) { Assert.AreEqual(loop, elementsOut[loop].UniqueId); } } }
public void SetTestModeDataContext_OldContextIsNull_CreatesElementDataContext_ChainsToPopulateData_CorrectParameters() { using (ShimsContext.Create()) { ElementDataContext dataContext = null; ElementContext elementContext = new ShimElementContext { DataContextGet = () => dataContext, DataContextSetElementDataContext = (dcNew) => { dataContext = dcNew; }, }; ShimDataManager.GetDefaultInstance = () => new ShimDataManager { GetElementContextGuid = (_) => elementContext, }; ElementDataContext actualContext = null; DataContextMode? actualMode = null; TreeViewMode? actualTreeViewMode = null; ShimCaptureAction.PopulateDataElementDataContextDataContextModeTreeViewMode = (dc, dcMode, tm) => { actualContext = dc; actualMode = dcMode; actualTreeViewMode = tm; }; Assert.IsTrue(CaptureAction.SetTestModeDataContext(Guid.Empty, DataContextMode.Test, TreeViewMode.Content)); Assert.IsNotNull(dataContext); Assert.AreEqual(0, dataContext.ElementCounter.Count); Assert.AreEqual(20000, dataContext.ElementCounter.UpperBound); Assert.AreSame(dataContext, actualContext); Assert.AreEqual(DataContextMode.Test, actualMode); Assert.AreEqual(TreeViewMode.Content, actualTreeViewMode); } }
public void AddElementAndChildrenIntoList_GeneralCase_BuildsCorrectDictionary() { const int elementCount = 7; BoundedCounter counter = new BoundedCounter(100); Dictionary <int, A11yElement> elementsOut = new Dictionary <int, A11yElement>(); // Build our tree List <A11yElement> elements = new List <A11yElement>(); for (int loop = 0; loop < elementCount; loop++) { A11yElement element = new A11yElement { UniqueId = loop }; elements.Add(element); } elements[0].Children = new List <A11yElement> { elements[1], elements[2] }; elements[2].Children = new List <A11yElement> { elements[3] }; elements[3].Children = new List <A11yElement> { elements[4], elements[5], elements[6] }; elements[6].Children = new List <A11yElement>(); CaptureAction.AddElementAndChildrenIntoList(elements[0], elementsOut, counter); Assert.AreEqual(elementCount, elementsOut.Count); for (int loop = 0; loop < elementCount; loop++) { Assert.AreEqual(loop, elementsOut[loop].UniqueId); } }
/// <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> /// Update selected element /// </summary> /// <param name="ecId">Element Context Id</param> public async Task SetElement(Guid ecId) { this.ElementContext = null; this.SelectedInHierarchyElement = null; EnableSelectorWhenPOISelectedInHierarchy = false; var ec = GetDataAction.GetElementContext(ecId); if (ec != null) { var prevFocus = Keyboard.FocusedElement; try { this.ctrlProgressRing.Activate(); this.ctrlHierarchy.IsEnabled = false; ctrlHierarchy.Visibility = Visibility.Visible; svInstructions.Visibility = Visibility.Collapsed; await Task.Run(() => { CaptureAction.SetLiveModeDataContext(ecId, Configuration.TreeViewMode); }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { this.ctrlHierarchy.DataContext = ec.DataContext; this.ElementContext = ec; // make sure that when selected node is changed in hiearchy tree, enable selector. EnableSelectorWhenPOISelectedInHierarchy = true; this.ctrlHierarchy.SetElement(ec); AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, "Live inspect with {0}", ec.Element.Glimpse)); }); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); // if there was any exception, make sure that we enable selector later. EnableSelectorWhenPOISelectedInHierarchy = false; } #pragma warning restore CA1031 // Do not catch general exception types finally { this.ctrlProgressRing.Deactivate(); Application.Current.Dispatcher.Invoke(() => { this.ctrlHierarchy.IsEnabled = true; // if the previously focused element is no longer visible and focus has gone to the window, // we will set focus back 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 (prevFocus is FrameworkElement fe && !fe.IsVisible && Keyboard.FocusedElement is Window) { this.ctrlHierarchy.Focus(); } }); } } else { Clear(); } if (EnableSelectorWhenPOISelectedInHierarchy == false) { Application.Current.Dispatcher.Invoke(() => UpdateStateMachineForLiveMode()); } }
/// <summary> /// set element /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { if (GetDataAction.ExistElementContext(ecId)) { try { HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter; HollowHighlightDriver.GetDefaultInstance().SetElement(ecId, 0); this.ctrlContrast.ActivateProgressRing(); ElementContext ec = null; string warning = string.Empty; string toolTipText = 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); } }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { if (ec == null || ec.Element == null) { toolTipText = Properties.Resources.ColorContrast_NoElementSelected; } else { if (ControlType.GetInstance().Values.Contains(ec.Element.ControlTypeId)) { Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { this.ctrlContrast.SetElement(ec); })).Wait(); toolTipText = string.Format(CultureInfo.InvariantCulture, Properties.Resources.ColorContrast_RatioAndConfidenceFormat, this.ctrlContrast.Ratio, this.ctrlContrast.Confidence); } else { toolTipText = Properties.Resources.ColorContrast_UnknownElementType; } } MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(toolTipText); // enable element selector MainWin.EnableElementSelector(); }); this.ctrlContrast.DeactivateProgressRing(); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { ex.ReportException(); Application.Current.Dispatcher.Invoke(() => { MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(Properties.Resources.ColorContrast_UnableToDetectColors); // enable element selector MainWin.EnableElementSelector(); this.ctrlContrast.ClearUI(); this.ctrlContrast.DeactivateProgressRing(); }); } #pragma warning restore CA1031 // Do not catch general exception types } }
/// <summary> /// set element /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { if (GetDataAction.ExistElementContext(ecId)) { try { HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.Highlighter; HollowHighlightDriver.GetDefaultInstance().SetElement(ecId, 0); this.ctrlContrast.ActivateProgressRing(); ElementContext ec = null; string warning = string.Empty; string toolTipText = 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); } }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { if (ec == null || ec.Element == null) { toolTipText = "No Eelement Selected!"; } else { if (CCAControlTypesFilter.GetDefaultInstance().Contains(ec.Element.ControlTypeId)) { Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { this.ctrlContrast.SetElement(ec); })).Wait(); toolTipText = string.Format(CultureInfo.InvariantCulture, "Ratio: {0}\nConfidence: {1}", this.ctrlContrast.getRatio(), this.ctrlContrast.getConfidence()); } else { toolTipText = "Unknown Element Type!"; } } MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText(toolTipText); // enable element selector MainWin.EnableElementSelector(); }); this.ctrlContrast.DeactivateProgressRing(); } catch (Exception ex) { ex.ReportException(); Application.Current.Dispatcher.Invoke(() => { MainWin.CurrentView = CCAView.Automatic; HollowHighlightDriver.GetDefaultInstance().HighlighterMode = HighlighterMode.HighlighterTooltip; HollowHighlightDriver.GetDefaultInstance().SetText("Unable to detect colors!"); // enable element selector MainWin.EnableElementSelector(); this.ctrlContrast.DeactivateProgressRing(); }); } } }
/// <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(); }); }