Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*******************************************************************************
* Copyright 2021 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.ui.test.executable.cases.project;

import java.io.IOException;

import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import static org.eclipse.swtbot.swt.finder.waits.Conditions.*;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.After;
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.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.LaunchBarConfigSelector;
import com.espressif.idf.ui.test.operations.selectors.LaunchBarTargetSelector;

/**
* Test class to test the Flash process
*
* @author Andrii Filippov
*
*/
@SuppressWarnings("restriction")
@RunWith(SWTBotJunit4ClassRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)

public class NewEspressifIDFProjectFlashProcessTest {
@BeforeClass
public static void beforeTestClass() throws Exception
{
Fixture.loadEnv();
}

@After
public void afterEachTest()
{
try
{
Fixture.cleanTestEnv(); // Make sure test environment is always cleaned up
}
catch (Exception e)
{
System.err.println("Error during cleanup: " + e.getMessage());
}
}


@Test
public void givenNewProjectCreatedBuiltWhenSelectSerialPortWhenFlashThenCheckFlashedSuccessfully()
throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectFlashTest");
Fixture.whenNewProjectIsSelected();
Fixture.whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenSelectLaunchTargetSerialPort();
Fixture.whenFlashProject();
Fixture.thenVerifyFlashDoneSuccessfully();
}

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 cleanTestEnv()
{
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
}

private static void whenSelectLaunchTargetSerialPort() throws Exception
{
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
targetSelector.clickEdit();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000);
SWTBotShell shell = bot.shell("New ESP Target");
bot.comboBoxWithLabel("Serial Port:").setSelection("/dev/ttyUSB1 Dual RS232-HS");
TestWidgetWaitUtility.waitForOperationsInProgressToFinishSync(bot);
shell.setFocus();
bot.button("Finish").click();
}

private static void whenTurnOffOpenSerialMonitorAfterFlashingInLaunchConfig() throws Exception
{
LaunchBarConfigSelector configSelector = new LaunchBarConfigSelector(bot);
configSelector.clickEdit();
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Edit Configuration", 20000);
bot.cTabItem("Main").show();
bot.cTabItem("Main").setFocus();
SWTBotCheckBox checkBox = bot.checkBox("Open Serial Monitor After Flashing");
if (checkBox.isChecked()) {
checkBox.click();
}
bot.button("OK").click();
}

private static void whenFlashProject() throws IOException
{
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Run Configurations...");
TestWidgetWaitUtility.waitForDialogToAppear(bot, "Run Configurations", 10000);
bot.tree().getTreeItem("ESP-IDF Application").select();
bot.tree().getTreeItem("ESP-IDF Application").expand();
bot.tree().getTreeItem("ESP-IDF Application").getNode(projectName).select();
bot.waitUntil(widgetIsEnabled(bot.button("Run")), 5000);
bot.button("Run").click();
}

private static void thenVerifyFlashDoneSuccessfully() throws Exception
{
ProjectTestOperations.waitForProjectFlash(bot);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class ProjectTestOperations

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

private static final String DEFAULT_FLASH_WAIT_PROPERTY = "default.project.flash.wait";

private static final Logger logger = LoggerFactory.getLogger(ProjectTestOperations.class);

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

public static void waitForProjectFlash(SWTWorkbenchBot bot) throws IOException
{
SWTBotView view = bot.viewByPartName("Console");
view.setFocus();
TestWidgetWaitUtility.waitUntilViewContains(bot, "Hard resetting via RTS pin...", view,
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_FLASH_WAIT_PROPERTY, 120000));
}

public static void waitForProjectNewComponentInstalled(SWTWorkbenchBot bot) throws IOException
{
SWTBotView consoleView = viewConsole("ESP-IDF Console", bot);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ public void click(int x, int y)
notify(SWT.MouseUp, createMouseEvent(x, y, 1, SWT.BUTTON1, 1));
}

public void clickEdit()
public void clickEdit()
{
click();
bot().buttonWithId(LaunchBarWidgetIds.EDIT).click(); // $NON-NLS-1$
bot().canvasWithId(LaunchBarWidgetIds.EDIT).click(); // $NON-NLS-1$
}

private void clickOnInternalWidget(int x, int y, Widget internalWidget)
Expand Down
Loading