|
| 1 | +# A part of NonVisual Desktop Access (NVDA) |
| 2 | +# Copyright (C) 2021 NV Access Limited |
| 3 | +# This file may be used under the terms of the GNU General Public License, version 2 or later. |
| 4 | +# For more details see: https://www.gnu.org/licenses/gpl-2.0.html |
| 5 | + |
| 6 | +"""Logic for testing NVDA interacting with the Windows system. |
| 7 | +""" |
| 8 | +import re as _re |
| 9 | + |
| 10 | +# relative import not used for 'systemTestUtils' because the folder is added to the path for 'libraries' |
| 11 | +# imported methods start with underscore (_) so they don't get imported into robot files as keywords |
| 12 | +from SystemTestSpy import ( |
| 13 | + _blockUntilConditionMet, |
| 14 | + _getLib, |
| 15 | +) |
| 16 | + |
| 17 | +# Imported for type information |
| 18 | +import NvdaLib as _nvdaLib |
| 19 | +from NotepadLib import NotepadLib as _NotepadLib |
| 20 | + |
| 21 | +_notepad: _NotepadLib = _getLib("NotepadLib") |
| 22 | + |
| 23 | +EMOJI_PANNEL_PATTERNS = [ |
| 24 | + _re.compile(r"level [0-9]+ ([A-z ]+) 1 of [0-9]+"), |
| 25 | + _re.compile(r"([A-z ]+) 1 of [0-9]+ level [0-9]+") |
| 26 | +] |
| 27 | + |
| 28 | + |
| 29 | +def _open_clipboard_history() -> str: |
| 30 | + return _nvdaLib.getSpeechAfterKey("leftWindows+v") |
| 31 | + |
| 32 | + |
| 33 | +def open_clipboard_history() -> str: |
| 34 | + """ |
| 35 | + Returns the last read item after opening the clipboard history. |
| 36 | + """ |
| 37 | + success, lastHistoryItem = _blockUntilConditionMet( |
| 38 | + getValue=_open_clipboard_history, |
| 39 | + giveUpAfterSeconds=2, |
| 40 | + intervalBetweenSeconds=0.2 |
| 41 | + ) |
| 42 | + if success: |
| 43 | + return lastHistoryItem |
| 44 | + raise AssertionError(f"Clipboard history not announced.") |
| 45 | + |
| 46 | + |
| 47 | +def copy_text(): |
| 48 | + """ |
| 49 | + Expects an editable field to be focused. |
| 50 | + """ |
| 51 | + spy = _nvdaLib.getSpyLib() |
| 52 | + spy.emulateKeyPress("control+a") |
| 53 | + spy.emulateKeyPress("control+c") |
| 54 | + |
| 55 | + |
| 56 | +def read_clipboard_history(*expectedClipboardHistory: str): |
| 57 | + """ |
| 58 | + Expects the clipboard panel to already be open and focused on an editable field. |
| 59 | + """ |
| 60 | + spy = _nvdaLib.getSpyLib() |
| 61 | + spy.wait_for_speech_to_finish() |
| 62 | + for copyText in expectedClipboardHistory: |
| 63 | + spy.wait_for_specific_speech(copyText) |
| 64 | + spy.emulateKeyPress('rightArrow') |
| 65 | + |
| 66 | + |
| 67 | +def open_emoji_panel() -> str: |
| 68 | + """ |
| 69 | + Returns the first read emoji after opening the emoji panel. |
| 70 | + """ |
| 71 | + lastSpeech = _nvdaLib.getSpeechAfterKey("leftWindows+.") |
| 72 | + for pattern in EMOJI_PANNEL_PATTERNS: |
| 73 | + emojiMatch = _re.match(pattern, lastSpeech) |
| 74 | + if emojiMatch is not None: |
| 75 | + return emojiMatch.group(1) |
| 76 | + raise AssertionError(f"Emoji not announced. Last speech: '{lastSpeech}'") |
| 77 | + |
| 78 | + |
| 79 | +def search_emojis(emojiNameSearchStr: str): |
| 80 | + """ |
| 81 | + Types a string search with the emoji panel open. |
| 82 | + Expects the emoji panel to already be open and focused on an editable field. |
| 83 | + """ |
| 84 | + spy = _nvdaLib.getSpyLib() |
| 85 | + for c in emojiNameSearchStr: |
| 86 | + spy.emulateKeyPress(c, blockUntilProcessed=False) |
| 87 | + spy.wait_for_speech_to_finish() |
| 88 | + |
| 89 | + |
| 90 | +def read_emojis(*expectedEmojiNameList: str): |
| 91 | + """ |
| 92 | + Navigates the emoji panel and confirms the expected emoji list. |
| 93 | + Expects the emoji panel to already be open. |
| 94 | + """ |
| 95 | + spy = _nvdaLib.getSpyLib() |
| 96 | + for emojiName in expectedEmojiNameList: |
| 97 | + spy.wait_for_specific_speech(emojiName) |
| 98 | + spy.emulateKeyPress('rightArrow') |
0 commit comments