Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
/*******************************************************************************
* Copyright 2025 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.ui.test.executable.cases.project;

import static org.eclipse.swtbot.swt.finder.waits.Conditions.widgetIsEnabled;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;

Comment thread
AndriiFilippov marked this conversation as resolved.
import com.espressif.idf.ui.handlers.Messages;
import com.espressif.idf.ui.test.common.WorkBenchSWTBot;
import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility;
import com.espressif.idf.ui.test.operations.EnvSetupOperations;
import com.espressif.idf.ui.test.operations.ProjectTestOperations;
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;

/**
* Test class to test the Launch Target Editor
*
* @author Andrii Filippov
*
*/
@SuppressWarnings("restriction")
@RunWith(SWTBotJunit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)

public class IDFProjectLaunchTargetEditorFunctionalityTest {
@BeforeClass
public static void beforeTestClass() throws Exception
{
Fixture.loadEnv();
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("LaunchTargetEditorTest");
Fixture.whenNewProjectIsSelected();
}

@AfterClass
public static void afterEachTest()
{
try
{
Fixture.cleanTestEnv();
}
catch (Exception e)
{
System.err.println("Error during cleanup: " + e.getMessage());
}
}

@Test
public void givenANewProjectCreatedBuiltWhenSelectNewTargetWhenPopUpAppearsThenBuildFolderDeletedSuccessfully()
throws Exception
{
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenChangeLaunchTarget();
Fixture.whenRefreshProject();
Fixture.thenBuildFolderDeletedSuccessfully();
}

@Test
public void givenBNewProjectCreatedWhenCreateNewLaunchTargetThenProjectBuiltSuccessfully()
throws Exception
{
Fixture.whenCreateNewLaunchTarget();
Fixture.whenProjectIsBuiltUsingContextMenu();
}
Comment thread
AndriiFilippov marked this conversation as resolved.

@Test
public void givenCNewProjectCreatedWhenDeleteSelectedLaunchTargetThenDeletedSuccessfully()
throws Exception
{
Fixture.whenProjectFullCleanUsingContextMenu();
Fixture.whenDeleteSelectedLaunchTarget();
Fixture.thenLaunchTargetDeletedSuccessfully();
}

private static class Fixture
{
private static SWTWorkbenchBot bot;
private static String category;
private static String subCategory;
private static String projectName;

private static void loadEnv() throws Exception
{
bot = WorkBenchSWTBot.getBot();
EnvSetupOperations.setupEspressifEnv(bot);
bot.sleep(1000);
ProjectTestOperations.deleteAllProjects(bot);
}

private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory)
{
Fixture.category = category;
Fixture.subCategory = subCategory;
}

private static void givenProjectNameIs(String projectName)
{
Fixture.projectName = projectName;
}

private static void whenNewProjectIsSelected() throws Exception
{
ProjectTestOperations.setupProject(projectName, category, subCategory, bot);
}

private static void whenProjectIsBuiltUsingContextMenu() throws IOException
{
ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot);
ProjectTestOperations.waitForProjectBuild(bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
}

private static void whenChangeLaunchTarget() throws Exception
{
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
targetSelector.selectTarget("esp32c2");
TestWidgetWaitUtility.waitForDialogToAppear(bot, "IDF Launch Target Changed", 20000);

@sigmaaa sigmaaa Sep 18, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we weren’t able to find dialogs created with MessageDialog.openQuestion. Last time I checked in the 4.0 PR, I couldn’t find any dialogs created with this method. We should revisit this for the 4.0.0 part—maybe the difference lies in how we pass the shell to the dialog. For example, in the IDF Launch Target Changed dialog, we are using EclipseUtil.getShell().

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If its working on runner with green builds which I am not seeing we can use it and see what is causing this issue and fix that

SWTBotShell shell = bot.shell("IDF Launch Target Changed");
shell.setFocus();
bot.button("Yes").click();
}
Comment thread
AndriiFilippov marked this conversation as resolved.

private static void whenSelectLaunchTarget() throws Exception
{
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
targetSelector.selectTarget("target");
}

private static void whenDeleteLaunchTarget() throws Exception
{
bot.sleep(500);
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
targetSelector.clickEdit();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000);
SWTBotShell shell = bot.shell("New ESP Target");
shell.setFocus();
bot.button("Delete").click();
}

