-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SWTBot test case: Partition Table Editor #1012
base: master
Are you sure you want to change the base?
Changes from all commits
396c15b
2acabf6
c070833
622f45b
72ca9ac
311374a
4e33063
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
/******************************************************************************* | ||
* 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 static org.junit.Assert.assertTrue; | ||
|
||
import java.io.IOException; | ||
|
||
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; | ||
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | ||
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; | ||
|
||
/** | ||
* Test class to test the SBOM feature | ||
* | ||
* @author Andrii Filippov | ||
* | ||
*/ | ||
@SuppressWarnings("restriction") | ||
@RunWith(SWTBotJunit4ClassRunner.class) | ||
@FixMethodOrder(MethodSorters.NAME_ASCENDING) | ||
public class NewEspressifIDFProjectPartitionTableEditorTest | ||
{ | ||
@BeforeClass | ||
public static void beforeTestClass() throws Exception | ||
{ | ||
Fixture.loadEnv(); | ||
} | ||
|
||
@After | ||
public void afterEachTest() | ||
{ | ||
Fixture.cleanTestEnv(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedNotBuiltWhenOpenPartitionTableEditorThenInformationPopUpMessage() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor1Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.ThenInformationMessagePopUp(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorThenBuiltInPartitionTableDisplayed() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor2Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.ThenBuiltInPartitionTableDisplayed(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenAddRowThenCheckRowAdded() throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor3Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenAddRowToPartitionTable(); | ||
Fixture.ThenCheckRowAdded(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowThenCheckRowDeleted() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor4Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.ThenCheckRowDeleted(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndQuitwhenReopenPartitionTableThenCheckChangesSaved() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor5Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.whenSaveAndQuit(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.thenCheckChangesSaved(); | ||
} | ||
|
||
@Test | ||
public void givenNewProjectCreatedBuiltWhenOpenPartitionTableEditorWhenDeleteSelectedRowWhenSaveAndCancelwhenReopenPartitionTableThenCheckChangesSaved() | ||
throws Exception | ||
{ | ||
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project"); | ||
Fixture.givenProjectNameIs("NewProjectPartitionTableEditor6Test"); | ||
Fixture.whenNewProjectIsSelected(); | ||
Fixture.whenProjectIsBuiltUsingContextMenu(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.whenDeleteRowFromPartitionTable(); | ||
Fixture.whenSavePartitionTable(); | ||
Fixture.whenCancel(); | ||
Fixture.whenOpenPartitionTableEditor(); | ||
Fixture.thenCheckChangesSaved(); | ||
} | ||
|
||
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); | ||
} | ||
|
||
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 whenOpenPartitionTableEditor() throws IOException | ||
{ | ||
ProjectTestOperations.launchCommandUsingContextMenu(projectName, bot, "Partition Table Editor"); | ||
} | ||
|
||
private static void ThenInformationMessagePopUp() throws IOException | ||
{ | ||
assertTrue(ProjectTestOperations.checkShellContent(bot, "Information", | ||
"Failed to get partition CSV file name from sdkconfig. Make sure your project is compiled and has sdkconfig.")); | ||
} | ||
|
||
private static void ThenBuiltInPartitionTableDisplayed() throws IOException | ||
{ | ||
assertTrue(ProjectTestOperations.checkPartitionTableContent(bot)); | ||
} | ||
|
||
private static void whenAddRowToPartitionTable() throws IOException | ||
{ | ||
bot.toolbarButton("Add Row").click(); | ||
} | ||
|
||
private static void ThenCheckRowAdded() throws IOException | ||
{ | ||
assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, 1)); | ||
} | ||
|
||
private static void whenDeleteRowFromPartitionTable() throws IOException | ||
{ | ||
ProjectTestOperations.deletePartitionTableRow(bot); | ||
} | ||
|
||
private static void ThenCheckRowDeleted() throws IOException | ||
{ | ||
assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, -1)); | ||
} | ||
|
||
private static void whenSaveAndQuit() throws IOException | ||
{ | ||
bot.button("Save and Quit").click(); | ||
bot.button("OK").click(); | ||
} | ||
|
||
private static void whenSavePartitionTable() throws IOException | ||
{ | ||
bot.toolbarButton("Save").click(); | ||
bot.button("OK").click(); | ||
} | ||
|
||
private static void whenCancel() throws IOException | ||
{ | ||
bot.button("Cancel").click(); | ||
} | ||
|
||
private static void thenCheckChangesSaved() throws IOException | ||
{ | ||
assertTrue(ProjectTestOperations.comparePartitionTableRows(bot, -1)); | ||
} | ||
|
||
private static void cleanTestEnv() | ||
{ | ||
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot); | ||
ProjectTestOperations.closeAllProjects(bot); | ||
ProjectTestOperations.deleteAllProjects(bot); | ||
} | ||
Comment on lines
+221
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle potential exceptions within the method. The private static void cleanTestEnv() {
try {
TestWidgetWaitUtility.waitForOperationsInProgressToFinishAsync(bot);
ProjectTestOperations.closeAllProjects(bot);
ProjectTestOperations.deleteAllProjects(bot);
} catch (Exception e) {
// Log the exception and proceed with cleanup
e.printStackTrace();
}
} |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,8 +24,10 @@ | |
import org.eclipse.swtbot.swt.finder.waits.DefaultCondition; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarDropDownButton; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | ||
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | ||
|
@@ -247,16 +249,6 @@ public static boolean checkTextEditorContentForPhrase(String phrase, SWTWorkbenc | |
return editorText.contains(phrase); | ||
} | ||
|
||
public static void openProjectNewComponentUsingContextMenu(String projectName, SWTWorkbenchBot bot) | ||
{ | ||
SWTBotTreeItem projectItem = fetchProjectFromProjectExplorer(projectName, bot); | ||
if (projectItem != null) | ||
{ | ||
projectItem.select(); | ||
projectItem.contextMenu("Install New Component").click(); | ||
} | ||
} | ||
|
||
/** | ||
* Creates an espressif idf project from the template | ||
* | ||
|
@@ -586,6 +578,59 @@ public static void findInConsole(SWTWorkbenchBot bot, String consoleName, String | |
TestWidgetWaitUtility.waitUntilViewContains(bot, findText, consoleView, 3000); | ||
} | ||
|
||
public static boolean checkShellContent(SWTWorkbenchBot bot, String shellName, String expectedText) | ||
{ | ||
SWTBotShell shell = bot.shell(shellName); | ||
shell.activate(); | ||
SWTBotLabel label = bot.label(expectedText); | ||
String actualText = label.getText(); | ||
return expectedText.equals(actualText); | ||
} | ||
Comment on lines
+581
to
+588
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good! Consider a minor refactoring. The new As a minor improvement, consider extracting the label text comparison logic to a separate private method, something like: private static boolean isLabelTextMatching(SWTBotLabel label, String expectedText) {
return expectedText.equals(label.getText());
} And then use it in return isLabelTextMatching(label, expectedText); This would improve readability and reusability of the text comparison logic. |
||
|
||
public static boolean checkPartitionTableContent(SWTWorkbenchBot bot) | ||
{ | ||
String[] builtInPartitionArray = { "nvs", "phy_init", "factory", "data", "data", "app", "nvs", "phy", "factory", | ||
"0x9000", "0xf000", "0x10000", "0x6000", "0x1000", "1M", "", "", "" }; | ||
int builtInIndex = 0; | ||
SWTBotTable table = bot.table(); | ||
int columns = table.columnCount(); | ||
int rows = table.rowCount(); | ||
if (columns != 6 && rows != 3) | ||
{ | ||
return false; | ||
} | ||
for (int col = 0; col < columns; col++) | ||
{ | ||
for (int row = 0; row < rows; row++) | ||
{ | ||
String tableContent = table.cell(row, col); | ||
|
||
if (!builtInPartitionArray[builtInIndex].equals(tableContent)) | ||
{ | ||
return false; | ||
} | ||
builtInIndex++; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public static boolean comparePartitionTableRows(SWTWorkbenchBot bot, int expectedDifference) throws IOException | ||
{ | ||
SWTBotTable table = bot.table(); | ||
int defaultRows = 3; | ||
int actualRows = table.rowCount(); | ||
return (actualRows - defaultRows) == expectedDifference; | ||
} | ||
|
||
public static void deletePartitionTableRow(SWTWorkbenchBot bot) throws IOException | ||
{ | ||
SWTBotTable table = bot.table(); | ||
table.select(1); | ||
bot.toolbarButton("Delete Selected").click(); | ||
bot.button("OK").click(); | ||
} | ||
|
||
public static void joinJobByName(String jobName) | ||
{ | ||
Job[] jobs = Job.getJobManager().find(null); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential exceptions within the method.
The
afterEachTest
method currently does not handle potential exceptions. Consider adding exception handling to ensure the test environment is cleaned up properly even if an error occurs.