private AutomationElement GetWindowUiaElement(CmdApp app) { IntPtr handle = app.GetWindowHandle(); AutomationElement windowUiaElement = AutomationElement.FromHandle(handle); return(windowUiaElement); }
private static void BufferVerificationHelper(CmdApp app, ViewportArea area, IntPtr hConsole, GetExpectedChar expectedCharAlgorithm) { WinCon.SMALL_RECT viewport = app.GetViewport(hConsole); Rectangle selectRect = new Rectangle(viewport.Left, viewport.Top, viewport.Width, viewport.Height); IEnumerable <string> scrapedText = area.GetLinesInRectangle(hConsole, selectRect); Verify.AreEqual(viewport.Height, scrapedText.Count(), "Verify the rows scraped is equal to the entire viewport height."); bool isValidState = true; string[] rows = scrapedText.ToArray(); for (int i = 0; i < rows.Length; i++) { for (int j = 0; j < viewport.Width; j++) { char actual = rows[i][j]; char expected = expectedCharAlgorithm(i, j, rows.Length, viewport.Width); isValidState = actual == expected; if (!isValidState) { Verify.Fail(string.Format("Text buffer verification failed at Row: {0} Col: {1} Expected: '{2}' Actual: '{3}'", i, j, expected, actual)); break; } } if (!isValidState) { break; } } }
void RunTest(AccessibilityTest test) { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (WinEventSystem sys = app.AttachWinEventSystem(this)) { using (ViewportArea area = new ViewportArea(app)) { Globals.WaitForTimeout(); // wait for everything to settle with winevents IntPtr hConsole = app.GetStdOutHandle(); // Prep structures to hold cursor and size of buffer. WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiex = new WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX(); sbiex.cbSize = (uint)Marshal.SizeOf(sbiex); // this is where we will hold our expected messages Queue <EventData> expected = new Queue <EventData>(); NativeMethods.Win32BoolHelper(WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref sbiex), "Get initial console data."); WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiexOriginal = sbiex; // keep a copy of the original data for later. // Run the test test(app, area, hConsole, sbiex, expected, sbiexOriginal); } } } } }
public void CanGetDocumentRangeText() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { // get the text from uia api AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange documentRange = textPattern.DocumentRange; string allText = documentRange.GetText(-1); // get text from console api IntPtr hConsole = app.GetStdOutHandle(); using (ViewportArea area = new ViewportArea(app)) { WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX screenInfo = app.GetScreenBufferInfo(); Rectangle rect = new Rectangle(0, 0, screenInfo.dwSize.X, screenInfo.dwSize.Y); IEnumerable <string> viewportText = area.GetLinesInRectangle(hConsole, rect); // the uia api does not return spaces beyond the last // non -whitespace character so we need to trim those from // the viewportText. The uia api also inserts \r\n to indicate // a new linen so we need to add those back in after trimming. string consoleText = ""; for (int i = 0; i < viewportText.Count(); ++i) { consoleText += viewportText.ElementAt(i).Trim() + "\r\n"; } consoleText = consoleText.Trim(); allText = allText.Trim(); // compare Verify.IsTrue(consoleText.Equals(allText)); } } }
public void VerifyCtrlZCmd() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (ViewportArea area = new ViewportArea(app)) { IntPtr hConsole = app.GetStdOutHandle(); Verify.IsNotNull(hConsole, "Ensure the handle is valid."); // get cursor location WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX screenBufferInfo = new WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX(); WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref screenBufferInfo); // send ^Z app.UIRoot.SendKeys(Keys.Control + "z" + Keys.Control); Globals.WaitForTimeout(); // test that "^Z" exists on the screen Rectangle rect = new Rectangle(0, 0, 200, 20); IEnumerable <string> text = area.GetLinesInRectangle(hConsole, rect); bool foundCtrlZ = false; foreach (string line in text) { if (line.Contains("^Z")) { foundCtrlZ = true; break; } } Verify.IsTrue(foundCtrlZ); } } } }
private BrowseCommand(CmdApp cmd, string path, bool select = false) : base(true) { _cmdApp = cmd; _path = path; _selectInExplorer = select; }
public void CanGetVisibleRange() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { // get the ranges from uia api AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] ranges = textPattern.GetVisibleRanges(); // get the ranges from the console api WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX screenInfo = app.GetScreenBufferInfo(); int viewportHeight = screenInfo.srWindow.Bottom - screenInfo.srWindow.Top + 1; // we should have one range per line in the viewport Verify.AreEqual(ranges.GetLength(0), viewportHeight); // each line should have the same text ViewportArea viewport = new ViewportArea(app); IntPtr hConsole = app.GetStdOutHandle(); for (int i = 0; i < viewportHeight; ++i) { Rectangle rect = new Rectangle(0, i, screenInfo.dwSize.X, 1); IEnumerable <string> text = viewport.GetLinesInRectangle(hConsole, rect); Verify.AreEqual(text.ElementAt(0).Trim(), ranges[i].GetText(-1).Trim()); } } }
public void VerifyCtrlHCmd() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (ViewportArea area = new ViewportArea(app)) { string testText = "1234blah5678"; IntPtr hConsole = app.GetStdOutHandle(); Verify.IsNotNull(hConsole, "Ensure the handle is valid."); // get cursor location WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX screenBufferInfo = new WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX(); WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref screenBufferInfo); // send some text and a ^H to remove the last character app.UIRoot.SendKeys(testText + Keys.Control + "h" + Keys.Control); Globals.WaitForTimeout(); // test that we're missing the last character of testText on the line Rectangle rect = new Rectangle(0, 0, 200, 20); IEnumerable <string> text = area.GetLinesInRectangle(hConsole, rect); bool foundCtrlH = false; foreach (string line in text) { if (line.Contains(testText.Substring(0, testText.Length - 1)) && !line.Contains(testText)) { foundCtrlH = true; break; } } Verify.IsTrue(foundCtrlH); } } } }
private void TestScrollByWheelImpl(CmdApp app, ViewportArea area, IntPtr hConsole, WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiex, Queue <EventData> expected, WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiexOriginal) { int rowsPerScroll = app.GetRowsPerScroll(); int scrollDelta; // A. Scroll down. { scrollDelta = -1; expected.Enqueue(new EventData(EventType.UpdateScroll, 0, scrollDelta * rowsPerScroll)); expected.Enqueue(new EventData(EventType.Layout)); app.ScrollWindow(scrollDelta); Globals.WaitForTimeout(); VerifyQueue(expected); } // B. Scroll up. { scrollDelta = 1; expected.Enqueue(new EventData(EventType.UpdateScroll, 0, scrollDelta * rowsPerScroll)); expected.Enqueue(new EventData(EventType.Layout)); app.ScrollWindow(scrollDelta); Globals.WaitForTimeout(); VerifyQueue(expected); } }
public void CanExpandToEnclosingUnitTextRangeProvider() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] visibleRanges = textPattern.GetVisibleRanges(); TextPatternRange testRange = visibleRanges.First().Clone(); // change testRange to a degenerate range and then expand to a line testRange.MoveEndpointByRange(TextPatternRangeEndpoint.End, testRange, TextPatternRangeEndpoint.Start); Verify.AreEqual(0, testRange.CompareEndpoints(TextPatternRangeEndpoint.Start, testRange, TextPatternRangeEndpoint.End)); testRange.ExpandToEnclosingUnit(TextUnit.Line); Verify.IsTrue(testRange.Compare(visibleRanges[0])); // expand to document size testRange.ExpandToEnclosingUnit(TextUnit.Document); Verify.IsTrue(testRange.Compare(textPattern.DocumentRange)); // shrink back to a line testRange.ExpandToEnclosingUnit(TextUnit.Line); Verify.IsTrue(testRange.Compare(visibleRanges[0])); // make the text buffer start to cycle its buffer _FillOutputBufferWithData(app); // expand to document range again testRange.ExpandToEnclosingUnit(TextUnit.Document); Verify.IsTrue(testRange.Compare(textPattern.DocumentRange)); } }
private static void TestInsertDelete(CmdApp app, ViewportArea area, IntPtr hConsole) { Log.Comment("--Insert/Delete Commands"); ScreenFillHelper(app, area, hConsole); Log.Comment("Move cursor to the middle-ish"); Point cursorExpected = new Point(); // H is at 5, 1. VT coords are 1-based and buffer is 0-based so adjust. cursorExpected.Y = 5 - 1; cursorExpected.X = 1 - 1; app.UIRoot.SendKeys("H"); // Move to middle-ish from here. 10 Bs and 10 Cs should about do it. for (int i = 0; i < 10; i++) { app.UIRoot.SendKeys("BC"); cursorExpected.Y++; cursorExpected.X++; } WinCon.SMALL_RECT viewport = app.GetViewport(hConsole); // The entire buffer should be Zs except for what we're about to insert and delete. app.UIRoot.SendKeys("O"); // insert WinCon.CHAR_INFO ciCursor = area.GetCharInfoAt(hConsole, cursorExpected); Verify.AreEqual(' ', ciCursor.UnicodeChar); Point endOfCursorLine = new Point(viewport.Right, cursorExpected.Y); app.UIRoot.SendKeys("P"); // delete WinCon.CHAR_INFO ciEndOfLine = area.GetCharInfoAt(hConsole, endOfCursorLine); Verify.AreEqual(' ', ciEndOfLine.UnicodeChar); ciCursor = area.GetCharInfoAt(hConsole, cursorExpected); Verify.AreEqual('Z', ciCursor.UnicodeChar); // Move to end of line and check both insert and delete operations while (cursorExpected.X < viewport.Right) { app.UIRoot.SendKeys("C"); cursorExpected.X++; } // move up a line to get some fresh Z app.UIRoot.SendKeys("A"); cursorExpected.Y--; app.UIRoot.SendKeys("O"); // insert at end of line ciCursor = area.GetCharInfoAt(hConsole, cursorExpected); Verify.AreEqual(' ', ciCursor.UnicodeChar); // move up a line to get some fresh Z app.UIRoot.SendKeys("A"); cursorExpected.Y--; app.UIRoot.SendKeys("P"); // delete at end of line ciCursor = area.GetCharInfoAt(hConsole, cursorExpected); Verify.AreEqual(' ', ciCursor.UnicodeChar); }
public void CanMoveEndpointByUnitNearTopBoundary() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] visibleRanges = textPattern.GetVisibleRanges(); TextPatternRange testRange = visibleRanges.First().Clone(); // assumes that range is a line range at the top of the screen buffer Action <TextPatternRange> testTopBoundary = delegate(TextPatternRange range) { // the first visible range is at the top of the screen // buffer, we shouldn't be able to move the starting endpoint up int moveAmount = range.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, TextUnit.Line, -1); Verify.AreEqual(0, moveAmount); // we should be able to move the ending endpoint back, creating a degenerate range moveAmount = range.MoveEndpointByUnit(TextPatternRangeEndpoint.End, TextUnit.Line, -1); Verify.AreEqual(-1, moveAmount); // the range should now be degenerate and the ending // endpoint should not be able to be moved back again string rangeText = range.GetText(-1); Verify.AreEqual("", rangeText); moveAmount = range.MoveEndpointByUnit(TextPatternRangeEndpoint.End, TextUnit.Line, -1); Verify.AreEqual(-1, moveAmount); }; testTopBoundary(testRange); // we want to test that the boundaries are still observed // when the screen buffer index and text buffer index don't align. // write a bunch of text to the screen to fill up the text // buffer and make it start to reuse its buffer _FillOutputBufferWithData(app); Globals.WaitForTimeout(); // move all the way to the bottom visibleRanges = textPattern.GetVisibleRanges(); testRange = visibleRanges.Last().Clone(); while (true) { int moved = testRange.Move(TextUnit.Line, 1); if (moved == 0) { break; } } // we're at the bottom of the screen buffer, so move back to the top // so we can test int rowsToMove = -1 * (_GetTotalRows(app) - 1); int moveCount = testRange.Move(TextUnit.Line, rowsToMove); Verify.AreEqual(rowsToMove, moveCount); testRange.ScrollIntoView(true); testTopBoundary(testRange); } }
public void CanAccessTextAreaUiaElement() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); Verify.IsTrue(textAreaUiaElement != null); } }
public void CanAccessAccessibilityTree() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement windowUiaElement = GetWindowUiaElement(app); Verify.IsTrue(windowUiaElement.Current.AutomationId.Equals("Console Window")); } }
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable public void CheckExperimentalDisableState() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); // manipulating the global v1/v2 state can affect the registry so back it up. using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (PropertiesDialog properties = new PropertiesDialog(app)) { properties.Open(OpenTarget.Defaults); using (Tabs tabs = new Tabs(properties)) { // check everything stays enabled when global is on. AutoHelpers.LogInvariant("Check that items are all enabled when global is enabled."); tabs.SetGlobalState(Tabs.GlobalState.ConsoleV2); // iterate through each tab AutoHelpers.LogInvariant("Checking elements on all tabs."); foreach (TabBase tab in tabs.AllTabs) { tab.NavigateToTab(); IEnumerable <AppiumWebElement> itemsUnaffected = tab.GetObjectsUnaffectedByV1V2Switch(); IEnumerable <AppiumWebElement> itemsThatDisable = tab.GetObjectsDisabledForV1Console(); foreach (AppiumWebElement obj in itemsThatDisable.Concat(itemsUnaffected)) { Verify.IsTrue(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text)); } } // check that relevant boxes are disabled when global is off. AutoHelpers.LogInvariant("Check that necessary items are disabled when global is disabled."); tabs.SetGlobalState(Tabs.GlobalState.ConsoleV1); foreach (TabBase tab in tabs.AllTabs) { tab.NavigateToTab(); IEnumerable <AppiumWebElement> itemsUnaffected = tab.GetObjectsUnaffectedByV1V2Switch(); IEnumerable <AppiumWebElement> itemsThatDisable = tab.GetObjectsDisabledForV1Console(); foreach (AppiumWebElement obj in itemsThatDisable) { Verify.IsFalse(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text)); } foreach (AppiumWebElement obj in itemsUnaffected) { Verify.IsTrue(obj.Enabled, AutoHelpers.FormatInvariant("Option: {0}", obj.Text)); } } } } } } }
public void RunVtAppTester() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); // we're going to modify the virtual terminal state for this, so back it up first. VersionSelector.SetConsoleVersion(reg, ConsoleVersion.V2); reg.SetDefaultValue(VIRTUAL_TERMINAL_KEY_NAME, VIRTUAL_TERMINAL_ON_VALUE); bool haveVtAppPath = !string.IsNullOrEmpty(vtAppLocation); Verify.IsTrue(haveVtAppPath, "Ensure that we passed in the location to VtApp.exe"); if (haveVtAppPath) { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext, vtAppLocation)) { using (ViewportArea area = new ViewportArea(app)) { // Get console handle. IntPtr hConsole = app.GetStdOutHandle(); Verify.IsNotNull(hConsole, "Ensure the STDOUT handle is valid."); Log.Comment("Check that the VT test app loaded up properly with its output line and the cursor down one line."); Rectangle selectRect = new Rectangle(0, 0, 9, 1); IEnumerable <string> scrapedText = area.GetLinesInRectangle(hConsole, selectRect); Verify.AreEqual(scrapedText.Count(), 1, "We should have retrieved one line."); string testerWelcome = scrapedText.Single(); Verify.AreEqual(testerWelcome, "VT Tester"); WinCon.COORD cursorPos = app.GetCursorPosition(hConsole); WinCon.COORD cursorExpected = new WinCon.COORD(); cursorExpected.X = 0; cursorExpected.Y = 1; Verify.AreEqual(cursorExpected, cursorPos, "Check cursor has moved to expected starting position."); TestCursorPositioningCommands(app, hConsole, cursorExpected); TestCursorVisibilityCommands(app, hConsole); TestAreaEraseCommands(app, area, hConsole); TestGraphicsCommands(app, area, hConsole); TestQueryResponses(app, hConsole); TestVtToggle(app, hConsole); TestInsertDelete(app, area, hConsole); } } } } }
private void TestLaunchAndExitChildImpl(CmdApp app, ViewportArea area, IntPtr hConsole, WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiex, Queue <EventData> expected, WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX sbiexOriginal) { // A. We're going to type "cmd" into the prompt to start a command prompt. { Log.Comment("Type 'cmd' to get ready to start nested prompt."); NativeMethods.Win32BoolHelper(WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref sbiex), "Update console data."); TestTypeStringHelper("cmd", app, sbiex); } // B. Now we're going to press enter to launch the CMD application { Log.Comment("Press enter to launch and observe launch events."); NativeMethods.Win32BoolHelper(WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref sbiex), "Update console data."); expected.Enqueue(new EventData(EventType.StartApplication)); expected.Enqueue(new EventData(EventType.UpdateRegion, 0, 0, sbiex.dwSize.X - 1, sbiex.dwSize.Y - 1)); sbiex.dwCursorPosition.Y++; expected.Enqueue(new EventData(EventType.UpdateRegion, 0, sbiex.dwCursorPosition.Y, "Microsoft Windows [Version 10.0.14974.1001]".Length - 1, sbiex.dwCursorPosition.Y)); sbiex.dwCursorPosition.Y++; expected.Enqueue(new EventData(EventType.UpdateRegion, 0, sbiex.dwCursorPosition.Y, "(c) 2016 Microsoft Corporation. All rights reserved.".Length - 1, sbiex.dwCursorPosition.Y)); sbiex.dwCursorPosition.Y++; sbiex.dwCursorPosition.Y++; expected.Enqueue(new EventData(EventType.UpdateRegion, 0, sbiex.dwCursorPosition.Y, sbiexOriginal.dwCursorPosition.X - 1, sbiex.dwCursorPosition.Y)); expected.Enqueue(new EventData(EventType.CaretVisible, sbiexOriginal.dwCursorPosition.X, sbiex.dwCursorPosition.Y)); app.UIRoot.SendKeys(Keys.Enter); Globals.WaitForTimeout(); Globals.WaitForTimeout(); VerifyQueue(expected); } // C. Now we're going to type exit to leave the nested CMD application { Log.Comment("Type 'exit' to get ready to exit nested prompt."); NativeMethods.Win32BoolHelper(WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref sbiex), "Update console data."); TestTypeStringHelper("exit", app, sbiex); } // D. Now we're going to press enter to exit the CMD application { Log.Comment("Press enter to launch and observe exit events."); NativeMethods.Win32BoolHelper(WinCon.GetConsoleScreenBufferInfoEx(hConsole, ref sbiex), "Update console data."); expected.Enqueue(new EventData(EventType.EndApplication)); sbiex.dwCursorPosition.Y++; sbiex.dwCursorPosition.Y++; expected.Enqueue(new EventData(EventType.UpdateRegion, 0, sbiex.dwCursorPosition.Y, sbiexOriginal.dwCursorPosition.X - 1, sbiex.dwCursorPosition.Y)); expected.Enqueue(new EventData(EventType.CaretVisible, sbiexOriginal.dwCursorPosition.X, sbiex.dwCursorPosition.Y)); app.UIRoot.SendKeys(Keys.Enter); Globals.WaitForTimeout(); Globals.WaitForTimeout(); VerifyQueue(expected); } }
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable public void CheckRegistryWritebacks() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { this.CheckRegistryWritebacks(reg, app, OpenTarget.Defaults); this.CheckRegistryWritebacks(reg, app, OpenTarget.Specifics); } } }
private void _FillOutputBufferWithData(CmdApp app) { for (int i = 0; i < _GetTotalRows(app) * 2 / 3; ++i) { // each echo command uses up 3 lines in the buffer: // 1. output text // 2. newline // 3. new prompt line app.UIRoot.SendKeys("echo "); app.UIRoot.SendKeys(i.ToString()); app.UIRoot.SendKeys(Keys.Enter); } }
public void CanCloneTextRangeProvider() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange textPatternRange = textPattern.DocumentRange; // clone it TextPatternRange copyRange = textPatternRange.Clone(); Verify.IsTrue(copyRange.Compare(textPatternRange)); // change the copy and make sure the compare fails copyRange.MoveEndpointByRange(TextPatternRangeEndpoint.End, copyRange, TextPatternRangeEndpoint.Start); Verify.IsFalse(copyRange.Compare(textPatternRange)); } }
private AutomationElement GetTextAreaUiaElement(CmdApp app) { AutomationElement windowUiaElement = GetWindowUiaElement(app); AutomationElementCollection descendants = windowUiaElement.FindAll(TreeScope.Descendants, Condition.TrueCondition); for (int i = 0; i < descendants.Count; ++i) { AutomationElement poss = descendants[i]; if (poss.Current.AutomationId.Equals("Text Area")) { return(poss); } } throw new InvalidElementException(); }
private static void TestVtToggle(CmdApp app, IntPtr hConsole) { WinCon.COORD cursorPos; Log.Comment("--Test VT Toggle--"); Verify.IsTrue(app.IsVirtualTerminalEnabled(hConsole), "Verify we're starting with VT on."); app.UIRoot.SendKeys("H-"); // move cursor to top left area H location and then turn off VT. cursorPos = app.GetCursorPosition(hConsole); Verify.IsFalse(app.IsVirtualTerminalEnabled(hConsole), "Verify VT was turned off."); app.UIRoot.SendKeys("-"); Verify.IsTrue(app.IsVirtualTerminalEnabled(hConsole), "Verify VT was turned back on ."); }
public void TestMouseWheel() { // Use a registry helper to backup and restore registry state before/after test using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); // Start our application to test using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { Log.Comment("First ensure that word wrap is off so we can get scroll bars in both directions."); // Make sure wrap is off app.SetWrapState(false); IntPtr handle = app.GetStdOutHandle(); Verify.IsNotNull(handle, "Ensure we have the output handle."); Log.Comment("Set up the window so the buffer is larger than the window. Retrieve existing properties then set the viewport to smaller than the buffer."); WinCon.CONSOLE_SCREEN_BUFFER_INFO_EX info = app.GetScreenBufferInfo(handle); info.srWindow.Left = 0; info.srWindow.Right = 30; info.srWindow.Top = 0; info.srWindow.Bottom = 30; info.dwSize.X = 100; info.dwSize.Y = 100; app.SetScreenBufferInfo(handle, info); Log.Comment("Now retrieve the starting position of the window viewport."); Log.Comment("Scroll down one."); VerifyScroll(app, ScrollDir.Vertical, -1); Log.Comment("Scroll right one."); VerifyScroll(app, ScrollDir.Horizontal, 1); Log.Comment("Scroll left one."); VerifyScroll(app, ScrollDir.Horizontal, -1); Log.Comment("Scroll up one."); VerifyScroll(app, ScrollDir.Vertical, 1); } } }
private static void TestCursorVisibilityCommands(CmdApp app, IntPtr hConsole) { WinCon.COORD cursorExpected; Log.Comment("---Cursor Visibility Commands---"); Log.Comment("Turn cursor display off. (l)"); app.UIRoot.SendKeys("l"); Verify.AreEqual(false, app.IsCursorVisible(hConsole), "Check that cursor is invisible."); Log.Comment("Turn cursor display on. (h)"); app.UIRoot.SendKeys("h"); Verify.AreEqual(true, app.IsCursorVisible(hConsole), "Check that cursor is visible."); Log.Comment("---Cursor Save/Restore Commands---"); Log.Comment("Save current cursor position with DEC save."); app.UIRoot.SendKeys("7"); cursorExpected = app.GetCursorPosition(hConsole); Log.Comment("Move the cursor a bit away from the saved position."); app.UIRoot.SendKeys("BBBBCCCCC"); Log.Comment("Restore existing position with DEC restore."); app.UIRoot.SendKeys("8"); Verify.AreEqual(cursorExpected, app.GetCursorPosition(hConsole), "Check that cursor restored back to the saved position."); Log.Comment("Move the cursor a bit away from the saved position."); app.UIRoot.SendKeys("BBBBCCCCC"); Log.Comment("Restore existing position with ANSISYS restore."); app.UIRoot.SendKeys("u"); Verify.AreEqual(cursorExpected, app.GetCursorPosition(hConsole), "Check that cursor restored back to the saved position."); Log.Comment("Move the cursor a bit away from either position."); app.UIRoot.SendKeys("BBB"); Log.Comment("Save current cursor position with ANSISYS save."); app.UIRoot.SendKeys("y"); cursorExpected = app.GetCursorPosition(hConsole); Log.Comment("Move the cursor a bit away from the saved position."); app.UIRoot.SendKeys("CCCBB"); Log.Comment("Restore existing position with DEC restore."); app.UIRoot.SendKeys("8"); Verify.AreEqual(cursorExpected, app.GetCursorPosition(hConsole), "Check that cursor restored back to the saved position."); }
public void VerifyCtrlCCmd() { using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (ViewportArea area = new ViewportArea(app)) { IntPtr hConsole = app.GetStdOutHandle(); Verify.IsNotNull(hConsole, "Ensure the handle is valid."); Globals.WaitForTimeout(); // send ctrl-c sequence const int keypressCount = 10; for (int i = 0; i < keypressCount; ++i) { app.UIRoot.SendKeys(Keys.Control + "c" + Keys.Control); } Globals.WaitForTimeout(); // fetch the text Rectangle rect = new Rectangle(0, 0, 50, 50); IEnumerable <string> text = area.GetLinesInRectangle(hConsole, rect); // filter out the blank lines List <string> possiblePromptLines = new List <string>(); for (int i = 0; i < text.Count(); ++i) { string line = text.ElementAt(i); line.Trim(' '); if (!line.Equals("")) { possiblePromptLines.Add(line); } } // make sure that the prompt line shows up for each ^C key press Verify.IsTrue(possiblePromptLines.Count() >= keypressCount); possiblePromptLines.Reverse(); for (int i = 0; i < keypressCount; ++i) { Verify.AreEqual(possiblePromptLines[0], possiblePromptLines[1]); possiblePromptLines.RemoveAt(0); } } } } }
[TestProperty("Ignore", "True")] // GH#7282 - investigate and reenable public void CheckShortcutWritebacks() { using (RegistryHelper reg = new RegistryHelper()) { // The global state changes can still impact the registry, so back up the registry anyway despite this being the shortcut test. reg.BackupRegistry(); using (ShortcutHelper shortcut = new ShortcutHelper()) { shortcut.CreateTempCmdShortcut(); using (CmdApp app = new CmdApp(CreateType.ShortcutFile, TestContext, shortcut.ShortcutPath)) { this.CheckShortcutWritebacks(shortcut, app, OpenTarget.Specifics); } } } }
public void CanGetBoundingRectangles() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] visibleRanges = textPattern.GetVisibleRanges(); // copy the first range TextPatternRange firstRange = visibleRanges[0].Clone(); // only one bounding rect should be returned for the one line Rect[] boundingRects = firstRange.GetBoundingRectangles(); Verify.AreEqual(1, boundingRects.GetLength(0)); // expand to two lines, verify we get a bounding rect per line firstRange.MoveEndpointByRange(TextPatternRangeEndpoint.End, visibleRanges[1], TextPatternRangeEndpoint.End); boundingRects = firstRange.GetBoundingRectangles(); Verify.AreEqual(2, boundingRects.GetLength(0)); } }
public void VerifyVimInput() { if (!IsProgramInPath("vim.exe")) { Log.Comment("vim can't be found in path, skipping test."); return; } using (RegistryHelper reg = new RegistryHelper()) { reg.BackupRegistry(); using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { using (ViewportArea area = new ViewportArea(app)) { IntPtr hConsole = app.GetStdOutHandle(); string testText = "hello world"; Verify.IsNotNull(hConsole, "ensure the stdout handle is valid."); // start up vim app.UIRoot.SendKeys("vim"); app.UIRoot.SendKeys(Keys.Enter); Globals.WaitForTimeout(); app.UIRoot.SendKeys(Keys.Enter); // go to insert mode app.UIRoot.SendKeys("i"); // write some text app.UIRoot.SendKeys(testText); Globals.WaitForTimeout(); // make sure text showed up in the output Rectangle rect = new Rectangle(0, 0, 20, 20); IEnumerable <string> text = area.GetLinesInRectangle(hConsole, rect); bool foundText = false; foreach (string line in text) { if (line.Contains(testText)) { foundText = true; break; } } Verify.IsTrue(foundText); } } } }
public void CanGetTextAtCharacterLevel() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { const int noMaxLength = -1; const string row1 = "1234567890"; const string row2 = " abcdefghijk"; _ClearScreenBuffer(app); _WriteCharTestText(app); AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange[] ranges = textPattern.GetVisibleRanges(); TextPatternRange range = ranges[0].Clone(); // should be able to get each char in row1 range.ExpandToEnclosingUnit(TextUnit.Character); foreach (char ch in row1) { string text = range.GetText(noMaxLength); Verify.AreEqual(ch.ToString(), text); range.Move(TextUnit.Character, 1); } // should be able to get each char in row2, including starting spaces range = ranges[1].Clone(); range.ExpandToEnclosingUnit(TextUnit.Character); foreach (char ch in row2) { string text = range.GetText(noMaxLength); Verify.AreEqual(ch.ToString(), text); range.Move(TextUnit.Character, 1); } // taking half of each row should return correct text with // spaces if they appear before the last non-whitespace char range = ranges[0].Clone(); range.MoveEndpointByUnit(TextPatternRangeEndpoint.Start, TextUnit.Character, 8); range.MoveEndpointByUnit(TextPatternRangeEndpoint.End, TextUnit.Character, 8); Verify.AreEqual("90\r\n abcde", range.GetText(noMaxLength)); } }
public void CanCompareTextRangeProviderEndpoints() { using (CmdApp app = new CmdApp(CreateType.ProcessOnly, TestContext)) { AutomationElement textAreaUiaElement = GetTextAreaUiaElement(app); TextPattern textPattern = textAreaUiaElement.GetCurrentPattern(TextPattern.Pattern) as TextPattern; TextPatternRange textPatternRange = textPattern.DocumentRange; // comparing an endpoint to itself should be the same Verify.AreEqual(0, textPatternRange.CompareEndpoints(TextPatternRangeEndpoint.Start, textPatternRange, TextPatternRangeEndpoint.Start)); // comparing an earlier endpoint to a later one should be negative Verify.IsGreaterThan(0, textPatternRange.CompareEndpoints(TextPatternRangeEndpoint.Start, textPatternRange, TextPatternRangeEndpoint.End)); // comparing a later endpoint to an earlier one should be positive Verify.IsLessThan(0, textPatternRange.CompareEndpoints(TextPatternRangeEndpoint.End, textPatternRange, TextPatternRangeEndpoint.Start)); } }