|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright 2021 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 java.io.IOException; |
| 8 | + |
| 9 | +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
| 10 | +import static org.eclipse.swtbot.swt.finder.waits.Conditions.*; |
| 11 | +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
| 12 | +import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; |
| 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 com.espressif.idf.ui.test.common.utility.TestWidgetWaitUtility; |
| 23 | +import com.espressif.idf.ui.test.operations.EnvSetupOperations; |
| 24 | +import com.espressif.idf.ui.test.operations.ProjectTestOperations; |
| 25 | +import com.espressif.idf.ui.test.operations.selectors.LaunchBarConfigSelector; |
| 26 | +import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector; |
| 27 | + |
| 28 | +/** |
| 29 | + * Test class to test the Flash process |
| 30 | + * |
| 31 | + * @author Andrii Filippov |
| 32 | + * |
| 33 | + */ |
| 34 | +@SuppressWarnings("restriction") |
| 35 | +@RunWith(SWTBotJunit4ClassRunner.class) |
| 36 | +@FixMethodOrder(MethodSorters.NAME_ASCENDING) |
| 37 | + |
| 38 | +public class NewEspressifIDFProjectFlashProcessTest { |
| 39 | + @BeforeClass |
| 40 | + public static void beforeTestClass() throws Exception |
| 41 | + { |
| 42 | + Fixture.loadEnv(); |
| 43 | + } |
| 44 | + |
| 45 | + @After |
| 46 | + public void afterEachTest() |
| 47 | + { |
| 48 | + try |
| 49 | + { |
| 50 | + Fixture.cleanTestEnv(); // Make sure test environment is always cleaned up |
| 51 | + } |
| 52 | + catch (Exception e) |
| 53 | + { |
| 54 | + System.err.println("Error during cleanup: " + e.getMessage()); |
| 55 | + } |
| 56 | + } |
| 57 | + |
| 58 | + |
| 59 | + @Test |
| 60 | + public void givenNewProjectCreatedBuiltWhenSelectSerialPortWhenFlashThenCheckFlashedSuccessfully() |
| 61 | + throws Exception |
| 62 | + { |
| 63 | + Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); |
| 64 | + Fixture.givenProjectNameIs("NewProjectFlashTest"); |
| 65 | + Fixture.whenNewProjectIsSelected(); |
| 66 | + Fixture.whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig(); |
| 67 | + Fixture.whenProjectIsBuiltUsingContextMenu(); |
| 68 | + Fixture.whenSelectLaunchTargetSerialPort(); |
| 69 | + Fixture.whenFlashProject(); |
| 70 | + Fixture.thenVerifyFlashDoneSuccessfully(); |
| 71 | + } |
| 72 | + |
| 73 | + private static class Fixture |
| 74 | + { |
| 75 | + private static SWTWorkbenchBot bot; |
| 76 | + private static String category; |
| 77 | + private static String subCategory; |
| 78 | + private static String projectName; |
| 79 | + |
| 80 | + private static void loadEnv() throws Exception |
| 81 | + { |
| 82 | + bot = WorkBenchSWTBot.getBot(); |
| 83 | + EnvSetupOperations.setupEspressifEnv(bot); |
| 84 | + bot.sleep(1000); |
| 85 | + ProjectTestOperations.deleteAllProjects(bot); |
| 86 | + } |
| 87 | + |
| 88 | + private static void givenNewEspressifIDFProjectIsSelected(String category, String subCategory) |
| 89 | + { |
| 90 | + Fixture.category = category; |
| 91 | + Fixture.subCategory = subCategory; |
| 92 | + } |
| 93 | + |
| 94 | + private static void givenProjectNameIs(String projectName) |
| 95 | + { |
| 96 | + Fixture.projectName = projectName; |
| 97 | + } |
| 98 | + |
| 99 | + private static void whenNewProjectIsSelected() throws Exception |
| 100 | + { |
| 101 | + ProjectTestOperations.setupProject(projectName, category, subCategory, bot); |
| 102 | + } |
| 103 | + |
| 104 | + private static void whenProjectIsBuiltUsingContextMenu() throws IOException |
| 105 | + { |
| 106 | + ProjectTestOperations.buildProjectUsingContextMenu(projectName, bot); |
| 107 | + ProjectTestOperations.waitForProjectBuild(bot); |
| 108 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); |
| 109 | + } |
| 110 | + |
| 111 | + private static void cleanTestEnv() |
| 112 | + { |
| 113 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); |
| 114 | + ProjectTestOperations.closeAllProjects(bot); |
| 115 | + ProjectTestOperations.deleteAllProjects(bot); |
| 116 | + } |
| 117 | + |
| 118 | + private static void whenSelectLaunchTargetSerialPort() throws Exception |
| 119 | + { |
| 120 | + LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot); |
| 121 | + targetSelector.clickEdit(); |
| 122 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000); |
| 123 | + SWTBotShell shell = bot.shell("New ESP Target"); |
| 124 | + bot.comboBoxWithLabel("Serial Port:").setSelection("/dev/ttyUSB1 Dual RS232-HS"); |
| 125 | + TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot); |
| 126 | + shell.setFocus(); |
| 127 | + bot.button("Finish").click(); |
| 128 | + } |
| 129 | + |
| 130 | + private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception |
| 131 | + { |
| 132 | + LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot); |
| 133 | + configSelector.clickEdit(); |
| 134 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000); |
| 135 | + bot.cTabItem("Main").show(); |
| 136 | + bot.cTabItem("Main").setFocus(); |
| 137 | + SWTBotCheckBox checkBox = bot.checkBox("Open Serial Monitor After Flashing"); |
| 138 | + if (checkBox.isChecked()) { |
| 139 | + checkBox.click(); |
| 140 | + } |
| 141 | + bot.button("OK").click(); |
| 142 | + } |
| 143 | + |
| 144 | + private static void whenFlashProject() throws IOException |
| 145 | + { |
| 146 | + ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations..."); |
| 147 | + TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000); |
| 148 | + bot.tree().getTreeItem("ESP-IDF Application").select(); |
| 149 | + bot.tree().getTreeItem("ESP-IDF Application").expand(); |
| 150 | + bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select(); |
| 151 | + bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000); |
| 152 | + bot.button("Run").click(); |
| 153 | + } |
| 154 | + |
| 155 | + private static void thenVerifyFlashDoneSuccessfully() throws Exception |
| 156 | + { |
| 157 | + ProjectTestOperations.waitForProjectFlash(bot); |
| 158 | + } |
| 159 | + } |
| 160 | +} |
0 commit comments