private static void whenDeleteSelectedLaunchTarget() throws Exception
{
whenSelectLaunchTarget();
whenDeleteLaunchTarget();
}
Comment on lines +149 to +158

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Also wait after deleting the launch target.

Ensures the edit dialog is closed and the workspace settled before verification.

         SWTBotShell shell = bot.shell("New ESP Target");
         shell.setFocus();
         bot.button("Delete").click();
+        bot.waitUntil(Conditions.shellCloses(shell), 20000);
+        TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SWTBotShell shell = bot.shell("New ESP Target");
shell.setFocus();
bot.button("Delete").click();
}
SWTBotShell shell = bot.shell("New ESP Target");
shell.setFocus();
bot.button("Delete").click();
bot.waitUntil(Conditions.shellCloses(shell), 20000);
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
}
🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectLaunchTargetEditorFunctionalityTest.java
around lines 151 to 154, after clicking the "Delete" button the test does not
wait for the "New ESP Target" dialog to close or for background workspace jobs
to settle; update the test to wait until the shell is closed (e.g., SWTBotShell
waitUntil/Condition for shell not active or bot.waitUntil with ShellCondition)
and then wait for workspace/job completion (e.g., waitForJobs or
Job.getJobManager().join/IDLE) before proceeding with verification so the dialog
is fully dismissed and the workspace is stable.


private static void thenLaunchTargetDeletedSuccessfully() throws Exception
{
bot.sleep(500);
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
assertTrue("Launch Target was not deleted successfully!", !targetSelector.isTargetPresent("target"));
}
Comment on lines +160 to +165

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Implement verification: ‘thenLaunchTargetDeletedSuccessfully’ is empty.

Without an assertion this test can pass even if deletion failed.

     private static void thenLaunchTargetDeletedSuccessfully() throws Exception
     {
-        bot.sleep(500);
-        LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
-        // ???
+        LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
+        boolean deleted;
+        try {
+            // If selection succeeds, target still exists
+            targetSelector.selectTarget("target");
+            deleted = false;
+        } catch (Exception e) {
+            // Expected: cannot select deleted target
+            deleted = true;
+        }
+        assertTrue("Launch target 'target' should be deleted and not selectable", deleted);
     }

If LaunchBarTargetSelector can expose isTargetPresent(String), prefer asserting assertTrue(!isTargetPresent("target")). I can submit that helper if desired.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private static void thenLaunchTargetDeletedSuccessfully() throws Exception
{
bot.sleep(500);
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
// ???
}
private static void thenLaunchTargetDeletedSuccessfully() throws Exception
{
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
boolean deleted;
try {
// If selection succeeds, target still exists
targetSelector.selectTarget("target");
deleted = false;
} catch (Exception e) {
// Expected: cannot select deleted target
deleted = true;
}
assertTrue("Launch target 'target' should be deleted and not selectable", deleted);
}
🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectLaunchTargetEditorFunctionalityTest.java
around lines 156-162, the helper thenLaunchTargetDeletedSuccessfully is empty so
the test never checks deletion; call LaunchBarTargetSelector (after the existing
sleep) to verify the target is gone and assert that deletion succeeded. If
LaunchBarTargetSelector provides isTargetPresent(String), use
Assert.assertFalse(targetSelector.isTargetPresent("target")); otherwise retrieve
the target list via the selector and assert it does not contain the target name
(or use Assert.assertTrue(!targetList.contains("target"))), so the test fails
when the launch target is still present.


