Skip to content

prevent Chrome losing focus during systests - #12293

Merged
seanbudd merged 8 commits into
masterfrom
fix-systests-2
Apr 21, 2021
Merged

prevent Chrome losing focus during systests#12293
seanbudd merged 8 commits into
masterfrom
fix-systests-2

Conversation

@seanbudd

@seanbudd seanbudd commented Apr 15, 2021

Copy link
Copy Markdown
Member

Link to issue number:

None

Summary of the issue:

Our system tests randomly fail due to chrome not having focus, and so NVDA does not read the expected speech. Sometimes this is due to a Docker popup asking for feedback such as this one .

Description of how this pull request fixes the issue:

  • Log when the event postNvdaStartup fires
  • sleep for 2s before launching chrome

Testing strategy:

Run many builds to ensure system tests don't fail.

Known issues with pull request:

  • Docker popups may still block the build
  • 2s of sleep might not be long enough (we have confidence that 10s is)
  • Lint checking randomly blocks builds due to a failed merge (likely due to a rare GitHub issue)

Change log entry:

None

Code Review Checklist:

  • Pull Request description is up to date.
  • Unit tests.
  • System (end to end) tests.
  • Manual tests.
  • User Documentation.
  • Change log entry.
  • Context sensitive help for GUI changes.

@seanbudd
seanbudd marked this pull request as ready for review April 15, 2021 07:02
@seanbudd seanbudd changed the title attempt to avoid NVDA losing focus during systests prevent NVDA losing focus during systests Apr 15, 2021
@seanbudd seanbudd self-assigned this Apr 15, 2021
@seanbudd seanbudd changed the title prevent NVDA losing focus during systests prevent chrome losing focus during systests Apr 15, 2021
@seanbudd seanbudd changed the title prevent chrome losing focus during systests prevent Chrome losing focus during systests Apr 15, 2021
@feerrenrut

feerrenrut commented Apr 20, 2021

Copy link
Copy Markdown
Contributor

The build artifacts for the build linked in the description will expire, and become unavailable in 6 months (soon this will change to 3 months I believe). So I'll attach the relevant files here:
dockerPopup-systemTestResults.zip
dockerPopup-fullBuildlog.txt

@seanbudd seanbudd added this to the 2021.1 milestone Apr 20, 2021
Comment thread source/core.py Outdated
Co-authored-by: Reef Turner <feerrenrut@users.noreply.github.com>
Comment on lines +201 to +202
if self._popup_stole_focus():
return self.wait_for_specific_speech(speech, afterIndex, maxWaitSeconds)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't think I saw any tests where this window being created mid system test was likely. Certainly there were situations where the popup had focus, but I doubt it was due to the popup being created mid test. Instead I suspect it was a result of NVDA "restoring focus" over the top of chrome due to a race condition during startup. I expect that the popup is first created much earlier, during the build.

Perhaps a comment in here (or the function) to say that this is to collect data on whether this is happening. And may be removed if we determine that it is not. An alternative approach may be to have an "allow list" of windows / processes that are allowed to gain focus after the test is started, anything else is a failure with the process name reported.

@seanbudd seanbudd Apr 21, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test where we sleep for 10s failed due to a docker popup: https://ci.appveyor.com/project/NVAccess/nvda/builds/38672328/artifacts.

@michaelDCurran also noted that we probably shouldn't be killing processes that developers may be running when running system tests locally. I'm going to remove this code in favour of the quick sleep fix and we can follow up to address the Docker issue later.

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 959892a3d4

@seanbudd

Copy link
Copy Markdown
Member Author

See test results for failed build of commit 959892a3d4

well it seems like this fix does not work - should we return to sleeping before launching chrome?

@AppVeyorBot

Copy link
Copy Markdown

See test results for failed build of commit 56f6f10d89

@feerrenrut

Copy link
Copy Markdown
Contributor

System test failure
Build (for testing PR)
See test results for failed build of commit 959892a

well it seems like this fix does not work - should we return to sleeping before launching chrome?

That build failure had the following log, from the screen shot I could confirm that the taskbar had focus.

