|
| 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 | + |
0 commit comments