Skip to content

Commit ba30dd4

Browse files
SWTBot test case: Launch Target editor verification (#1304)
SWTBot test case: Launch Target editor verification (#1304) (IEP-1629)
1 parent a6383d9 commit ba30dd4

File tree

3 files changed

+308
-22
lines changed

3 files changed

+308
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/*******************************************************************************
2+
* Copyright 2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
3+
* Use is subject to license terms.
4+
*******************************************************************************/
5+
package com.espressif.idf.ui.test.executable.cases.project;
6+
7+
import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled;
8+
import static org.junit.Assert.assertTrue;
9+
10+
import java.io.IOException;
11+
12+
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
13+
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
14+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
15+
import org.junit.AfterClass;
16+
import org.junit.BeforeClass;
17+
import org.junit.FixMethodOrder;
18+
import org.junit.Test;
19+
import org.junit.runner.RunWith;
20+
import org.junit.runners.MethodSorters;
21+
22+
import com.espressif.idf.ui.handlers.Messages;
23+
import com.espressif.idf.ui.test.common.WorkBenchSWTBot;
24+
import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility;
25+
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
26+
import com.espressif.idf.ui.test.operations.ProjectTestOperations;
27+
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;
28+
29+
/**
30+
* Test class to test the Launch Target Editor
31+
*
32+
* @author Andrii Filippov
33+
*
34+
*/
35+
@SuppressWarnings("restriction")
36+
@RunWith(SWTBotJunit4ClassRunner.class)
37+
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
38+
39+
public class IDFProjectLaunchTargetEditorFunctionalityTest {
40+
@BeforeClass
41+
public static void beforeTestClass() throws Exception
42+
{
43+
Fixture.loadEnv();
44+
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
45+
Fixture.givenProjectNameIs("LaunchTargetEditorTest");
46+
Fixture.whenNewProjectIsSelected();
47+
}
48+
49+
@AfterClass
50+
public static void afterEachTest()
51+
{
52+
try
53+
{
54+
Fixture.cleanTestEnv();
55+
}
56+
catch (Exception e)
57+
{
58+
System.err.println("Error during cleanup: " + e.getMessage());
59+
}
60+
}
61+
62+
@Test
63+
public void givenANewProjectCreatedBuiltWhenSelectNewTargetWhenPopUpAppearsThenBuildFolderDeletedSuccessfully()
64+
throws Exception
65+
{
66+
Fixture.whenProjectIsBuiltUsingContextMenu();
67+
Fixture.whenChangeLaunchTarget();
68+
Fixture.whenRefreshProject();
69+
Fixture.thenBuildFolderDeletedSuccessfully();
70+
}
71+
72+
@Test
73+
public void givenBNewProjectCreatedWhenCreateNewLaunchTargetThenProjectBuiltSuccessfully()
74+
throws Exception
75+
{
76+
Fixture.whenCreateNewLaunchTarget();
77+
Fixture.whenProjectIsBuiltUsingContextMenu();
78+
}
79+
80+
@Test
81+
public void givenCNewProjectCreatedWhenDeleteSelectedLaunchTargetThenDeletedSuccessfully()
82+
throws Exception
83+
{
84+
Fixture.whenProjectFullCleanUsingContextMenu();
85+
Fixture.whenDeleteSelectedLaunchTarget();
86+
Fixture.thenLaunchTargetDeletedSuccessfully();
87+
}
88+
89+
private static class Fixture
90+
{
91+
private static SWTWorkbenchBot bot;
92+
private static String category;
93+
private static String subCategory;
94+
private static String projectName;
95+
96+
private static void loadEnv() throws Exception
97+
{
98+
bot = WorkBenchSWTBot.getBot();
99+
EnvSetupOperations.setupEspressifEnv(bot);
100+
bot.sleep(1000);
101+
ProjectTestOperations.deleteAllProjects(bot);
102+
}
103+
104+
private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory)
105+
{
106+
Fixture.category = category;
107+
Fixture.subCategory = subCategory;
108+
}
109+
110+
private static void givenProjectNameIs(String projectName)
111+
{
112+
Fixture.projectName = projectName;
113+
}
114+
115+
private static void whenNewProjectIsSelected() throws Exception
116+
{
117+
ProjectTestOperations.setupProject(projectName, category, subCategory, bot);
118+
}
119+
120+
private static void whenProjectIsBuiltUsingContextMenu() throws IOException
121+
{
122+
ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot);
123+
ProjectTestOperations.waitForProjectBuild(bot);
124+
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
125+
}
126+
127+
private static void whenChangeLaunchTarget() throws Exception
128+
{
129+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
130+
targetSelector.selectTarget("esp32c2");
131+
TestWidgetWaitUtility.waitForDialogToAppear(bot, "IDF Launch Target Changed", 20000);
132+
SWTBotShell shell = bot.shell("IDF Launch Target Changed");
133+
shell.setFocus();
134+
bot.button("Yes").click();
135+
}
136+
137+
private static void whenSelectLaunchTarget() throws Exception
138+
{
139+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
140+
targetSelector.selectTarget("target");
141+
}
142+
143+
private static void whenDeleteLaunchTarget() throws Exception
144+
{
145+
bot.sleep(500);
146+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
147+
targetSelector.clickEdit();
148+
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000);
149+
SWTBotShell shell = bot.shell("New ESP Target");
150+
shell.setFocus();
151+
bot.button("Delete").click();
152+
}
153+
154+
private static void whenDeleteSelectedLaunchTarget() throws Exception
155+
{
156+
whenSelectLaunchTarget();
157+
whenDeleteLaunchTarget();
158+
}
159+
160+
private static void thenLaunchTargetDeletedSuccessfully() throws Exception
161+
{
162+
bot.sleep(500);
163+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
164+
assertTrue("Launch Target was not deleted successfully!", !targetSelector.isTargetPresent("target"));
165+
}
166+
167+
private static void selectNewLaunchTarget()
168+
{
169+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
170+
targetSelector.select("New Launch Target...");
171+
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New Launch Target", 20000);
172+
assertTrue("'New Launch Target' dialog did not appear", bot.shell("New Launch Target").isActive());
173+
}
174+
175+
private static void handleNewLaunchTargetDialog() throws Exception
176+
{
177+
SWTBotShell shell = bot.shell("New Launch Target");
178+
bot.table().select("ESP Target");
179+
shell.setFocus();
180+
bot.waitUntil(widgetIsEnabled(bot.button("Next >")), 5000);
181+
bot.button("Next >").click();
182+
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target",10000);
183+
}
184+
185+
private static void handleNewEspTargetDialog() throws Exception
186+
{
187+
bot.textWithLabel("Name:").setText("target");
188+
bot.button("Finish").click();
189+
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
190+
}
191+
192+
private static void whenCreateNewLaunchTarget() throws Exception
193+
{
194+
selectNewLaunchTarget();
195+
handleNewLaunchTargetDialog();
196+
handleNewEspTargetDialog();
197+
}
198+
199+
private static void whenRefreshProject() throws IOException
200+
{
201+
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Refresh");
202+
}
203+
204+
private static void thenBuildFolderDeletedSuccessfully() throws Exception
205+
{
206+
assertTrue("Build folder was not deleted successfully!", ProjectTestOperations.findProjectFullCleanedFilesInBuildFolder(projectName, bot));
207+
}
208+
209+
private static void whenProjectFullCleanUsingContextMenu() throws IOException
210+
{
211+
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Project Full Clean");
212+
ProjectTestOperations.joinJobByName(Messages.ProjectFullCleanCommandHandler_RunningFullcleanJobName);
213+
ProjectTestOperations.findInConsole(bot, "Espressif IDF Tools Console", "Done");
214+
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
215+
}
216+
217+
private static void cleanTestEnv()
218+
{
219+
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
220+
ProjectTestOperations.closeAllProjects(bot);
221+
ProjectTestOperations.deleteAllProjects(bot);
222+
}
223+
}
224+
}
225+

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,12 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException
8888
SWTBotView consoleView = viewConsole("CDT Build Console", bot);
8989
consoleView.show();
9090
consoleView.setFocus();
91+
try {
9192
TestWidgetWaitUtility.waitUntilViewContains(bot, "Build complete", consoleView,
9293
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 300000));
94+
} catch (Exception e) {
95+
throw new AssertionError("Project Build failed", e);
96+
}
9397
}
9498

