|
| 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 | +from robot.libraries.BuiltIn import BuiltIn |
| 9 | +# relative import not used for 'systemTestUtils' because the folder is added to the path for 'libraries' |
| 10 | +# imported methods start with underscore (_) so they don't get imported into robot files as keywords |
| 11 | +from SystemTestSpy import ( |
| 12 | + _getLib, |
| 13 | +) |
| 14 | + |
| 15 | +# Imported for type information |
| 16 | +from robot.libraries.Process import Process as _ProcessLib |
| 17 | +from AssertsLib import AssertsLib as _AssertsLib |
| 18 | +import NvdaLib as _nvdaLib |
| 19 | +from NvdaLib import NvdaLib as _nvdaRobotLib |
| 20 | +_nvdaProcessAlias = _nvdaRobotLib.nvdaProcessAlias |
| 21 | + |
| 22 | +builtIn: BuiltIn = BuiltIn() |
| 23 | +_process: _ProcessLib = _getLib("Process") |
| 24 | +_asserts: _AssertsLib = _getLib("AssertsLib") |
| 25 | + |
| 26 | + |
| 27 | +def open_clipboard_history() -> str: |
| 28 | + """ |
| 29 | + Returns the last read item after opening the clipboard history. |
| 30 | + """ |
| 31 | + spy = _nvdaLib.getSpyLib() |
| 32 | + spy.emulateKeyPress("leftWindows+v") |
| 33 | + spy.wait_for_speech_to_finish() |
| 34 | + return spy.get_last_speech() |
| 35 | + |
| 36 | + |
| 37 | +def write_and_copy_text(text: str): |
| 38 | + """ |
| 39 | + Expects an editable field to be focused. |
| 40 | + """ |
| 41 | + spy = _nvdaLib.getSpyLib() |
| 42 | + spy.emulateKeyPress("control+a") |
| 43 | + spy.emulateKeyPress("backspace") |
| 44 | + for c in text: |
| 45 | + spy.emulateKeyPress(c) |
| 46 | + spy.wait_for_speech_to_finish() |
| 47 | + spy.emulateKeyPress("control+a") |
| 48 | + spy.emulateKeyPress("control+x") |
| 49 | + spy.reset_all_speech_index() |
| 50 | + |
| 51 | + |
| 52 | +def read_clipboard_history(*expectedClipboardHistory: str): |
| 53 | + """ |
| 54 | + Expects the clipboard panel to already be open and focused on an editable field. |
| 55 | + """ |
| 56 | + spy = _nvdaLib.getSpyLib() |
| 57 | + spy.wait_for_speech_to_finish() |
| 58 | + for copyText in expectedClipboardHistory: |
| 59 | + spy.wait_for_specific_speech(copyText) |
| 60 | + spy.emulateKeyPress('rightArrow') |
| 61 | + |
| 62 | + |
| 63 | +def open_emoji_panel() -> str: |
| 64 | + """ |
| 65 | + Returns the first read emoji after opening the emoji panel. |
| 66 | + """ |
| 67 | + spy = _nvdaLib.getSpyLib() |
| 68 | + spy.emulateKeyPress("leftWindows+.") |
| 69 | + spy.wait_for_speech_to_finish() |
| 70 | + lastSpeech = spy.get_last_speech() |
| 71 | + try: |
| 72 | + return lastSpeech.split(" ")[1] |
| 73 | + except IndexError: |
| 74 | + raise AssertionError(f"Emoji not announced. Last speech: '{lastSpeech}'") |
| 75 | + |
| 76 | + |
| 77 | +def search_emojis(emojiNameSearchStr: str): |
| 78 | + """ |
| 79 | + Types a string search with the emoji panel open. |
| 80 | + Expects the emoji panel to already be open and focused on an editable field. |
| 81 | + """ |
| 82 | + spy = _nvdaLib.getSpyLib() |
| 83 | + for c in emojiNameSearchStr: |
| 84 | + spy.emulateKeyPress(c, blockUntilProcessed=False) |
| 85 | + spy.wait_for_speech_to_finish() |
| 86 | + |
| 87 | + |
| 88 | +def read_emojis(*expectedEmojiNameList: str): |
| 89 | + """ |
| 90 | + Navigates the emoji panel and confirms the expected emoji list. |
| 91 | + Expects the emoji panel to already be open. |
| 92 | + """ |
| 93 | + spy = _nvdaLib.getSpyLib() |
| 94 | + for emojiName in expectedEmojiNameList: |
| 95 | + spy.wait_for_specific_speech(emojiName) |
| 96 | + spy.emulateKeyPress('rightArrow') |
0 commit comments