Skip to content

Commit ed7867a

Browse files
ci: implement 'ScrollToBottom' method for better search in Launch Target list. Add A/B/C markers to make sure tests run in correct(needed) order
1 parent c4f6b9b commit ed7867a

File tree

2 files changed

+93
-70
lines changed

2 files changed

+93
-70
lines changed

tests/com.espressif.idf.ui.test/src/com/espressif/idf/ui/test/executable/cases/project/IDFProjectLaunchTargetEditorFunctionalityTest.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void afterEachTest()
5656
}
5757

5858
@Test
59-
public void givenNewProjectCreatedBuiltWhenSelectNewTargetWhenPopUpAppearsThenBuildFolderDeletedSuccessfully()
59+
public void givenANewProjectCreatedBuiltWhenSelectNewTargetWhenPopUpAppearsThenBuildFolderDeletedSuccessfully()
6060
throws Exception
6161
{
6262
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
@@ -69,7 +69,7 @@ public void givenNewProjectCreatedBuiltWhenSelectNewTargetWhenPopUpAppearsThenBu
6969
}
7070

7171
@Test
72-
public void givenNewProjectCreatedWhenCreateNewLaunchTargetThenProjectBuiltSuccessfully()
72+
public void givenBNewProjectCreatedWhenCreateNewLaunchTargetThenProjectBuiltSuccessfully()
7373
throws Exception
7474
{
7575
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
@@ -80,13 +80,13 @@ public void givenNewProjectCreatedWhenCreateNewLaunchTargetThenProjectBuiltSucce
8080
}
8181

8282
@Test
83-
public void givenNewProjectCreatedWhenCreateNewLaunchTargetWhenDeleteCreatedLaunchTargetThenDeletedSuccessfully()
83+
public void givenCNewProjectCreatedWhenDeleteSelectedLaunchTargetThenDeletedSuccessfully()
8484
throws Exception
8585
{
8686
Fixture.givenNewEspressifIDFProjectIsSelected("EspressIf", "Espressif IDF Project");
8787
Fixture.givenProjectNameIs("NewProjectLaunchTargetTest3");
8888
Fixture.whenNewProjectIsSelected();
89-
Fixture.whenDeleteLaunchTarget();
89+
Fixture.whenDeleteSelectedLaunchTarget();
9090
Fixture.thenLaunchTargetDeletedSuccessfully();
9191
}
9292

@@ -138,8 +138,15 @@ private static void whenChangeLaunchTarget() throws Exception
138138
bot.button("Yes").click();
139139
}
140140

141+
private static void whenSelectLaunchTarget() throws Exception
142+
{
143+
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
144+
targetSelector.selectTarget("target");
145+
}
146+
141147
private static void whenDeleteLaunchTarget() throws Exception
142148
{
149+
bot.sleep(500);
143150
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
144151
targetSelector.clickEdit();
145152
TestWidgetWaitUtility.waitForDialogToAppear(bot, "New ESP Target", 20000);
@@ -148,11 +155,17 @@ private static void whenDeleteLaunchTarget() throws Exception
148155
bot.button("Delete").click();
149156
}
150157

158+
private static void whenDeleteSelectedLaunchTarget() throws Exception
159+
{
160+
whenSelectLaunchTarget();
161+
whenDeleteLaunchTarget();
162+
}
163+
151164
private static void thenLaunchTargetDeletedSuccessfully() throws Exception
152165
{
153166
bot.sleep(500);
154167
LaunchBarTargetSelector targetSelector = new LaunchBarTargetSelector(bot);
155-
assertTrue(!targetSelector.isTargetPresent("esp32"));
168+
assertTrue("Launch Target was not deleted successfully!", !targetSelector.isTargetPresent("target"));
156169
}
157170

158171
private static void selectNewLaunchTarget()
@@ -194,7 +207,7 @@ private static void whenRefreshProject() throws IOException
194207

195208
private static void thenBuildFolderDeletedSuccessfully() throws Exception
196209
{
197-
assertTrue(ProjectTestOperations.findProjectFullCleanedFilesInBuildFolder(projectName, bot));
210+
assertTrue("Build folder was not deleted successfully!", ProjectTestOperations.findProjectFullCleanedFilesInBuildFolder(projectName, bot));
198211
}
199212

200213
private static void cleanTestEnv()

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

Lines changed: 74 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
import org.eclipse.swtbot.swt.finder.widgets.AbstractSWTBotControl;
3030
import org.eclipse.swtbot.swt.finder.widgets.SWTBotLabel;
3131
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
32+
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.allOf;
33+
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
34+
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withText;
3235