9599
public static void waitForProjectFlash(SWTWorkbenchBot bot) throws IOException

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/selectors/LaunchBarTargetSelector.java

Lines changed: 79 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
99
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;
1010

11+
import java.util.List;
12+
1113
import org.eclipse.launchbar.ui.controls.internal.CSelector;
1214
import org.eclipse.launchbar.ui.controls.internal.LaunchBarWidgetIds;
1315
import org.eclipse.launchbar.ui.controls.internal.TargetSelector;
@@ -23,7 +25,9 @@
2325
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
2426
import org.eclipse.swtbot.swt.finder.results.Result;
2527
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
28+
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
2629
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
30+
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
2731

2832
/**
2933
* Launchbar CDT helper class to select items from launch targets
@@ -98,27 +102,80 @@ public LaunchBarTargetSelector select(String text)
98102

99103
public LaunchBarTargetSelector selectTarget(String text)
100104
{
101-
click();
102-
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
103-
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
104-
int numberOfItemsInScrolledComp = syncExec(
105-
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
106-
Label itemToSelect;
107-
108-
// Set the text in the not visible text field
109-
// when the target list is too big, swtbot cannot select a target label, so we filter the list
110-
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
111-
{
112-
swtBotShell.bot().text().setText(text);
113-
itemToSelect = swtBotShell.bot().label(0).widget;
114-
}
115-
else
116-
{
117-
itemToSelect = swtBotShell.bot().widget(withText(text));
118-
}
119-
120-
Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
121-
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
122-
return this;
105+
click();
106+
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
107+
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
108+
int numberOfItemsInScrolledComp = syncExec(
109+
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
110+
Label itemToSelect;
111+
112+
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
113+
{
114+
swtBotShell.bot().text().setText(text);
115+
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
116+
}
117+
else
118+
{
119+
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
120+
}
121+
122+
Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
123+
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
124+
return this;
125+
}
126+
127+
public void scrollToBottom(ScrolledComposite scrolledComposite)
128+
{
129+
syncExec(() -> {
130+
scrolledComposite.setOrigin(0, scrolledComposite.getClientArea().height);
131+
});
132+
}
133+
134+
public boolean isTargetPresent(String text)
135+
{
136+
click();
137+
138+
try
139+
{
140+
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
141+
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
142+
143+
int numberOfItemsInScrolledComp = syncExec(() ->
144+
((Composite) scrolledComposite.getChildren()[0]).getChildren().length
145+
);
146+
147+
// Scroll to the bottom if there are many items
148+
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
149+
{
150+
scrollToBottom(swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)));
151+
swtBotShell.bot().text().setText(text);
152+
153+
List<? extends Label> labels = swtBotShell.bot().widgets(widgetOfType(Label.class));
154+
for (Label label : labels)
155+
{
156+
String labelText = syncExec(label::getText);
157+
if (labelText.equals(text))
158+
{
159+
return true;
160+
}
161+
}
162+
return false;
163+
}
164+
else
165+
{
166+
Widget itemToCheck = swtBotShell.bot().widget(withText(text));
167+
String labelText = syncExec(() -> ((Label) itemToCheck).getText());
168+
return labelText.equals(text);
169+
}
170+
}
171+
catch (WidgetNotFoundException e)
172+
{
173+
return false;
174+
}
175+
catch (Exception e)
176+
{
177+
e.printStackTrace();
178+
return false;
179+
}
123180
}
124181
}

0 commit comments

Comments
 (0)