Skip to content

Commit 63c3340

Browse files
authored
IEP-1649 Add SWT Tests to Verify ESP-IDF Terminal in the IDE (#1337)
* feat: added a test to verify esp-idf terminal in the IDE * fix: on the remote IDE there is a different lable for terminal * fix: cover all possible tooltips * fix: remove static bot field * fix: return static field since it's needed for beforeClass * fix: closing terminal view after tests
1 parent 3c041c3 commit 63c3340

1 file changed

Lines changed: 137 additions & 0 deletions

File tree

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
package com.espressif.idf.ui.test;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.io.File;
6+
import java.nio.charset.StandardCharsets;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
10+
import org.eclipse.swt.SWT;
11+
import org.eclipse.swt.widgets.Event;
12+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
13+
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
14+
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
15+
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
16+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCanvas;
17+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
18+
import org.junit.AfterClass;
19+
import org.junit.BeforeClass;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
23+
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
24+
25+
@RunWith(SWTBotJunit4ClassRunner.class)
26+
public class TerminalViewTest
27+
{
28+
29+
private static SWTWorkbenchBot bot;
30+
31+
@BeforeClass
32+
public static void setup() throws Exception
33+
{
34+
35+
bot = new SWTWorkbenchBot();
36+
EnvSetupOperations.setupEspressifEnv(bot);
37+
}
38+
39+
@AfterClass
40+
public static void cleanup() throws Exception
41+
{
42+
try
43+
{
44+
SWTBotView terminalView = bot.viewByTitle("Terminal");
45+
terminalView.close();
46+
}
47+
catch (WidgetNotFoundException ignored)
48+
{
49+
}
50+
51+
}
52+
53+
@Test
54+
public void testOpenTerminalView() throws Exception
55+
{
56+
// Create a temporary file for capturing terminal output
57+
Path tempFile = Files.createTempFile("idf_version_output", ".txt");
58+
File outputFile = tempFile.toFile();
59+
outputFile.deleteOnExit(); // ensure cleanup after JVM exits
60+
61+
String[] tooltips = { "Open a Terminal (Ctrl+Alt+Shift+T)", "Open a Terminal (Shift+Ctrl+Alt+T)",
62+
"Open a Terminal" };
63+
64+
SWTBotToolbarButton openTerminalButton = null;
65+
66+
for (String tooltip : tooltips)
67+
{
68+
try
69+
{
70+
openTerminalButton = bot.toolbarButtonWithTooltip(tooltip);
71+
break; // stop at the first one found
72+
}
73+
catch (WidgetNotFoundException ignored)
74+
{
75+
// try next tooltip
76+
}
77+
}
78+
79+
if (openTerminalButton == null)
80+
{
81+
throw new WidgetNotFoundException("Toolbar button 'Open a Terminal' not found with any known tooltip");
82+
}
83+
84+
openTerminalButton.click();
85+
bot.comboBox().setSelection("ESP-IDF Terminal");
86+
bot.button("OK").click();
87+
SWTBotView terminalView = bot.viewByTitle("Terminal");
88+
terminalView.show();
89+
terminalView.setFocus();
90+
91+
// Wait for terminal to initialize
92+
bot.sleep(3000);
93+
94+
// Type command into the Canvas terminal
95+
SWTBotCanvas canvas = terminalView.bot().canvas();
96+
canvas.setFocus();
97+
98+
// Command with temporary file
99+
String cmd = "idf.py --version > " + outputFile.getAbsolutePath();
100+
canvas.display.syncExec(() -> {
101+
for (char c : cmd.toCharArray())
102+
{
103+
Event e = new Event();
104+
e.type = SWT.KeyDown;
105+
e.character = c;
106+
canvas.widget.notifyListeners(SWT.KeyDown, e);
107+
108+
Event e2 = new Event();
109+
e2.type = SWT.KeyUp;
110+
e2.character = c;
111+
canvas.widget.notifyListeners(SWT.KeyUp, e2);
112+
}
113+
114+
// Press Enter
115+
Event enterDown = new Event();
116+
enterDown.type = SWT.KeyDown;
117+
enterDown.character = '\r';
118+
canvas.widget.notifyListeners(SWT.KeyDown, enterDown);
119+
120+
Event enterUp = new Event();
121+
enterUp.type = SWT.KeyUp;
122+
enterUp.character = '\r';
123+
canvas.widget.notifyListeners(SWT.KeyUp, enterUp);
124+
});
125+
126+
// Wait for the command to execute
127+
bot.sleep(5000);
128+
129+
// Read the output from the temporary file
130+
String output = new String(Files.readAllBytes(tempFile), StandardCharsets.UTF_8);
131+
132+
assertTrue("Output should contain 'IDF v'", output.contains("IDF v"));
133+
// Optional: delete the temp file explicitly after test
134+
Files.deleteIfExists(tempFile);
135+
}
136+
137+
}

0 commit comments

Comments
 (0)