3336
/**
3437
* Launchbar CDT helper class to select items from launch targets
@@ -103,73 +106,80 @@ public LaunchBarTargetSelector select(String text)
103106

104107
public LaunchBarTargetSelector selectTarget(String text)
105108
{
106-
click();
107-
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
108-
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
109-
int numberOfItemsInScrolledComp = syncExec(
110-
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
111-
Label itemToSelect;
112-
113-
// Set the text in the not visible text field
114-
// when the target list is too big, swtbot cannot select a target label, so we filter the list
115-
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
116-
{
117-
swtBotShell.bot().text().setText(text);
118-
itemToSelect = swtBotShell.bot().label(0).widget;
119-
}
120-
else
121-
{
122-
itemToSelect = swtBotShell.bot().widget(withText(text));
123-
}
124-
125-
Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
126-
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
127-
return this;
109+
click();
110+
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
111+
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
112+
int numberOfItemsInScrolledComp = syncExec(
113+
() -> ((Composite) scrolledComposite.getChildren()[0]).getChildren().length);
114+
Label itemToSelect;
115+
116+
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
117+
{
118+
swtBotShell.bot().text().setText(text);
119+
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
120+
}
121+
else
122+
{
123+
itemToSelect = swtBotShell.bot().widget(allOf(widgetOfType(Label.class), withText(text)));
124+
}
125+
126+
Point itemToSelectLocation = syncExec((Result<Point>) itemToSelect::getLocation);
127+
clickOnInternalWidget(itemToSelectLocation.x, itemToSelectLocation.y, itemToSelect);
128+
return this;
128129
}
129130

130-
public boolean isTargetPresent(String text)
131+
public void scrollToBottom(ScrolledComposite scrolledComposite)
131132
{
132-
click();
133+
syncExec(() -> {
134+
scrolledComposite.setOrigin(0, scrolledComposite.getClientArea().height);
135+
});
136+
}
133137

134-
try
135-
{
136-
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
137-
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
138-
139-
int numberOfItemsInScrolledComp = syncExec(() ->
140-
((Composite) scrolledComposite.getChildren()[0]).getChildren().length
141-
);
142-
143-
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
144-
{
145-
swtBotShell.bot().text().setText(text);
146-
147-
List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class));
148-
for (Widget widget : labels)
149-
{
150-
String labelText = syncExec(() -> ((Label) widget).getText());
151-
if (labelText.equals(text))
152-
{
153-
return true;
154-
}
155-
}
156-
return false;
157-
}
158-
else
159-
{
160-
Widget itemToCheck = swtBotShell.bot().widget(withText(text));
161-
String labelText = syncExec(() -> ((Label) itemToCheck).getText());
162-
return labelText.equals(text);
163-
}
164-
}
165-
catch (WidgetNotFoundException e)
166-
{
167-
return false;
168-
}
169-
catch (Exception e)
170-
{
171-
e.printStackTrace();
172-
return false;
173-
}
138+
public boolean isTargetPresent(String text)
139+
{
140+
click();
141+
142+
try
143+
{
144+
SWTBotShell swtBotShell = bot().shellWithId(LaunchBarWidgetIds.POPUP);
145+
ScrolledComposite scrolledComposite = swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class));
146+
147+
int numberOfItemsInScrolledComp = syncExec(() ->
148+
((Composite) scrolledComposite.getChildren()[0]).getChildren().length
149+
);
150+
151+
// Scroll to the bottom if there are many items
152+
if (numberOfItemsInScrolledComp > NUM_FOR_FILTER_POPUP)
153+
{
154+
scrollToBottom(swtBotShell.bot().widget(widgetOfType(ScrolledComposite.class)));
155+
swtBotShell.bot().text().setText(text);
156+
157+
List<? extends Widget> labels = swtBotShell.bot().widgets(widgetOfType(Label.class));
158+
for (Widget widget : labels)
159+
{
160+
String labelText = syncExec(() -> ((Label) widget).getText());
161+
if (labelText.equals(text))
162+
{
163+
return true;
164+
}
165+
}
166+
return false;
167+
}
168+
else
169+
{
170+
Widget itemToCheck = swtBotShell.bot().widget(withText(text));
171+
String labelText = syncExec(() -> ((Label) itemToCheck).getText());
172+
return labelText.equals(text);
173+
}
174+
}
175+
catch (WidgetNotFoundException e)
176+
{
177+
return false;
178+
}
179+
catch (Exception e)
180+
{
181+
e.printStackTrace();
182+
return false;
183+
}
174184
}
175185
}

0 commit comments

Comments
 (0)