DEBUG - core._doPostNvdaStartupAction (02:03:06.704) - MainThread (4720):
Notify of postNvdaStartup action
IO - speech.speak (02:03:06.704) - MainThread (4720):
Speaking [LangChangeCommand ('en'), 'Taskbar', CancellableSpeech (still valid)]
DEBUGWARNING - IAccessibleHandler.internalWinEventHandler._shouldGetEvents (02:03:08.007) - MainThread (4720):
Foreground took too long to change. Foreground still 131098 (Shell_TrayWnd). Should be 328256 (Chrome_WidgetWin_1)
DEBUG - external:globalPlugins.speechSpyGlobalPlugin.NVDASpyLib.dump_speech_to_log (02:03:12.546) - RF Test Spy Thread (2444):
dump_speech_to_log.
DEBUGWARNING - displayModel.DisplayModelTextInfo._get__storyFieldsAndRects (02:03:12.546) - RF Test Spy Thread (2444):
AppModule does not have a binding handle
INFO - external:globalPlugins.speechSpyGlobalPlugin.NVDASpyLib._devInfoToLog (02:03:12.546) - RF Test Spy Thread (2444):
Developer info for navigator object:
name: 'Taskbar'
role: ROLE_PANE
roleText: None
states: STATE_FOCUSABLE, STATE_FOCUSED
isFocusable: True
hasFocus: True
Python object: <NVDAObjects.IAccessible.Taskbar object at 0x06C32178>
Python class mro: (<class 'NVDAObjects.IAccessible.Taskbar'>, <class 'NVDAObjects.IAccessible.IAccessible'>, <class 'NVDAObjects.window.Window'>, <class 'NVDAObjects.NVDAObject'>, <class 'documentBase.TextContainerObject'>, <class 'baseObject.ScriptableObject'>, <class 'baseObject.AutoPropertyObject'>, <class 'garbageHandler.TrackedObject'>, <class 'object'>)
description: None
location: RectLTWH(left=0, top=728, width=1024, height=40)
value: None
appModule: <'explorer' (appName 'explorer', process ID 4376) at address 5200178>
appModule.productName: 'Microsoft® Windows® Operating System'
appModule.productVersion: '10.0.17763.1'
TextInfo: <class 'NVDAObjects.NVDAObjectTextInfo'>
windowHandle: 131098
windowClassName: 'Shell_TrayWnd'
windowControlID: 0
windowStyle: -1778384896
extendedWindowStyle: 136
windowThreadID: 4500
windowText: ''
displayText: ''
IAccessibleObject: <POINTER(IAccessible) ptr=0x39c02d8 at 69ce4f0>
IAccessibleChildID: 0
IAccessible event parameters: windowHandle=131098, objectID=-4, childID=0
IAccessible accName: 'Taskbar'
IAccessible accRole: ROLE_SYSTEM_CLIENT
IAccessible accState: STATE_SYSTEM_FOCUSED, STATE_SYSTEM_FOCUSABLE, STATE_SYSTEM_VALID (1048580)
IAccessible accDescription: None
IAccessible accValue: None
DEBUG - external:globalPlugins.speechSpyGlobalPlugin.NVDASpyLib.dump_speech_to_log (02:03:12.546) - RF Test Spy Thread (2444):
All speech:
[[''], [LangChangeCommand ('en'), 'Taskbar  ', IndexCommand(1)]]

@seanbudd
seanbudd requested a review from a team as a code owner April 21, 2021 00:14
@seanbudd
seanbudd merged commit 0703066 into master Apr 21, 2021
@seanbudd
seanbudd deleted the fix-systests-2 branch April 21, 2021 01:01
@feerrenrut

Copy link
Copy Markdown
Contributor

It's a shame to lose the logging for the startup task.

@feerrenrut

Copy link
Copy Markdown
Contributor

My mistake, I looked at the "changes since last review"

seanbudd added a commit that referenced this pull request May 5, 2021
As discussed in #12293, our systems fail randomly. Usually this is due to another window stealing focus, such as the taskbar or Docker. As system tests are run locally, we shouldn't be killing these processes.

Description of how this pull request fixes the issue:
Use windows API to make the chrome window gain focus
Adds logging that lists the foreground window and open windows if chrome doesn't gain focus
Removes extra sleep time after starting NVDA
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants