From bc7ad19d9021d5094ac349d6ec6c9087ca43ff9d Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 20 Oct 2025 13:32:47 +0300 Subject: [PATCH 1/6] feat: added a test to verify esp-idf terminal in the IDE --- .../idf/ui/test/TerminalViewTest.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java new file mode 100644 index 000000000..6b6dda91c --- /dev/null +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -0,0 +1,97 @@ +package com.espressif.idf.ui.test; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.espressif.idf.ui.test.operations.EnvSetupOperations; + +@RunWith(SWTBotJunit4ClassRunner.class) +public class TerminalViewTest +{ + + private static SWTWorkbenchBot bot; + + @BeforeClass + public static void setup() throws Exception + { + + bot = new SWTWorkbenchBot(); + EnvSetupOperations.setupEspressifEnv(bot); + } + + @Test + public void testOpenTerminalView() throws Exception + { + // Create a temporary file for capturing terminal output + Path tempFile = Files.createTempFile("idf_version_output", ".txt"); + File outputFile = tempFile.toFile(); + outputFile.deleteOnExit(); // ensure cleanup after JVM exits + + bot.toolbarButtonWithTooltip("Open a Terminal").click(); + bot.comboBox().setSelection("ESP-IDF Terminal"); + bot.button("OK").click(); + SWTBotView terminalView = bot.viewByTitle("Terminal"); + terminalView.show(); + terminalView.setFocus(); + + // Wait for terminal to initialize + bot.sleep(3000); + + // Type command into the Canvas terminal + SWTBotCanvas canvas = terminalView.bot().canvas(); + canvas.setFocus(); + + // Command with temporary file + String cmd = "idf.py --version > " + outputFile.getAbsolutePath(); + canvas.display.syncExec(() -> { + for (char c : cmd.toCharArray()) + { + Event e = new Event(); + e.type = SWT.KeyDown; + e.character = c; + canvas.widget.notifyListeners(SWT.KeyDown, e); + + Event e2 = new Event(); + e2.type = SWT.KeyUp; + e2.character = c; + canvas.widget.notifyListeners(SWT.KeyUp, e2); + } + + // Press Enter + Event enterDown = new Event(); + enterDown.type = SWT.KeyDown; + enterDown.character = '\r'; + canvas.widget.notifyListeners(SWT.KeyDown, enterDown); + + Event enterUp = new Event(); + enterUp.type = SWT.KeyUp; + enterUp.character = '\r'; + canvas.widget.notifyListeners(SWT.KeyUp, enterUp); + }); + + // Wait for the command to execute + bot.sleep(5000); + + // Read the output from the temporary file + String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8); + + assertTrue("Output should contain 'IDF v'", output.contains("IDF v")); + // Optional: delete the temp file explicitly after test + Files.deleteIfExists(tempFile); + } + +} From 8f7302b92181aa4137acb8040dc7fe5dd09b7ea7 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Mon, 20 Oct 2025 14:18:38 +0300 Subject: [PATCH 2/6] fix: on the remote IDE there is a different lable for terminal --- .../src/com/espressif/idf/ui/test/TerminalViewTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java index 6b6dda91c..4ab6e668e 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -41,7 +41,7 @@ public void testOpenTerminalView() throws Exception File outputFile = tempFile.toFile(); outputFile.deleteOnExit(); // ensure cleanup after JVM exits - bot.toolbarButtonWithTooltip("Open a Terminal").click(); + bot.toolbarButtonWithTooltip("Open a Terminal (Ctrl+Alt+Shift+T)").click(); bot.comboBox().setSelection("ESP-IDF Terminal"); bot.button("OK").click(); SWTBotView terminalView = bot.viewByTitle("Terminal"); From 3de138c6531eb599f55cb82e9d357c60cee506d7 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Tue, 21 Oct 2025 17:24:00 +0300 Subject: [PATCH 3/6] fix: cover all possible tooltips --- .../idf/ui/test/TerminalViewTest.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java index 4ab6e668e..02d9783e6 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -11,8 +11,10 @@ import org.eclipse.swt.widgets.Event; import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; +import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -41,7 +43,30 @@ public void testOpenTerminalView() throws Exception File outputFile = tempFile.toFile(); outputFile.deleteOnExit(); // ensure cleanup after JVM exits - bot.toolbarButtonWithTooltip("Open a Terminal (Ctrl+Alt+Shift+T)").click(); + String[] tooltips = { "Open a Terminal (Ctrl+Alt+Shift+T)", "Open a Terminal (Shift+Ctrl+Alt+T)", + "Open a Terminal" }; + + SWTBotToolbarButton openTerminalButton = null; + + for (String tooltip : tooltips) + { + try + { + openTerminalButton = bot.toolbarButtonWithTooltip(tooltip); + break; // stop at the first one found + } + catch (WidgetNotFoundException ignored) + { + // try next tooltip + } + } + + if (openTerminalButton == null) + { + throw new WidgetNotFoundException("Toolbar button 'Open a Terminal' not found with any known tooltip"); + } + + openTerminalButton.click(); bot.comboBox().setSelection("ESP-IDF Terminal"); bot.button("OK").click(); SWTBotView terminalView = bot.viewByTitle("Terminal"); From 55cddae27c351dd2afeac582f7ace5d009a1cddb Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Wed, 22 Oct 2025 10:01:32 +0300 Subject: [PATCH 4/6] fix: remove static bot field --- .../src/com/espressif/idf/ui/test/TerminalViewTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java index 02d9783e6..d6734856c 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -25,10 +25,10 @@ public class TerminalViewTest { - private static SWTWorkbenchBot bot; + private SWTWorkbenchBot bot; @BeforeClass - public static void setup() throws Exception + public void setup() throws Exception { bot = new SWTWorkbenchBot(); From 5a158ed12ba0c3e13e1f880ce4150503eaabe846 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Wed, 22 Oct 2025 10:14:31 +0300 Subject: [PATCH 5/6] fix: return static field since it's needed for beforeClass --- .../src/com/espressif/idf/ui/test/TerminalViewTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java index d6734856c..02d9783e6 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -25,10 +25,10 @@ public class TerminalViewTest { - private SWTWorkbenchBot bot; + private static SWTWorkbenchBot bot; @BeforeClass - public void setup() throws Exception + public static void setup() throws Exception { bot = new SWTWorkbenchBot(); From 39b687865fab8145958a4fba8c6e5c37b4aa93f9 Mon Sep 17 00:00:00 2001 From: Denys Almazov Date: Wed, 22 Oct 2025 11:19:46 +0300 Subject: [PATCH 6/6] fix: closing terminal view after tests --- .../espressif/idf/ui/test/TerminalViewTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java index 02d9783e6..85543f3e4 100644 --- a/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java +++ b/tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/TerminalViewTest.java @@ -15,6 +15,7 @@ import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas; import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton; +import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -35,6 +36,20 @@ public static void setup() throws Exception EnvSetupOperations.setupEspressifEnv(bot); } + @AfterClass + public static void cleanup() throws Exception + { + try + { + SWTBotView terminalView = bot.viewByTitle("Terminal"); + terminalView.close(); + } + catch (WidgetNotFoundException ignored) + { + } + + } + @Test public void testOpenTerminalView() throws Exception {