private static void selectNewLaunchTarget()
{
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
targetSelector.select("New Launch Target...");
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New Launch Target", 20000);
assertTrue("'New Launch Target' dialog did not appear", bot.shell("New Launch Target").isActive());
}

private static void handleNewLaunchTargetDialog() throws Exception
{
SWTBotShell shell = bot.shell("New Launch Target");
bot.table().select("ESP Target");
shell.setFocus();
bot.waitUntil(widgetIsEnabled(bot.button("Next >")), 5000);
bot.button("Next >").click();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target",10000);
}

private static void handleNewEspTargetDialog() throws Exception
{
bot.textWithLabel("Name:").setText("target");
bot.button("Finish").click();
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
}

private static void whenCreateNewLaunchTarget() throws Exception
{
selectNewLaunchTarget();
handleNewLaunchTargetDialog();
handleNewEspTargetDialog();
}
Comment thread
AndriiFilippov marked this conversation as resolved.

private static void whenRefreshProject() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Refresh");
}
Comment thread
AndriiFilippov marked this conversation as resolved.

private static void thenBuildFolderDeletedSuccessfully() throws Exception
{
assertTrue("Build folder was not deleted successfully!", ProjectTestOperations.findProjectFullCleanedFilesInBuildFolder(projectName, bot));
}

private static void whenProjectFullCleanUsingContextMenu() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Project Full Clean");
ProjectTestOperations.joinJobByName(Messages.ProjectFullCleanCommandHandler_RunningFullcleanJobName);
ProjectTestOperations.findInConsole(bot, "Espressif IDF Tools Console", "Done");
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
}

private static void cleanTestEnv()
{
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException
SWTBotView consoleView = viewConsole("CDT Build Console", bot);
consoleView.show();
consoleView.setFocus();
try {
TestWidgetWaitUtility.waitUntilViewContains(bot, "Build complete", consoleView,
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 300000));
} catch (Exception e) {
throw new AssertionError("Project Build failed", e);
}
}

public static void waitForProjectFlash(SWTWorkbenchBot bot) throws IOException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;

import java.util.List;

import org.eclipse.launchbar.ui.controls.internal.CSelector;
import org.eclipse.launchbar.ui.controls.internal.LaunchBarWidgetIds;
import org.eclipse.launchbar.ui.controls.internal.TargetSelector;
Expand All @@ -23,7 +25,9 @@
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;

