Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2016-05-30 05:52:00 +0000
committerMatthias Sohn2016-05-30 09:03:52 +0000
commit75a97ff82ac6f1c95eaac6f59a87ed022a1902f7 (patch)
tree46f5ae7c0680429226d6241f27112879ceb586a1
parentcfeb6e18377bd8a7779b4be838fd640dd2966397 (diff)
downloadegit-75a97ff82ac6f1c95eaac6f59a87ed022a1902f7.tar.gz
egit-75a97ff82ac6f1c95eaac6f59a87ed022a1902f7.tar.xz
egit-75a97ff82ac6f1c95eaac6f59a87ed022a1902f7.zip
Test stability: wait for specific child node after expansion
The first test in GlobalConfigurationPageTest frequently fails on Hudson because it doesn't find the child node "Configuration". It appears that child nodes in the preference page's tree are added one after another, so waiting until there is any child is not good enough: "Configuration" is the second child and might not have appeared yet. Change-Id: Ic5690b481b111fe98aa6d8da1108d5ee462c6e1a Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java6
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java42
2 files changed, 45 insertions, 3 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
index 895a92966d..41fee09def 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java
@@ -74,9 +74,9 @@ public class GlobalConfigurationPageTest {
private void getGitConfigurationPreferencePage() {
preferencePage = new Eclipse().openPreferencePage(preferencePage);
SWTBotTreeItem team = preferencePage.bot().tree().getTreeItem("Team");
- team = TestUtil.expandAndWait(team)
- .getNode(util.getPluginLocalizedValue("GitPreferences_name"));
- team = TestUtil.expandAndWait(team).getNode(
+ team = TestUtil.expandAndWaitFor(team,
+ util.getPluginLocalizedValue("GitPreferences_name"));
+ team = TestUtil.expandAndWaitFor(team,
util.getPluginLocalizedValue("ConfigurationPage.name"));
team.select();
}
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
index 16520a3a49..555b9788db 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/TestUtil.java
@@ -603,6 +603,48 @@ public class TestUtil {
}
/**
+ * Expand a node and wait until it is expanded and has a child node with the
+ * given name. Use only if the node is expected to have children.
+ *
+ * @param treeItem
+ * to expand
+ * @param childName
+ * to wait for
+ * @return the child node
+ */
+ public static SWTBotTreeItem expandAndWaitFor(final SWTBotTreeItem treeItem,
+ final String childName) {
+ final String text = treeItem.getText();
+ final SWTBotTreeItem[] result = { null };
+ treeItem.expand();
+ new SWTBot().waitUntil(new DefaultCondition() {
+
+ @Override
+ public boolean test() {
+ if (treeItem.widget.isDisposed()) {
+ return true; // Stop waiting and report failure below.
+ }
+ try {
+ result[0] = treeItem.getNode(childName);
+ return true;
+ } catch (WidgetNotFoundException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return "Child " + childName + " not found under " + text;
+ }
+ });
+ if (treeItem.widget.isDisposed()) {
+ fail("Widget disposed while waiting for child node " + text + '.'
+ + childName);
+ }
+ return result[0];
+ }
+
+ /**
* Navigates in the given tree to the node denoted by the labels in the
* path, using {@link #getNode(SWTBotTreeItem[], String)} to find children.
*

Back to the top