public void Execute_NoScanResultsInPOI_RetentionIsEnabled_SavesFile_ReturnsCompleteWithNoIssues() { using (ShimsContext.Create()) { ShimSelectAction selectAction = new ShimSelectAction() { SetCandidateElementA11yElement = (element) => { }, Select = () => true, POIElementContextGet = () => new ElementContext( new A11yElement { ScanResults = new ScanResults(), Children = new List <A11yElement> { new A11yElement { ScanResults = new ScanResults(), Children = new List <A11yElement>(), } } }), }; InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true, selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true, setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); AssertCompleteResult(result, 0, 0, 0, 0); } }
public void Execute_NullResultsAssembler_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns <IScanResultsAssembler>(null); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); ScanResults tempResults = null; _actionsMock.Setup(x => x.Scan(It.IsAny <A11yElement>(), It.IsAny <ScanActionCallback <ScanResults> >())) .Callback <A11yElement, ScanActionCallback <ScanResults> >((e, cb) => tempResults = cb(e, Guid.Empty)) .Returns(() => tempResults); var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException)); Assert.IsTrue(ex.Message.Contains("ResultsAssembler")); _scanToolsMock.VerifyAll(); _nativeMethodsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); }
public void Execute_OnlyUnsupportedsInPOI_RetentionIsEnabled_SavesFile_ReturnsComplete_UnsupportedsOnly() { using (ShimsContext.Create()) { List <ScanStatus> scanStatusUnsupported = new List <ScanStatus> { ScanStatus.ScanNotSupported }; ShimSelectAction selectAction = new ShimSelectAction() { SetCandidateElementA11yElement = (element) => { }, Select = () => true, POIElementContextGet = () => new ElementContext( CreateA11yElement( new List <A11yElement> { CreateA11yElement(new List <A11yElement>(), scanStatusUnsupported) }, scanStatusUnsupported)) }; InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true, selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true, setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); AssertCompleteResult(result, 0, 0, 0, 2); } }
public void Execute_NullOutputFilePath_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object); _scanToolsMock.Setup(x => x.OutputFileHelper).Returns(_outputFileHelperMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); var expectedResults = new ScanResults(); expectedResults.ErrorCount = 1; InitResultsCallback(expectedResults); _actionsMock.Setup(x => x.CaptureScreenshot(It.IsAny <Guid>())); _outputFileHelperMock.Setup(x => x.GetNewA11yTestFilePath()).Returns <string>(null); var config = Config.Builder .ForProcessId(-1) .WithOutputFileFormat(OutputFileFormat.A11yTest) .Build(); var action = new Action(() => SnapshotCommand.Execute(config, _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException)); Assert.IsTrue(ex.Message.Contains("a11yTestOutputFile")); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); _resultsAssemblerMock.VerifyAll(); _outputFileHelperMock.VerifyAll(); }
public void Execute_NullScanTools_ThrowsException() { var action = new Action(() => SnapshotCommand.Execute(config: _minimalConfig, scanTools: null)); var ex = Assert.ThrowsException <ArgumentNullException>(action); Assert.IsTrue(ex.Message.Contains("scanTools")); }
public void Execute_TargetElementLocatorReceivesExpectedParameters() { using (ShimsContext.Create()) { CommandParameters actualParameters = null; CommandParameters expectedParameters = new CommandParameters(TestParameters, string.Empty); ShimAutomationSession.Instance = () => { return(new ShimAutomationSession() { SessionParametersGet = () => expectedParameters }); }; ShimTargetElementLocator.LocateElementCommandParameters = (commandParameters) => { actualParameters = commandParameters; throw new Exception(TestMessage); }; InitializeShims(populateLocationHelper: false); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); Utilities.AssertEqual(expectedParameters.ConfigCopy, actualParameters.ConfigCopy); AssertIncompleteResult(result, TestMessage, false); } }
public void Execute_NullConfig_ThrowsException() { var action = new Action(() => SnapshotCommand.Execute(config: null, scanTools: _scanToolsMock.Object)); var ex = Assert.ThrowsException <ArgumentNullException>(action); Assert.IsTrue(ex.Message.Contains("config")); }
public void Execute_NoErrors_NoOutputFiles() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); var expectedResults = new ScanResults(); expectedResults.ErrorCount = 0; InitResultsCallback(expectedResults); // In addition to throwing an ArgumentNullException // The following call would cause mock exceptions for IAxeWindowsActions.CaptureScreenshot and IAxeWindowsActions.SaveA11yTestFile. // var config = Config.Builder .ForProcessId(-1) .WithOutputFileFormat(OutputFileFormat.A11yTest) .Build(); var actualResults = SnapshotCommand.Execute(config, _scanToolsMock.Object); Assert.IsNull(actualResults.OutputFile.A11yTest); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); _resultsAssemblerMock.VerifyAll(); }
public void Execute_NullOutputFileHelper_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object); _scanToolsMock.Setup(x => x.OutputFileHelper).Returns <IOutputFileHelper>(null); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); var expectedResults = new ScanResults(); expectedResults.ErrorCount = 1; InitResultsCallback(expectedResults); var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException)); Assert.IsTrue(ex.Message.Contains("OutputFileHelper")); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); _resultsAssemblerMock.VerifyAll(); }
public void Execute_NullScanTools_ThrowsException() { var action = new Action(() => SnapshotCommand.Execute(config: _minimalConfig, scanTools: null)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException)); Assert.IsTrue(ex.Message.Contains("scanTools")); }
public void Execute_NullConfig_ThrowsException() { var action = new Action(() => SnapshotCommand.Execute(config: null, scanTools: _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentException)); Assert.IsTrue(ex.Message.Contains("config")); }
public void Execute_NullTargetElementLocator_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns <ITargetElementLocator>(null); var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object)); var ex = Assert.ThrowsException <ArgumentException>(action); Assert.IsTrue(ex.Message.Contains("TargetElementLocator")); _scanToolsMock.VerifyAll(); }
public void VerifyAccessibility() { var result = SnapshotCommand.Execute(new Dictionary <string, string> { { CommandConstStrings.TargetProcessId, testAppProcessId.ToString() }, { CommandConstStrings.OutputFile, "GettingStartedPage" }, { CommandConstStrings.OutputFileFormat, "a11ytest" } }); Assert.AreEqual(0, result.ScanResultsFailedCount); }
public void Execute_NullAxeWindowsActions_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns <IAxeWindowsActions>(null); var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(ArgumentNullException)); Assert.IsTrue(ex.Message.Contains("Actions")); _scanToolsMock.VerifyAll(); }
public void Execute_MixedResultsInPOI_RetentionIsEnabled_SavesFile_ReturnsComplete_CorrectMixedResults() { using (ShimsContext.Create()) { ShimSelectAction selectAction = new ShimSelectAction() { SetCandidateElementA11yElement = (element) => { }, Select = () => true, POIElementContextGet = () => new ElementContext( CreateA11yElement( new List <A11yElement> { CreateA11yElement(new List <A11yElement>(), new List <ScanStatus> { ScanStatus.Fail, ScanStatus.Pass // Will count as failure }), CreateA11yElement(new List <A11yElement>(), new List <ScanStatus> { ScanStatus.Pass // Will count as pass }), CreateA11yElement(new List <A11yElement>(), new List <ScanStatus> { ScanStatus.Uncertain, ScanStatus.Uncertain, ScanStatus.ScanNotSupported // Will count as unsupported }), CreateA11yElement(new List <A11yElement>(), new List <ScanStatus> { ScanStatus.Pass, ScanStatus.Uncertain, ScanStatus.NoResult // Will count as uncertain }), CreateA11yElement(new List <A11yElement>(), new List <ScanStatus> { ScanStatus.Uncertain, ScanStatus.NoResult // Will count as uncertain }), }, new List <ScanStatus> { ScanStatus.Pass // Will count as pass })) }; InitializeShims(populateLocationHelper: true, enableRetention: true, shimTargetElementLocator: true, selectAction: selectAction, elementBoundExceeded: false, shimUiFramework: true, setTestModeSucceeds: true, shimScreenCapture: true, shimSnapshot: true, shimSarif: true); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); // Note: Results are for each A11yElement, not for each ScanStatus! AssertCompleteResult(result, 2, 1, 2, 1); } }
public void Execute_TargetElementLocatorReturnsNull_ThrowsException() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns <A11yElement>(null); var action = new Action(() => SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object)); var ex = Assert.ThrowsException <AxeWindowsAutomationException>(action); Assert.IsInstanceOfType(ex.InnerException, typeof(InvalidOperationException)); Assert.IsTrue(ex.Message.Contains("rootElement")); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); }
public void Execute_TargetElementLocatorReturnsNull_PassesNullToScan() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElements(It.IsAny <int>())).Returns <IEnumerable <A11yElement> >(null); SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object); _scanToolsMock.VerifyAll(); _nativeMethodsMock.VerifyAll(); _actionsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); }
public void Execute_TargetElementLocatorReceivesConfigProcessId() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(42)).Returns <A11yElement>(null); var config = Config.Builder.ForProcessId(42).Build(); var action = new Action(() => SnapshotCommand.Execute(config, _scanToolsMock.Object)); Assert.ThrowsException <AxeWindowsAutomationException>(action); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); }
public void Execute_ActionsScan_IsCalledWithExpectedElement() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); var element = new A11yElement(); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(element); _actionsMock.Setup(x => x.Scan(element, It.IsAny <ScanActionCallback <ScanResults> >())).Returns <ScanResults>(null); SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); }
public void Execute_UnableToSelectCandidateElement_ReturnsIncomplete_ErrorAutomation008() { using (ShimsContext.Create()) { ShimSelectAction selectAction = new ShimSelectAction() { SetCandidateElementA11yElement = (element) => { }, Select = () => false, }; InitializeShims(selectAction: selectAction, populateLocationHelper: false, enableRetention: true, shimTargetElementLocator: true); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); AssertIncompleteResult(result, " Automation008:", false); } }
public void Execute_UnableToSetTestModeDataContext_ReturnsIncomplete_ErrorAutomation008() { using (ShimsContext.Create()) { ShimSelectAction selectAction = new ShimSelectAction() { SetCandidateElementA11yElement = (element) => { }, Select = () => true, POIElementContextGet = () => new ElementContext(CreateA11yElement()), }; InitializeShims(populateLocationHelper: false, enableRetention: true, shimTargetElementLocator: true, shimUiFramework: true, setTestModeSucceeds: false); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); AssertIncompleteResult(result, " Automation008:", false); } }
public void Execute_ActionsScan_IsCalledWithExpectedElement() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object); var elements = CreateMockElementArray(); _targetElementLocatorMock.Setup(x => x.LocateRootElements(It.IsAny <int>())).Returns(elements); _actionsMock.Setup(x => x.Scan( elements.First(), It.IsAny <ScanActionCallback <ScanResults> >())).Returns <ScanResults>(null); SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object); _scanToolsMock.VerifyAll(); _nativeMethodsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); }
/// <summary> /// This is where the scan is triggered /// </summary> protected override void ProcessRecord() { Dictionary <string, string> parameters = new Dictionary <string, string>(); if (!string.IsNullOrEmpty(this.TargetProcessId)) { parameters[CommandConstStrings.TargetProcessId] = this.TargetProcessId; } if (!string.IsNullOrEmpty(this.OutputFile)) { parameters[CommandConstStrings.OutputFile] = this.OutputFile; } using (new AppDomainAdjuster()) { WriteObject(SnapshotCommand.Execute(parameters)); } }
public void Execute_TargetElementLocatorReceivesConfigProcessId() { const int expectedProcessId = 42; _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElements(expectedProcessId)).Returns(CreateMockElementArray()); _actionsMock.Setup(x => x.Scan(It.IsNotNull <A11yElement>(), It.IsNotNull <ScanActionCallback <ScanResults> >())).Returns <ScanResults>(null); var config = Config.Builder.ForProcessId(expectedProcessId).Build(); SnapshotCommand.Execute(config, _scanToolsMock.Object); _scanToolsMock.VerifyAll(); _nativeMethodsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); }
public void Execute_AutomationSessionInstanceThrowsAutomationException_ReturnsIncomplete_MessageMatchesException() { using (ShimsContext.Create()) { int callsToInstance = 0; ShimAutomationSession.Instance = () => { callsToInstance++; throw new A11yAutomationException(TestMessage); }; InitializeShims(); SnapshotCommandResult result = SnapshotCommand.Execute(new Dictionary <string, string>()); Assert.AreEqual(1, callsToInstance); AssertIncompleteResult(result, TestMessage); } }
public void Execute_ReturnsExpectedResults() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); var expectedResults = new ScanResults(); InitResultsCallback(expectedResults); var actualResults = SnapshotCommand.Execute(_minimalConfig, _scanToolsMock.Object); Assert.AreEqual(expectedResults, actualResults); _scanToolsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); _resultsAssemblerMock.VerifyAll(); }
public void Execute_WithErrors_CreatesSnapshotAndA11yTestFile() { _scanToolsMock.Setup(x => x.TargetElementLocator).Returns(_targetElementLocatorMock.Object); _scanToolsMock.Setup(x => x.Actions).Returns(_actionsMock.Object); _scanToolsMock.Setup(x => x.NativeMethods).Returns(_nativeMethodsMock.Object); _scanToolsMock.Setup(x => x.ResultsAssembler).Returns(_resultsAssemblerMock.Object); _scanToolsMock.Setup(x => x.OutputFileHelper).Returns(_outputFileHelperMock.Object); _targetElementLocatorMock.Setup(x => x.LocateRootElement(It.IsAny <int>())).Returns(new A11yElement()); var expectedResults = new ScanResults(); expectedResults.ErrorCount = 75; InitResultsCallback(expectedResults); var expectedPath = "Test.file"; _actionsMock.Setup(x => x.CaptureScreenshot(It.IsAny <Guid>())); _actionsMock.Setup(x => x.SaveA11yTestFile(expectedPath, It.IsAny <A11yElement>(), It.IsAny <Guid>())); _outputFileHelperMock.Setup(m => m.EnsureOutputDirectoryExists()); _outputFileHelperMock.Setup(x => x.GetNewA11yTestFilePath()).Returns(expectedPath); var config = Config.Builder .ForProcessId(-1) .WithOutputFileFormat(OutputFileFormat.A11yTest) .Build(); var actualResults = SnapshotCommand.Execute(config, _scanToolsMock.Object); Assert.AreEqual(75, actualResults.ErrorCount); Assert.AreEqual(expectedPath, actualResults.OutputFile.A11yTest); _scanToolsMock.VerifyAll(); _nativeMethodsMock.VerifyAll(); _targetElementLocatorMock.VerifyAll(); _actionsMock.VerifyAll(); _resultsAssemblerMock.VerifyAll(); _outputFileHelperMock.VerifyAll(); }
private void RefreshSnapshotStatus(bool canSnapshot) { _canSnapshot = canSnapshot; SnapshotCommand.RaiseCanExecuteChanged(); }
/// <summary> /// This entry point does not ship, but it makes for a quick and easy way to debug through the /// automation code. One caveat--we intentionally don't build symbols for this app, so while you /// can use it to to debug the automation code, breakpoints set in this class will be ignored. /// </summary> static void Main(string[] args) { Dictionary <string, string> parameters = new Dictionary <string, string>(); string secondaryConfigFile = string.Empty; char[] delimiters = { '=' }; foreach (string arg in args) { string[] pieces = arg.Split(delimiters); if (pieces.Length == 2) { string key = pieces[0].Trim(); string value = pieces[1].Trim(); if (!string.IsNullOrWhiteSpace(key) && !string.IsNullOrWhiteSpace(value)) { // Special case for SecondaryConfigFile if (key.Equals("SecondaryConfigFile", StringComparison.OrdinalIgnoreCase)) { secondaryConfigFile = value; } else { parameters[key] = value; } continue; } } Console.WriteLine("Ignoring malformed input: {0}", arg); } ; Console.WriteLine(StartCommand.Execute(parameters, secondaryConfigFile).ToString()); int autoFileId = 0; while (true) { Console.Write("Enter process ID to capture (blank to exit): "); string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } if (!int.TryParse(input, out int processId)) { Console.WriteLine("Not a valid int: " + input); continue; } Dictionary <string, string> snapshotParameters = new Dictionary <string, string> { { CommandConstStrings.TargetProcessId, input }, { CommandConstStrings.OutputFile, autoFileId++.ToString(CultureInfo.InvariantCulture) }, }; Console.WriteLine(SnapshotCommand.Execute(snapshotParameters).ToString()); } Console.WriteLine(StopCommand.Execute().ToString()); }