Skip to content

Commit

Permalink
Merge pull request #833 from espressif/IEP-1038
Browse files Browse the repository at this point in the history
SWTBot: 'ESP-IDF Install New Component' test case
  • Loading branch information
AndriiFilippov authored Oct 19, 2023
2 parents 516a51e + ff55c58 commit f3598d0
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@ public void givenNewProjectCreatedDfuBuiltThenHasDfuBin() throws Exception
Fixture.thenProjectHasTheFile("dfu.bin", "/build");
Fixture.turnOffDfu();
}

@Test
public void givenNewProjectCreatedThenInstallNewComponent() throws Exception
{
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
Fixture.givenProjectNameIs("NewProjectTest");
Fixture.whenNewProjectIsSelected();
Fixture.whenProjectIsBuiltUsingContextMenu();
Fixture.whenInstallNewComponentUsingContextMenu();
Fixture.checkIfNewComponentIsInstalledUsingContextMenu();
}

private static class Fixture
{
Expand Down Expand Up @@ -284,6 +295,22 @@ private static void whenProjectIsBuiltUsingContextMenu() throws IOException
ProjectTestOperations.waitForProjectBuild(bot);
TestWidgetWaitUtility.waitForOperationsInProgressToFinish(bot);
}

private static void whenInstallNewComponentUsingContextMenu() throws IOException
{
ProjectTestOperations.openProjectNewComponentUsingContextMenu(projectName, bot);
bot.editorByTitle(projectName).show();
bot.button("Install").click();
ProjectTestOperations.waitForProjectNewComponentInstalled(bot);
bot.editorByTitle(projectName).close();
ProjectTestOperations.refreshProjectUsingContextMenu(projectName, bot);
}

private static void checkIfNewComponentIsInstalledUsingContextMenu() throws IOException
{
ProjectTestOperations.openProjectComponentYMLFileInTextEditorUsingContextMenu(projectName, bot);
ProjectTestOperations.checkTextEditorContentForPhrase("espressif/mdns", bot);
}

private static void thenAllConfigurationsAreDeleted()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
Expand Down Expand Up @@ -60,7 +61,16 @@ public static void waitForProjectBuild(SWTWorkbenchBot bot) throws IOException
consoleView.show();
consoleView.setFocus();
TestWidgetWaitUtility.waitUntilViewContains(bot, "Build complete", consoleView,
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 60000));
DefaultPropertyFetcher.getLongPropertyValue(DEFAULT_PROJECT_BUILD_WAIT_PROPERTY, 600000));
}

public static void waitForProjectNewComponentInstalled(SWTWorkbenchBot bot) throws IOException
{
SWTBotView consoleView = viewConsole("ESP-IDF Console", bot);
consoleView.show();
consoleView.setFocus();
TestWidgetWaitUtility.waitUntilViewContains(bot, "Successfully added dependency", consoleView,
DefaultPropertyFetcher.getLongPropertyValue("Install New Component", 10000));
}

public static SWTBotView viewConsole(String consoleType, SWTWorkbenchBot bot)
Expand Down Expand Up @@ -89,6 +99,78 @@ public static void createDebugConfiguration(String projectName, SWTWorkbenchBot
}

}

public static void refreshProjectUsingContextMenu(String projectName, SWTWorkbenchBot bot)
{
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
if (projectItem != null)
{
projectItem.select();
projectItem.contextMenu("Refresh").click();
}
}

public static void openProjectComponentYMLFileInTextEditorUsingContextMenu(String projectName, SWTWorkbenchBot bot)
{
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
if (projectItem != null) {
projectItem.select();
projectItem.expand();
projectItem.getNode("main").expand();

int maxAttempts = 2;
for (int attempt = 0; attempt <= maxAttempts; attempt++) {
SWTBotTreeItem fileToOpenItem = findTreeItem(projectItem.getNode("main"), "idf_component.yml");

if (fileToOpenItem != null) {
fileToOpenItem.select();
fileToOpenItem.doubleClick();
return;
}

else {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
throw new RuntimeException("The 'idf_component.yml' file was not found in the 'main' subfolder.");
}
}

private static SWTBotTreeItem findTreeItem(SWTBotTreeItem parent, String itemName) {
for (SWTBotTreeItem child : parent.getItems()) {
if (child.getText().equals(itemName)) {
return child;
}
SWTBotTreeItem found = findTreeItem(child, itemName);
if (found != null) {
return found;
}
}
return null;
}

public static void checkTextEditorContentForPhrase(String phrase, SWTWorkbenchBot bot) {
SWTBotEditor textEditor = bot.activeEditor();
String editorText = textEditor.toTextEditor().getText();

if (!editorText.contains(phrase)) {
throw new RuntimeException("The specified phrase '" + phrase + "' was not found in the text editor.");
}
}

public static void openProjectNewComponentUsingContextMenu(String projectName, SWTWorkbenchBot bot)
{
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot);
if (projectItem != null)
{
projectItem.select();
projectItem.contextMenu("ESP-IDF: Install New Component").click();
}
}

/**
* Creates an espressif idf project from the template
Expand Down

0 comments on commit f3598d0

Please sign in to comment.