Skip to content

Commit 6f62d42

Browse files
SWTBot test case: Flash Process verification (#1299)
* ci: add first Flash process test
1 parent 693c10c commit 6f62d42

File tree

3 files changed

+172
-3
lines changed

3 files changed

+172
-3
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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+
}

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/ProjectTestOperations.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ public class ProjectTestOperations
5353

5454
private static final String DEFAULT_PROJECT_BUILD_WAIT_PROPERTY = "default.project.build.wait";
5555

56+
private static final String DEFAULT_FLASH_WAIT_PROPERTY = "default.project.flash.wait";
57+
5658
private static final Logger logger = LoggerFactory.getLogger(ProjectTestOperations.class);
5759

5860
private static final int DELETE_PROJECT_TIMEOUT = 240000;
@@ -90,6 +92,14 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException
9092
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 300000));
9193
}
9294

95+
public static void waitForProjectFlash(SWTWorkbenchBot bot) throws IOException
96+
{
97+
SWTBotView view = bot.viewByPartName("Console");
98+
view.setFocus();
99+
TestWidgetWaitUtility.waitUntilViewContains(bot, "Hard resetting via RTS pin...", view,
100+
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_FLASH_WAIT_PROPERTY, 120000));
101+
}
102+
93103
public static void waitForProjectNewComponentInstalled(SWTWorkbenchBot bot) throws IOException
94104
{
95105
SWTBotView consoleView = viewConsole("ESP-IDF Console", bot);

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/operations/selectors/LaunchBarTargetSelector.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ public void click(int x, int y)
6868
notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
6969
}
7070

71-
public void clickEdit()
71+
public void clickEdit()
7272
{
73-
click();
74-
bot().buttonWithId(LaunchBarWidgetIds.EDIT).click(); // $NON-NLS-1$
73+
bot().canvasWithId(LaunchBarWidgetIds.EDIT).click(); // $NON-NLS-1$
7574
}
7675

7776
private void clickOnInternalWidget(int x, int y, Widget internalWidget)

0 commit comments

Comments
 (0)