-
Notifications
You must be signed in to change notification settings - Fork 133
SWTBot test case: Launch Target editor verification #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
17be7b0
0bfddae
e5dcc06
268a097
b25b8f4
d1708c7
c4f6b9b
ed7867a
01bba94
b0777d5
82303cc
744cb38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 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(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
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); | ||||||||||||||||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| 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(); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
AndriiFilippov marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| private static void whenRefreshProject() throws IOException | ||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||
| ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Refresh"); | ||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||
|
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 |
|---|---|---|
|
|
@@ -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; | ||
|
|
@@ -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; | ||
|
|
||
|
AndriiFilippov marked this conversation as resolved.
|
||
| /** | ||
| * Launchbar CDT helper class to select items from launch targets | ||
|
|
@@ -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)); | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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.
🤖 Prompt for AI Agents |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.