-
Notifications
You must be signed in to change notification settings - Fork 32
Allow the “bash requesting screen access” popup in macOs latest #1482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
16b9107
850cc7e
4be5826
6df111a
524e1ab
c7227cb
43af4b0
9869123
2f1b94a
f3b9ad1
888047f
fa96fb3
310dcc7
3a87d21
2a1955a
3a82f9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2939,4 +2939,68 @@ public static void clickOnLoad(RemoteRobot remoteRobot) { | |
|
|
||
| TestUtils.sleepAndIgnoreException(5); | ||
| } | ||
|
|
||
| /** | ||
| * Handles macOS permission popup for screen recording by clicking the "Allow" button. | ||
| * | ||
| * @param remoteRobot The RemoteRobot instance. | ||
| * @param fileTabName The name of the file tab to click on for focus (e.g., "server.xml"). | ||
| */ | ||
| public static void handleMacOSPermissionPopup(RemoteRobot remoteRobot, String fileTabName) { | ||
| if (!remoteRobot.isMac()) { | ||
| return; // Only applicable to macOS | ||
| } | ||
|
|
||
| TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "Handling macOS permission popup..."); | ||
|
|
||
| // Click on the specified file tab to ensure the window is in focus | ||
| clickOnFileTab(remoteRobot, fileTabName); | ||
|
|
||
| // Wait for the permission popup to appear | ||
| TestUtils.sleepAndIgnoreException(12); | ||
|
|
||
| // Execute AppleScript to click the "Allow" button | ||
| try { | ||
| String appleScript = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to cite the source that was used as reference for this "Apple script". You can mention that the appleScript is based off an example provided at https://smartwatermelon.medium.com/automating-macos-security-dialogs-a-tale-of-yak-shaving-and-applescript-759300d6fba9. It would also be good to point to official documentation, like the one you shared here: https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/AutomatetheUserInterface.html - just in case a developer in the future needs to make changes.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added these references. |
||
| "tell application \"System Events\"\n" + | ||
| " set dialogFound to false\n" + | ||
| " \n" + | ||
| " -- Try to find and click Allow button in various processes\n" + | ||
| " repeat with proc in (every process whose visible is true)\n" + | ||
| " try\n" + | ||
| " tell proc\n" + | ||
| " if exists (button \"Allow\" of window 1) then\n" + | ||
| " click button \"Allow\" of window 1\n" + | ||
| " set dialogFound to true\n" + | ||
| " exit repeat\n" + | ||
| " end if\n" + | ||
| " end tell\n" + | ||
| " end try\n" + | ||
| " end repeat\n" + | ||
| " \n" + | ||
| " -- If not found, try specific processes\n" + | ||
| " if not dialogFound then\n" + | ||
| " try\n" + | ||
| " tell process \"UserNotificationCenter\"\n" + | ||
| " if exists button \"Allow\" of window 1 then\n" + | ||
| " click button \"Allow\" of window 1\n" + | ||
| " set dialogFound to true\n" + | ||
| " end if\n" + | ||
| " end tell\n" + | ||
| " end try\n" + | ||
| " end if\n" + | ||
| " \n" + | ||
| " return dialogFound\n" + | ||
| "end tell"; | ||
|
|
||
| new ProcessBuilder("osascript", "-e", appleScript).start(); | ||
|
|
||
| // Wait a moment for the click to take effect | ||
| TestUtils.sleepAndIgnoreException(2); | ||
|
|
||
| UIBotTestUtils.closeFileEditorTab(remoteRobot, fileTabName, "3"); | ||
| } catch (Exception e) { | ||
| TestUtils.printTrace(TestUtils.TraceSevLevel.ERROR, "Failed to execute AppleScript: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add this annotation to the base class? Will that work the way we want it to? If so, we could avoid adding this line to all the tests extending the base class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I have added it to just base class and removed it from others. It works as expected.