|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright 2025 Espressif Systems (Shanghai) PTE LTD. |
| 3 | + * All rights reserved. Use is subject to license terms. |
| 4 | + *******************************************************************************/ |
| 5 | + |
| 6 | +package com.espressif.idf.ui.test.executable.cases.project; |
| 7 | + |
| 8 | +import java.io.IOException; |
| 9 | + |
| 10 | +import org.apache.commons.lang3.SystemUtils; |
| 11 | +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
| 12 | +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| 13 | +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; |
| 14 | +import org.junit.After; |
| 15 | +import org.junit.BeforeClass; |
| 16 | +import org.junit.FixMethodOrder; |
| 17 | +import org.junit.Test; |
| 18 | +import org.junit.runner.RunWith; |
| 19 | +import org.junit.runners.MethodSorters; |
| 20 | + |
| 21 | +import com.espressif.idf.ui.test.common.WorkBenchSWTBot; |
| 22 | +import static org.eclipse.swtbot.swt.finder.waits.Conditions.*; |
| 23 | +import static org.junit.Assert.assertTrue; |
| 24 | + |
| 25 | +import com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility; |
| 26 | +import com.espressif.idf.ui.test.operations.EnvSetupOperations; |
| 27 | +import com.espressif.idf.ui.test.operations.ProjectTestOperations; |
| 28 | +import com.espressif.idf.ui.test.operations.selectors.LaunchBarConfigSelector; |
| 29 | +import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector; |
| 30 | + |
| 31 | +/** |
| 32 | + * Test class to test JTAG Flash Process |
| 33 | + * |
| 34 | + * @author Andrii Filippov |
| 35 | + * |
| 36 | + */ |
| 37 | + |
| 38 | +@SuppressWarnings("restriction") |
| 39 | +@RunWith(SWTBotJunit4ClassRunner.class) |
| 40 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 41 | +public class IDFProjectJTAGFlashTest |
| 42 | +{ |
| 43 | + @BeforeClass |
| 44 | + public static void beforeTestClass() throws Exception |
| 45 | + { |
| 46 | + Fixture.loadEnv(); |
| 47 | + } |
| 48 | + |
| 49 | + @After |
| 50 | + public 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 givenNewProjectCreatedWhenSelectJTAGflashWhenBuiltThenCheckFlashedSuccessfully() throws Exception |
| 64 | + { |
| 65 | + if (SystemUtils.IS_OS_LINUX) //temporary solution until new ESP boards arrive for Windows |
| 66 | + { |
| 67 | + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); |
| 68 | + Fixture.givenProjectNameIs("NewProjectJTAGFlashTest"); |
| 69 | + Fixture.whenNewProjectIsSelected(); |
| 70 | + Fixture.whenSelectJTAGflashInLaunchConfig(); |
| 71 | + Fixture.whenSelectLaunchTargetBoard(); |
| 72 | + Fixture.whenProjectIsBuiltUsingContextMenu(); |
| 73 | + Fixture.whenFlashProject(); |
| 74 | + Fixture.thenVerifyJTAGflashDone(); |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + assertTrue(true); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + private static class Fixture |
| 83 | + { |
| 84 | + private static SWTWorkbenchBot bot; |
| 85 | + private static String category; |
| 86 | + private static String subCategory; |
| 87 | + private static String projectName; |
| 88 | + |
| 89 | + private static void loadEnv() throws Exception |
| 90 | + { |
| 91 | + bot = WorkBenchSWTBot.getBot(); |
| 92 | + EnvSetupOperations.setupEspressifEnv(bot); |
| 93 | + bot.sleep(1000); |
| 94 | + ProjectTestOperations.deleteAllProjects(bot); |
| 95 | + } |
| 96 | + |
| 97 | + private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory) |
| 98 | + { |
| 99 | + Fixture.category = category; |
| 100 | + Fixture.subCategory = subCategory; |
| 101 | + } |
| 102 | + |
| 103 | + private static void givenProjectNameIs(String projectName) |
| 104 | + { |
| 105 | + Fixture.projectName = projectName; |
| 106 | + } |
| 107 | + |
| 108 | + private static void whenNewProjectIsSelected() throws Exception |
| 109 | + { |
| 110 | + ProjectTestOperations.setupProject(projectName, category, subCategory, bot); |
| 111 | + } |
| 112 | + |
| 113 | + private static void whenProjectIsBuiltUsingContextMenu() throws IOException |
| 114 | + { |
| 115 | + ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot); |
| 116 | + ProjectTestOperations.waitForProjectBuild(bot); |
| 117 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); |
| 118 | + } |
| 119 | + |
| 120 | + private static void whenFlashProject() throws IOException |
| 121 | + { |
| 122 | + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations..."); |
| 123 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000); |
| 124 | + bot.tree().getTreeItem("ESP-IDF Application").select(); |
| 125 | + bot.tree().getTreeItem("ESP-IDF Application").expand(); |
| 126 | + bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select(); |
| 127 | + bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); |
| 128 | + bot.button("Run").click(); |
| 129 | + } |
| 130 | + |
| 131 | + private static void whenSelectJTAGflashInLaunchConfig() throws Exception |
| 132 | + { |
| 133 | + LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); |
| 134 | + configSelector.clickEdit(); |
| 135 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000); |
| 136 | + bot.cTabItem("Main").show(); |
| 137 | + bot.cTabItem("Main").setFocus(); |
| 138 | + bot.comboBoxWithLabel("Flash over:").setSelection("JTAG"); |
| 139 | + bot.button("OK").click(); |
| 140 | + } |
| 141 | + |
| 142 | + private static void whenSelectLaunchTargetBoard() throws Exception |
| 143 | + { |
| 144 | + LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); |
| 145 | + targetSelector.clickEdit(); |
| 146 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); |
| 147 | + SWTBotShell shell = bot.shell("New ESP Target"); |
| 148 | + bot.comboBoxWithLabel("Board:").setSelection("ESP32-ETHERNET-KIT [usb://1-10]"); |
| 149 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); |
| 150 | + shell.setFocus(); |
| 151 | + bot.button("Finish").click(); |
| 152 | + } |
| 153 | + |
| 154 | + private static void thenVerifyJTAGflashDone() throws Exception |
| 155 | + { |
| 156 | + ProjectTestOperations.verifyTheConsoleOutput(bot, "** Flashing done for partition_table/partition-table.bin"); |
| 157 | + } |
| 158 | + |
| 159 | + private static void cleanTestEnv() |
| 160 | + { |
| 161 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); |
| 162 | + ProjectTestOperations.closeAllProjects(bot); |
| 163 | + ProjectTestOperations.deleteAllProjects(bot); |
| 164 | + } |
| 165 | + } |
| 166 | +} |
0 commit comments