Skip to content

Commit 7a6ef3b

Browse files
committed
Refactor browser closure logic into reusable function
Replaced inline JavaScript workaround with a dedicated `closeBrowser` function to handle browser shutdown across different operating systems. This improves code readability and maintainability while ensuring compatibility with Windows, macOS, and Linux environments.
1 parent 1e899fa commit 7a6ef3b

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

src/test/kotlin/com/magento/idea/magento2plugin/actions/content/MarkDirectoryAsMagentoRootTest.kt

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test
2929
import org.junit.jupiter.api.extension.ExtendWith
3030
import java.awt.event.KeyEvent.*
3131
import java.io.File
32+
import java.io.IOException
3233
import java.time.Duration.ofMinutes
3334
import kotlin.io.path.createTempDirectory
3435

@@ -75,23 +76,7 @@ class MarkDirectoryAsMagentoRootTest {
7576
val dialog = find<DialogFixture>(byXpath("//div[@class='MyDialog']"))
7677
dialog.button("Close").click()
7778
Thread.sleep(10_000)
78-
step("Switch back to PhpStorm IDE window if Firefox overlay detected") {
79-
remoteRobot.runJs(
80-
"""
81-
try {
82-
const KeyEvent = Java.type("java.awt.event.KeyEvent");
83-
robot.keyPress(KeyEvent.VK_ALT);
84-
robot.keyPress(KeyEvent.VK_TAB);
85-
Thread.sleep(100);
86-
robot.keyRelease(KeyEvent.VK_TAB);
87-
robot.keyRelease(KeyEvent.VK_ALT);
88-
true;
89-
} catch (error) {
90-
false;
91-
}
92-
""".trimIndent()
93-
)
94-
}
79+
closeBrowser()
9580
// end temporary workaround
9681

9782
welcomeFrame {
@@ -192,6 +177,32 @@ class MarkDirectoryAsMagentoRootTest {
192177
}
193178
}
194179

180+
fun closeBrowser() {
181+
val os = System.getProperty("os.name").lowercase()
182+
183+
try {
184+
if (os.contains("win")) {
185+
// For Windows: Close common browsers like Chrome, Firefox, etc.
186+
Runtime.getRuntime().exec("taskkill /F /IM chrome.exe")
187+
Runtime.getRuntime().exec("taskkill /F /IM firefox.exe")
188+
Runtime.getRuntime().exec("taskkill /F /IM msedge.exe")
189+
} else if (os.contains("mac")) {
190+
// For macOS: Kill browsers using `pkill`
191+
Runtime.getRuntime().exec("pkill -f 'Google Chrome'")
192+
Runtime.getRuntime().exec("pkill -f 'Firefox'")
193+
Runtime.getRuntime().exec("pkill -f 'Safari'")
194+
} else if (os.contains("nix") || os.contains("nux")) {
195+
// For Linux-based systems: Kill typical browser processes
196+
Runtime.getRuntime().exec("pkill -f 'chrome'")
197+
Runtime.getRuntime().exec("pkill -f 'firefox'")
198+
Runtime.getRuntime().exec("pkill -f 'edge'")
199+
}
200+
} catch (e: IOException) {
201+
e.printStackTrace()
202+
}
203+
}
204+
205+
195206
private fun createAPluginWithoutMagentoRootInVendor(
196207
ideaFrame: IdeaFrame,
197208
remoteRobot1: RemoteRobot

0 commit comments

Comments
 (0)