-
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 8 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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2025 IBM Corporation. | ||
| * | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the Eclipse Public License v. 2.0 which is available at | ||
| * http://www.eclipse.org/legal/epl-2.0. | ||
| * | ||
| * SPDX-License-Identifier: EPL-2.0 | ||
| *******************************************************************************/ | ||
| package io.openliberty.tools.intellij.it; | ||
|
|
||
| import com.intellij.remoterobot.RemoteRobot; | ||
| import com.automation.remarks.junit5.Video; | ||
| import org.junit.jupiter.api.*; | ||
| import org.junit.jupiter.api.condition.EnabledOnOs; | ||
| import org.junit.jupiter.api.condition.OS; | ||
|
|
||
|
|
||
| public class MacOSAllowPopupTest { | ||
|
|
||
| /** | ||
| * URL to display the UI Component hierarchy. This is used to obtain xPath related | ||
| * information to find UI components. | ||
| */ | ||
| public static final String REMOTE_BOT_URL = "http://localhost:8082"; | ||
|
|
||
| /** | ||
| * The remote robot object. | ||
| */ | ||
| public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTE_BOT_URL); | ||
|
|
||
| /** | ||
| * Test to handle macOS permission popup if it appears | ||
| */ | ||
| @Order(1) | ||
| @Test | ||
| @Video | ||
| @EnabledOnOs({OS.MAC}) | ||
| public void AllowPopupTest() { | ||
| UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,7 +21,8 @@ | |
|
|
||
| import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError; | ||
|
|
||
| public abstract class SingleModJakartaLSTestCommon { | ||
| @TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
|
||
| public abstract class SingleModJakartaLSTestCommon extends MacOSAllowPopupTest { | ||
| public static final String REMOTEBOT_URL = "http://localhost:8082"; | ||
| public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTEBOT_URL); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2939,4 +2939,45 @@ 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. | ||
| */ | ||
| public static void handleMacOSPermissionPopup(RemoteRobot remoteRobot) { | ||
| if (!remoteRobot.isMac()) { | ||
| return; // Only applicable to macOS | ||
| } | ||
| TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, "Handling macOS permission popup..."); | ||
|
|
||
| // Wait for the permission popup to appear | ||
| TestUtils.sleepAndIgnoreException(10); | ||
| // 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" + | ||
| " tell process \"UserNotificationCenter\"\n" + | ||
| " if exists window 1 then\n" + | ||
| " try\n" + | ||
| " set dialogText to value of static text 1 of window 1\n" + | ||
| " if dialogText contains \"bash\" and dialogText contains \"screen and audio\" then\n" + | ||
| " if exists button \"Allow\" of window 1 then\n" + | ||
| " click button \"Allow\" of window 1\n" + | ||
| " end if\n" + | ||
| " end if\n" + | ||
| " end try\n" + | ||
| " end if\n" + | ||
| " end tell\n" + | ||
| "end tell"; | ||
|
|
||
| new ProcessBuilder("osascript", "-e", appleScript).start(); | ||
|
|
||
| // Wait a moment for the click to take effect | ||
| TestUtils.sleepAndIgnoreException(5); | ||
|
|
||
| } catch (Exception e) { | ||
| TestUtils.printTrace(TestUtils.TraceSevLevel.ERROR, "Failed to execute AppleScript: " + e.getMessage()); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.
Discussed with @turkeylurkey . We'd like to suggest renaming the class to "BaseOSUtilities". It seems strange to have our common test classes extending a Mac specific class. This class could then be expanded in the future if other setup becomes necessary for any OS.
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.
Thanks for the suggestion. I have modified the name.