Comment thread
AndriiFilippov marked this conversation as resolved.
/**
* Launchbar CDT helper class to select items from launch targets
Expand Down Expand Up @@ -98,27 +102,80 @@ public LaunchBarTargetSelector select(String text)

public LaunchBarTargetSelector selectTarget(String text)
{
click();
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
int numberOfItemsInScrolledComp = syncExec(
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
Label itemToSelect;

// Set the text in the not visible text field
// when the target list is too big, swtbot cannot select a target label, so we filter the list
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
{
swtBotShell.bot().text().setText(text);
itemToSelect = swtBotShell.bot().label(0).widget;
}
else
{
itemToSelect = swtBotShell.bot().widget(withText(text));
}

Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
return this;
click();
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
int numberOfItemsInScrolledComp = syncExec(
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
Label itemToSelect;

if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
{
swtBotShell.bot().text().setText(text);
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
}
else
{
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
}

Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
return this;
}

public void scrollToBottom(ScrolledComposite scrolledComposite)
{
syncExec(() -> {
scrolledComposite.setOrigin(0, scrolledComposite.getClientArea().height);
});
}

public boolean isTargetPresent(String text)
{
click();

try
{
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));

int numberOfItemsInScrolledComp = syncExec(() ->
((Composite) scrolledComposite.getChildren()[0]).getChildren().length
);

// Scroll to the bottom if there are many items
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
{
scrollToBottom(swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)));
swtBotShell.bot().text().setText(text);

List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class));
Comment thread
AndriiFilippov marked this conversation as resolved.
Outdated
for (Widget widget : labels)
{
String labelText = syncExec(() -> ((Label) widget).getText());
if (labelText.equals(text))
{
return true;
}
}
return false;
}
else
{
Widget itemToCheck = swtBotShell.bot().widget(withText(text));
String labelText = syncExec(() -> ((Label) itemToCheck).getText());
return labelText.equals(text);
}
}
catch (WidgetNotFoundException e)
{
return false;
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
Comment on lines +126 to +180

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Close the popup and avoid side effects; tighten matching scope to reduce false positives.

  • The popup remains open on all return paths, and the filter text may remain populated. This can make subsequent SWTBot steps flaky. Ensure the shell is closed (e.g., in finally).
  • After filtering, scanning all labels in the shell risks matching unrelated labels. Limit search to the ScrolledComposite’s list content.
  • In the short-list branch, you can rely on label(text) instead of casting from a generic Widget.

Apply this diff:

-   public boolean isTargetPresent(String text)
-   {
-       click();
-
-       try
-       {
-           SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
-           ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
-
-           int numberOfItemsInScrolledComp = syncExec(() ->
-               ((Composite) scrolledComposite.getChildren()[0]).getChildren().length
-           );
-
-           if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
-           {
-               swtBotShell.bot().text().setText(text);
-
-               List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class));
-               for (Widget widget : labels)
-               {
-                   String labelText = syncExec(() -> ((Label) widget).getText());
-                   if (labelText.equals(text))
-                   {
-                       return true;
-                   }
-               }
-               return false;
-           }
-           else
-           {
-               Widget itemToCheck = swtBotShell.bot().widget(withText(text));
-               String labelText = syncExec(() -> ((Label) itemToCheck).getText());
-               return labelText.equals(text);
-           }
-       }
-       catch (WidgetNotFoundException e)
-       {
-           return false;
-       }
-       catch (Exception e)
-       {
-           e.printStackTrace();
-           return false;
-       }
-   }
+   public boolean isTargetPresent(String text)
+   {
+       click();
+       SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
+       boolean found = false;
+       try
+       {
+           ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
+           int numberOfItemsInScrolledComp = syncExec(() ->
+               ((Composite) scrolledComposite.getChildren()[0]).getChildren().length
+           );
+
+           if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
+           {
+               swtBotShell.bot().text().setText(text);
+               // Scan only the list content to avoid unrelated labels.
+               found = syncExec(() -> {
+                   Composite list = (Composite) scrolledComposite.getChildren()[0];
+                   for (Widget w : list.getChildren()) {
+                       if (w instanceof Label && text.equals(((Label) w).getText())) {
+                           return true;
+                       }
+                   }
+                   return false;
+               });
+           }
+           else
+           {
+               try {
+                   swtBotShell.bot().label(text);
+                   found = true;
+               } catch (WidgetNotFoundException e) {
+                   found = false;
+               }
+           }
+       }
+       catch (Exception e)
+       {
+           e.printStackTrace();
+           found = false;
+       }
+       finally
+       {
+           try { swtBotShell.close(); } catch (Exception ignore) {}
+       }
+       return found;
+   }

Optional: after setting the filter text, add a short wait for UI update (e.g., a DefaultCondition) to reduce flakiness.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In
tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/selectors/LaunchBarTargetSelector.java
around lines 129 to 174, ensure the popup shell is always closed and the filter
cleared by moving shell-close/cleanup into a finally block; after typing the
filter text wait briefly for the UI to update (e.g., a short DefaultCondition or
sync) before inspecting results; when the scrolled composite contains many
items, restrict the label scan to the scrolledComposite’s child controls (not
all shell labels) by retrieving its first child Composite and iterating that
child’s children only; in the short-list branch use bot().label(text) (or
SWTBotLabel lookup) instead of casting a generic Widget to Label; keep
WidgetNotFoundException handling but ensure the finally closes the popup and
clears the filter to avoid side effects.

}