Skip to content

Commit f3598d0

Browse files
Merge pull request #833 from espressif/IEP-1038
SWTBot: 'ESP-IDF Install New Component' test case
2 parents 516a51e + ff55c58 commit f3598d0

File tree

2 files changed

+110
-1
lines changed

2 files changed

+110
-1
lines changed

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/NewEspressifIDFProjectTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,17 @@ public void givenNewProjectCreatedDfuBuiltThenHasDfuBin() throws Exception
186186
Fixture.thenProjectHasTheFile("dfu.bin", "/build");
187187
Fixture.turnOffDfu();
188188
}
189+
190+
@Test
191+
public void givenNewProjectCreatedThenInstallNewComponent() throws Exception
192+
{
193+
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
194+
Fixture.givenProjectNameIs("NewProjectTest");
195+
Fixture.whenNewProjectIsSelected();
196+
Fixture.whenProjectIsBuiltUsingContextMenu();
197+
Fixture.whenInstallNewComponentUsingContextMenu();
198+
Fixture.checkIfNewComponentIsInstalledUsingContextMenu();
199+
}
189200

190201
private static class Fixture
191202
{
@@ -284,6 +295,22 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException
284295
ProjectTestOperations.waitForProjectBuild(bot);
285296
TestWidgetWaitUtility.waitForOperationsInProgressToFinish(bot);
286297
}
298+
299+
private static void whenInstallNewComponentUsingContextMenu() throws IOException
300+
{
301+
ProjectTestOperations.openProjectNewComponentUsingContextMenu(projectName, bot);
302+
bot.editorByTitle(projectName).show();
303+
bot.button("Install").click();
304+
ProjectTestOperations.waitForProjectNewComponentInstalled(bot);
305+
bot.editorByTitle(projectName).close();
306+
ProjectTestOperations.refreshProjectUsingContextMenu(projectName, bot);
307+
}
308+
309+
private static void checkIfNewComponentIsInstalledUsingContextMenu() throws IOException
310+
{
311+
ProjectTestOperations.openProjectComponentYMLFileInTextEditorUsingContextMenu(projectName, bot);
312+
ProjectTestOperations.checkTextEditorContentForPhrase("espressif/mdns", bot);
313+
}
287314

288315
private static void thenAllConfigurationsAreDeleted()
289316
{

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.eclipse.swt.widgets.MenuItem;
1212
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
13+
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
1314
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
1415
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
1516
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
@@ -60,7 +61,16 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException
6061
consoleView.show();
6162
consoleView.setFocus();
6263
TestWidgetWaitUtility.waitUntilViewContains(bot, "Build complete", consoleView,
63-
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 60000));
64+
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 600000));
65+
}
66+
67+
public static void waitForProjectNewComponentInstalled(SWTWorkbenchBot bot) throws IOException
68+
{
69+
SWTBotView consoleView = viewConsole("ESP-IDF Console", bot);
70+
consoleView.show();
71+
consoleView.setFocus();
72+
TestWidgetWaitUtility.waitUntilViewContains(bot, "Successfully added dependency", consoleView,
73+
DefaultPropertyFetcher.getLongPropertyValue("Install New Component", 10000));
6474
}
6575

6676
public static SWTBotView viewConsole(String consoleType, SWTWorkbenchBot bot)
@@ -89,6 +99,78 @@ public static void createDebugConfiguration(String projectName, SWTWorkbenchBot
8999
}
90100

91101
}
102+
103+
public static void refreshProjectUsingContextMenu(String projectName, SWTWorkbenchBot bot)
104+
{
105+
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
106+
if (projectItem != null)
107+
{
108+
projectItem.select();
109+
projectItem.contextMenu("Refresh").click();
110+
}
111+
}
112+
113+
public static void openProjectComponentYMLFileInTextEditorUsingContextMenu(String projectName, SWTWorkbenchBot bot)
114+
{
115+
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
116+
if (projectItem != null) {
117+
projectItem.select();
118+
projectItem.expand();
119+
projectItem.getNode("main").expand();
120+
121+
int maxAttempts = 2;
122+
for (int attempt = 0; attempt <= maxAttempts; attempt++) {
123+
SWTBotTreeItem fileToOpenItem = findTreeItem(projectItem.getNode("main"), "idf_component.yml");
124+
125+
if (fileToOpenItem != null) {
126+
fileToOpenItem.select();
127+
fileToOpenItem.doubleClick();
128+
return;
129+
}
130+
131+
else {
132+
try {
133+
Thread.sleep(3000);
134+
} catch (InterruptedException e) {
135+
e.printStackTrace();
136+
}
137+
}
138+
}
139+
throw new RuntimeException("The 'idf_component.yml' file was not found in the 'main' subfolder.");
140+
}
141+
}
142+
143+
private static SWTBotTreeItem findTreeItem(SWTBotTreeItem parent, String itemName) {
144+
for (SWTBotTreeItem child : parent.getItems()) {
145+
if (child.getText().equals(itemName)) {
146+
return child;
147+
}
148+
SWTBotTreeItem found = findTreeItem(child, itemName);
149+
if (found != null) {
150+
return found;
151+
}
152+
}
153+
return null;
154+
}
155+
156+
public static void checkTextEditorContentForPhrase(String phrase, SWTWorkbenchBot bot) {
157+
SWTBotEditor textEditor = bot.activeEditor();
158+
String editorText = textEditor.toTextEditor().getText();
159+
160+
if (!editorText.contains(phrase)) {
161+
throw new RuntimeException("The specified phrase '" + phrase + "' was not found in the text editor.");
162+
}
163+
}
164+
165+
public static void openProjectNewComponentUsingContextMenu(String projectName, SWTWorkbenchBot bot)
166+
{
167+
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
168+
if (projectItem != null)
169+
{
170+
projectItem.select();
171+
projectItem.contextMenu("ESP-IDF: Install New Component").click();
172+
}
173+
}
92174

93175
/**
94176
* Creates an espressif idf project from the template

0 commit comments

Comments
 (0)