Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- runtime: linux
os: ubuntu-latest
- runtime: mac
os: macOS-14
os: macOS-latest
- runtime: windows
os: windows-latest
- test-group: Maven-MicroProfile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import com.intellij.remoterobot.fixtures.JTreeFixture;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

public abstract class SingleModJakartaLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTEBOT_URL);
Expand Down Expand Up @@ -69,6 +72,17 @@ public static void cleanup() {
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, "SystemResource");
}

/**
* Tests Jakarta Language Server code snippet support in a Java source file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.intellij.remoterobot.utils.Keyboard;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -26,6 +28,7 @@

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class SingleModLibertyLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTEBOT_URL);
Expand Down Expand Up @@ -75,6 +78,18 @@ public static void cleanup() {
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
// Handle macOS permission popup if it appears
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, "server.xml");
}

/**
* Tests Liberty Lemminx Extension Hover support in server.xml for a
* Liberty Server Feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
import com.intellij.remoterobot.fixtures.JTreeFixture;
import io.openliberty.tools.intellij.it.fixtures.ProjectFrameFixture;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;

import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;

@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class SingleModMPLSTestCommon {
public static final String REMOTEBOT_URL = "http://localhost:8082";
public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTEBOT_URL);
Expand Down Expand Up @@ -74,6 +77,18 @@ public static void cleanup() {
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
// Handle macOS permission popup if it appears
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, "ServiceLiveHealthCheck");
}

/**
* Tests MicroProfile Language Server code snippet support in a Java source file
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.automation.remarks.junit5.Video;
import com.intellij.remoterobot.RemoteRobot;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.io.File;
import java.nio.file.Paths;
Expand All @@ -22,6 +24,7 @@
/**
* Holds common tests that use a single module MicroProfile project.
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class SingleModMPProjectCfgTestCommon {

// In this test case the environment has been set up so that there is a new project
Expand Down Expand Up @@ -137,6 +140,22 @@ protected static void closeProjectView() {
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
boolean isGradle = getSmMPProjectName().equals("singleMod GradleMP");
String buildFileName = isGradle ? "build.gradle" : "pom.xml";
// Open the build file to bring focus
UIBotTestUtils.openFile(remoteRobot, smMpProjectName, buildFileName, smMpProjectName);
// Handle macOS permission popup if it appears
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, buildFileName);
}

/**
* Create a run configuration and see if it caused a null pointer exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
/**
* Holds common tests that use a single module MicroProfile project.
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class SingleModMPProjectTestCommon {

/**
Expand Down Expand Up @@ -348,6 +349,20 @@ protected static void closeProjectView() {
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
// Open the build file to bring focus
UIBotTestUtils.openFile(remoteRobot, smMpProjectName, getBuildFileName(), smMpProjectName);
// Handle macOS permission popup if it appears
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, getBuildFileName());
}

/**
* Tests the liberty: View <project build file> action run from the project's pop-up action menu.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.automation.remarks.junit5.Video;
import com.intellij.remoterobot.RemoteRobot;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -25,6 +27,7 @@
/**
* Holds common tests that use a single module non Liberty Tools compliant REST project.
*/
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public abstract class SingleModNLTRestProjectTestCommon {

/**
Expand Down Expand Up @@ -145,6 +148,20 @@ public void setBuildFileName(String name) {
buildFileName = name;
}

/**
* Test to handle macOS permission popup if it appears
*/
@Order(1)
@Test
@Video
@EnabledOnOs({OS.MAC})
public void AllowPopupTest() {
// Open the build file to bring focus
UIBotTestUtils.openFile(remoteRobot, smNLTRestProjectName, getBuildFileName(), smNLTRestProjectName);
// Handle macOS permission popup if it appears
UIBotTestUtils.handleMacOSPermissionPopup(remoteRobot, getBuildFileName());
}

/**
* Tests manually Adding/Removing project from the tool window using the Liberty add/remove
* options available through search everywhere panel.
Expand Down
64 changes: 64 additions & 0 deletions src/test/java/io/openliberty/tools/intellij/it/UIBotTestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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());
}
}
}
Loading