Make sure that the main window(s) are first in the windowsWithKeyWindow array

`stepToDismissPopover` looks at the first window in the array returned by `windowsWithKeyWindow`; this is not always the main window.  This commit (a) makes sure that the main window is first, if present, and (b) makes sure that the app delegate's window is used if it's different to the app's key window (this was happening on my system causing the step to fail).