From 677a18861bae86abae7f30fc88d57fca04bab093 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 15 Apr 2021 12:21:27 +1000 Subject: [PATCH 1/6] attempt to avoid NVDA losing focus during systests --- source/core.py | 5 +++++ .../SystemTestSpy/speechSpyGlobalPlugin.py | 20 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/source/core.py b/source/core.py index 5c6f56b8a8f..3c25c164de6 100644 --- a/source/core.py +++ b/source/core.py @@ -584,9 +584,14 @@ def run(self): log.debug("initializing updateCheck") updateCheck.initialize() log.info("NVDA initialized") + # Queue the firing of the postNVDAStartup notification. # This is queued so that it will run from within the core loop, # and initial focus has been reported. + def _postNvdaStartupLogMessage(): + log.debug("postNvdaStartup event fired") + + postNvdaStartup.register(_postNvdaStartupLogMessage) queueHandler.queueFunction(queueHandler.eventQueue, postNvdaStartup.notify) log.debug("entering wx application main loop") diff --git a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py index 365daee455c..78b5c3d7263 100644 --- a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py +++ b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py @@ -159,8 +159,9 @@ def wait_for_NVDA_startup_to_complete(self): giveUpAfterSeconds=self._minTimeout(10), errorMessage="Unable to connect to nvdaSpy", ) - if self._isNvdaStartupComplete: + with self._speechLock: self.reset_all_speech_index() + self.wait_for_speech_to_finish() def get_last_speech(self) -> str: return self._getSpeechAtIndex(-1) @@ -197,6 +198,8 @@ def wait_for_specific_speech( errorMessage=None ) if not success: + if self._popup_stole_focus(): + return self.wait_for_specific_speech(speech, afterIndex, maxWaitSeconds) self.dump_speech_to_log() raise AssertionError( "Specific speech did not occur before timeout: {}\n" @@ -204,6 +207,21 @@ def wait_for_specific_speech( ) return speechIndex + def _popup_stole_focus(self): + KNOWN_POPUPS = [ + { + "speech": "Your feedback is important to us", + "process_name": "Docker Desktop.exe" + }, + ] + for popup in KNOWN_POPUPS: + if self.get_last_speech() == popup["speech"]: + log.debug(f"{popup['process_name']} stole focus, killing the process") + os.system(f'taskkill /im "{popup["process_name"]}"') + return True + return False + + def wait_for_speech_to_finish( self, maxWaitSeconds=5.0, From 27cff53edcac6f81086896ceb27d5f7a86ff2c71 Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 15 Apr 2021 12:26:45 +1000 Subject: [PATCH 2/6] fix lint --- tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py index 78b5c3d7263..dd60e13ef19 100644 --- a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py +++ b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py @@ -221,7 +221,6 @@ def _popup_stole_focus(self): return True return False - def wait_for_speech_to_finish( self, maxWaitSeconds=5.0, From a231d62f89ed45e1cd1a333b704c8ee902e918af Mon Sep 17 00:00:00 2001 From: buddsean Date: Thu, 15 Apr 2021 16:22:50 +1000 Subject: [PATCH 3/6] only call get last speech once --- tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py index dd60e13ef19..6621f2c7ef4 100644 --- a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py +++ b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py @@ -214,8 +214,9 @@ def _popup_stole_focus(self): "process_name": "Docker Desktop.exe" }, ] + last_speech = self.get_last_speech() for popup in KNOWN_POPUPS: - if self.get_last_speech() == popup["speech"]: + if last_speech == popup["speech"]: log.debug(f"{popup['process_name']} stole focus, killing the process") os.system(f'taskkill /im "{popup["process_name"]}"') return True From 9f4a8ac6accf507f2b6521e3f11226d000343817 Mon Sep 17 00:00:00 2001 From: Sean Budd Date: Tue, 20 Apr 2021 11:51:32 +1000 Subject: [PATCH 4/6] log before firing postNvdaStartup notify event Co-authored-by: Reef Turner --- source/core.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/core.py b/source/core.py index 3c25c164de6..f8233540ee0 100644 --- a/source/core.py +++ b/source/core.py @@ -588,11 +588,12 @@ def run(self): # Queue the firing of the postNVDAStartup notification. # This is queued so that it will run from within the core loop, # and initial focus has been reported. - def _postNvdaStartupLogMessage(): - log.debug("postNvdaStartup event fired") + def _doPostNvdaStartupAction(): + log.debug("Notify of postNvdaStartup action") + postNvdaStartup.notify() + + queueHandler.queueFunction(queueHandler.eventQueue, _doPostNvdaStartupAction) - postNvdaStartup.register(_postNvdaStartupLogMessage) - queueHandler.queueFunction(queueHandler.eventQueue, postNvdaStartup.notify) log.debug("entering wx application main loop") app.MainLoop() From 9c7d9c2912d092e4b7e335e6c6a4c0d2d79ca7c7 Mon Sep 17 00:00:00 2001 From: buddsean Date: Wed, 21 Apr 2021 09:57:26 +1000 Subject: [PATCH 5/6] add 2s sleep to system tests --- tests/system/robot/chromeTests.robot | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/system/robot/chromeTests.robot b/tests/system/robot/chromeTests.robot index bcf5b91d000..01c33755681 100644 --- a/tests/system/robot/chromeTests.robot +++ b/tests/system/robot/chromeTests.robot @@ -12,7 +12,7 @@ Library NvdaLib.py Library chromeTests.py Library ScreenCapLibrary -Test Setup start NVDA standard-dontShowWelcomeDialog.ini +Test Setup default setup Test Teardown default teardown *** Keywords *** @@ -22,6 +22,10 @@ default teardown exit chrome quit NVDA +default setup + start NVDA standard-dontShowWelcomeDialog.ini + Sleep 2s + *** Test Cases *** checkbox labelled by inner element From f19e4817351780f8a9104f7cf34adee2eb0592d9 Mon Sep 17 00:00:00 2001 From: buddsean Date: Wed, 21 Apr 2021 10:25:52 +1000 Subject: [PATCH 6/6] revert killing docker --- .../SystemTestSpy/speechSpyGlobalPlugin.py | 21 +------------------ 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py index 6621f2c7ef4..fe5868cd888 100644 --- a/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py +++ b/tests/system/libraries/SystemTestSpy/speechSpyGlobalPlugin.py @@ -159,9 +159,7 @@ def wait_for_NVDA_startup_to_complete(self): giveUpAfterSeconds=self._minTimeout(10), errorMessage="Unable to connect to nvdaSpy", ) - with self._speechLock: - self.reset_all_speech_index() - self.wait_for_speech_to_finish() + self.reset_all_speech_index() def get_last_speech(self) -> str: return self._getSpeechAtIndex(-1) @@ -198,8 +196,6 @@ def wait_for_specific_speech( errorMessage=None ) if not success: - if self._popup_stole_focus(): - return self.wait_for_specific_speech(speech, afterIndex, maxWaitSeconds) self.dump_speech_to_log() raise AssertionError( "Specific speech did not occur before timeout: {}\n" @@ -207,21 +203,6 @@ def wait_for_specific_speech( ) return speechIndex - def _popup_stole_focus(self): - KNOWN_POPUPS = [ - { - "speech": "Your feedback is important to us", - "process_name": "Docker Desktop.exe" - }, - ] - last_speech = self.get_last_speech() - for popup in KNOWN_POPUPS: - if last_speech == popup["speech"]: - log.debug(f"{popup['process_name']} stole focus, killing the process") - os.system(f'taskkill /im "{popup["process_name"]}"') - return True - return False - def wait_for_speech_to_finish( self, maxWaitSeconds=5.0,