Author: ppitonak(a)redhat.com
Date: 2009-09-15 07:32:11 -0400 (Tue, 15 Sep 2009)
New Revision: 15573
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dropDownMenu/HorizontalMenuTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/fileUpload/FileUploadTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/paint2d/Paint2DTestCase.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/progressBar/ProgressBarTestCase.java
Log:
* test cases refactored to provide more stable results
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dropDownMenu/HorizontalMenuTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dropDownMenu/HorizontalMenuTestCase.java 2009-09-15
10:28:18 UTC (rev 15572)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/dropDownMenu/HorizontalMenuTestCase.java 2009-09-15
11:32:11 UTC (rev 15573)
@@ -27,6 +27,8 @@
import static org.testng.Assert.assertTrue;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
+import org.jboss.test.selenium.waiting.Condition;
+import org.jboss.test.selenium.waiting.Wait;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -71,10 +73,12 @@
@Test
public void testMenuItem() {
selenium.click(LOC_FIRST_MENU_NEW);
- waitFor(400);
- String text = selenium.getText(LOC_FIRST_CURRENT_SELECTION);
- assertEquals(text, MSG_FIRST_CURRENT_SELECTION_NEW, "Text shown in current
selection.");
+ Wait.failWith("Text shown in current selection.").until(new Condition()
{
+ public boolean isTrue() {
+ return
MSG_FIRST_CURRENT_SELECTION_NEW.equals(selenium.getText(LOC_FIRST_CURRENT_SELECTION));
+ }
+ });
}
/**
@@ -83,10 +87,12 @@
@Test
public void testMenuGroup() {
selenium.click(LOC_FIRST_MENU_SAVE_ALL);
- waitFor(400);
- String text = selenium.getText(LOC_FIRST_CURRENT_SELECTION);
- assertEquals(text, MSG_FIRST_CURRENT_SELECTION_SAVE_ALL, "Text shown in
'Current Selection:'");
+ Wait.failWith("Text shown in current Selection.").until(new Condition()
{
+ public boolean isTrue() {
+ return
MSG_FIRST_CURRENT_SELECTION_SAVE_ALL.equals(selenium.getText(LOC_FIRST_CURRENT_SELECTION));
+ }
+ });
}
/**
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/fileUpload/FileUploadTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/fileUpload/FileUploadTestCase.java 2009-09-15
10:28:18 UTC (rev 15572)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/fileUpload/FileUploadTestCase.java 2009-09-15
11:32:11 UTC (rev 15573)
@@ -303,7 +303,12 @@
selenium.attachFile(format(LOC_ADD_BUTTON_N, 2), "file://" +
FILE_BIG);
selenium.click(LOC_UPLOAD_BUTTON);
- waitFor(2000);
+
+ Wait.failWith(MSG_RIGHT_PANEL_NUMBER_OF_ITEMS).until(new Condition() {
+ public boolean isTrue() {
+ return selenium.getXpathCount(LOC_UPLOADED_LIST_TR).intValue() == 1;
+ }
+ });
String text = selenium.getText(format(LOC_NOT_UPLOADED_LIST_N_NAME, 1));
assertEquals(text, "selenium-test" + Color.YELLOW.getRGB() +
".jpg", format(MSG_LEFT_PANEL_NAME_N, 1));
@@ -319,9 +324,6 @@
assertEquals(text, "Done", format(MSG_LEFT_PANEL_DONE_N, 2));
text = selenium.getText(format(LOC_NOT_UPLOADED_LIST_N_DONE, 2));
assertEquals(text, "File size restricted",
format(MSG_LEFT_PANEL_DONE_N, 2));
-
- int count = selenium.getXpathCount(LOC_UPLOADED_LIST_TR).intValue();
- assertEquals(count, 1, MSG_RIGHT_PANEL_NUMBER_OF_ITEMS);
}
/**
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/paint2d/Paint2DTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/paint2d/Paint2DTestCase.java 2009-09-15
10:28:18 UTC (rev 15572)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/paint2d/Paint2DTestCase.java 2009-09-15
11:32:11 UTC (rev 15573)
@@ -29,6 +29,8 @@
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
import org.jboss.test.selenium.utils.URLUtils;
+import org.jboss.test.selenium.waiting.Condition;
+import org.jboss.test.selenium.waiting.Wait;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -98,7 +100,7 @@
int position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_INITIAL_STATE_SHADOW_SLIDER_HANDLE, "Size of the
shadow.");
- assertImageHash(MSG_INITIAL_STATE_HASH);
+ assertEquals(getImageHash(), MSG_INITIAL_STATE_HASH, "Hash of the
image.");
}
/**
@@ -108,13 +110,22 @@
public void testChangeText() {
selenium.type(LOC_INPUT_TEXT, "XoXoXoXoX");
selenium.typeKeys(LOC_INPUT_TEXT, " "); // why is this necessary?
- waitFor(1500);
- assertImageHash(MSG_CHANGE_TEXT_HASH_1);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_TEXT_HASH_1);
+ }
+ });
+
selenium.type(LOC_INPUT_TEXT, "Red Hat");
selenium.typeKeys(LOC_INPUT_TEXT, " "); // why is this necessary?
- waitFor(1500);
- assertImageHash(MSG_CHANGE_TEXT_HASH_2);
+
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_TEXT_HASH_2);
+ }
+ });
+
}
/**
@@ -124,15 +135,21 @@
public void testChangeColor() {
selenium.type(LOC_INPUT_COLOR, "fbff00");
selenium.click(LOC_BUTTON_APPLY_COLOR);
+
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_COLOR_HASH_1);
+ }
+ });
- waitFor(1500);
- assertImageHash(MSG_CHANGE_COLOR_HASH_1);
-
selenium.type(LOC_INPUT_COLOR, "00ffbb");
selenium.click(LOC_BUTTON_APPLY_COLOR);
-
- waitFor(1500);
- assertImageHash(MSG_CHANGE_COLOR_HASH_2);
+
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_COLOR_HASH_2);
+ }
+ });
}
/**
@@ -145,24 +162,33 @@
int position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_SHADOW_SLIDER_HANDLE_1, "Position of the
slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_SHADOW_HASH_1);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_SHADOW_HASH_1);
+ }
+ });
selenium.mouseDownAt(LOC_SHADOW_SLIDER, "96,0");
selenium.mouseUp(LOC_SHADOW_SLIDER);
position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_SHADOW_SLIDER_HANDLE_2, "Position of the
slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_SHADOW_HASH_2);
-
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_SHADOW_HASH_2);
+ }
+ });
+
selenium.mouseDownAt(LOC_SHADOW_SLIDER, "191,0");
selenium.mouseUp(LOC_SHADOW_SLIDER);
position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_SHADOW_SLIDER_HANDLE_3, "Position of the
slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_SHADOW_HASH_3);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_SHADOW_HASH_3);
+ }
+ });
}
/**
@@ -175,8 +201,11 @@
selenium.type(LOC_INPUT_COLOR, "894bd6");
selenium.click(LOC_BUTTON_APPLY_COLOR);
- waitFor(1500);
- assertImageHash(MSG_CHANGE_TEXT_AND_COLOR_HASH);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_TEXT_AND_COLOR_HASH);
+ }
+ });
}
/**
@@ -191,8 +220,11 @@
int position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_TEXT_AND_SHADOW_SLIDER_HANDLE, "Position
of the slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_TEXT_AND_SHADOW_HASH);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_TEXT_AND_SHADOW_HASH);
+ }
+ });
}
/**
@@ -208,8 +240,11 @@
int position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_COLOR_AND_SHADOW_SLIDER_HANDLE, "Position
of the slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_COLOR_AND_SHADOW_HASH);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_COLOR_AND_SHADOW_HASH);
+ }
+ });
}
/**
@@ -227,8 +262,11 @@
int position = Integer.parseInt(getStyle(LOC_SHADOW_SLIDER_HANDLE,
"left").replace("px", ""));
assertEquals(position, MSG_CHANGE_ALL_SLIDER_HANDLE, "Position of the
slider's handle.");
- waitFor(1500);
- assertImageHash(MSG_CHANGE_ALL_HASH);
+ Wait.failWith("Hash of the image.").until(new Condition() {
+ public boolean isTrue() {
+ return getImageHash().equals(MSG_CHANGE_ALL_HASH);
+ }
+ });
}
/**
@@ -271,28 +309,25 @@
abstractTestSource(1, "View PaintData.java Source", strings);
}
- /**
- * Verifies the hash code of the displayed image.
- *
- * @param hashCode
- * expected hash code of the image
- */
- private void assertImageHash(String hashCode) {
- // create URL of the image
- int index = selenium.getLocation().indexOf('/', 7);
- String tmp = selenium.getLocation().substring(0, index);
- tmp += selenium.getAttribute(LOC_IMAGE + "@src");
+ /**
+ * Returns hash code of the image.
+ */
+ private String getImageHash() {
+ // create URL of the image
+ int index = selenium.getLocation().indexOf('/', 7);
+ String tmp = selenium.getLocation().substring(0, index);
+ tmp += selenium.getAttribute(LOC_IMAGE + "@src");
- try {
- tmp = URLUtils.resourceMd5Digest(tmp);
- } catch (IOException e) {
- e.printStackTrace();
- fail(e.getMessage());
- }
-
- assertEquals(tmp, hashCode, "Hash of the image.");
- }
-
+ try {
+ return URLUtils.resourceMd5Digest(tmp);
+ } catch (IOException e) {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+ return null;
+ }
+
/**
* Loads the page containing the component.
*/
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/progressBar/ProgressBarTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/progressBar/ProgressBarTestCase.java 2009-09-15
10:28:18 UTC (rev 15572)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/progressBar/ProgressBarTestCase.java 2009-09-15
11:32:11 UTC (rev 15573)
@@ -26,6 +26,8 @@
import static org.testng.Assert.assertTrue;
import org.jboss.richfaces.integrationTest.AbstractSeleniumRichfacesTestCase;
+import org.jboss.test.selenium.waiting.Condition;
+import org.jboss.test.selenium.waiting.Wait;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -47,6 +49,26 @@
private final String LOC_SECOND_LABEL_INITIAL =
getLoc("SECOND_LABEL_INITIAL");
private final String LOC_SECOND_PROGRESS_BAR_STYLE =
getLoc("SECOND_PROGRESS_BAR_STYLE");
+ private class ProgressBarCondition implements Condition {
+ private int oldValue;
+ private int newValue;
+ private String locator;
+
+ public ProgressBarCondition(int oldValue, String locator) {
+ this.oldValue = oldValue;
+ this.locator = locator;
+ }
+
+ public int getNewValue() {
+ return newValue;
+ }
+
+ public boolean isTrue() {
+ newValue = (int) Double.parseDouble(getStyle(locator,
"width").replace("px", ""));
+ return newValue > oldValue;
+ }
+ }
+
/**
* Tests the first example. It checks that the button is visible and then it
* click on the button. The process starts and the test checks 3 times that
@@ -61,18 +83,17 @@
selenium.click(LOC_FIRST_BUTTON);
- waitFor(500);
- present = selenium.isElementPresent(LOC_FIRST_BUTTON);
- assertFalse(present, "Button \"Restart Process\" should not be
present on the page.");
+ Wait.failWith("Button \"Restart Process\" should not be present on
the page.").until(new Condition() {
+ public boolean isTrue() {
+ return !selenium.isElementPresent(LOC_FIRST_BUTTON);
+ }
+ });
- int value1 = 0;
- int value2 = 0;
-
- for (int i = 0; i < 6; i++) {
- waitFor(2000);
- value2 = value1;
- value1 = (int) Double.parseDouble(getStyle(LOC_FIRST_PROGRESS_BAR_STYLE,
"width").replace("px", ""));
- assertTrue(value1 > value2, "Progress bar should move to the
right.");
+ int oldValue = 0;
+ for (int i = 0; i < 4; i++) {
+ ProgressBarCondition condition = new ProgressBarCondition(oldValue,
LOC_FIRST_PROGRESS_BAR_STYLE);
+ Wait.timeout(3000).failWith("Progress bar should move to the
right.").until(condition);
+ oldValue = condition.getNewValue();
}
}
@@ -91,21 +112,23 @@
selenium.click(LOC_SECOND_BUTTON);
- int current = 0;
- int previous = 0;
- waitFor(2200);
+ int oldValue = 0;
+ waitFor(3000);
- for (int i = 0; i < 10; i++) {
- waitFor(2000);
- current = (int) Double.parseDouble(getStyle(LOC_SECOND_PROGRESS_BAR_STYLE,
"width").replace("px", ""));
- assertTrue(current >= previous, "Progress of the progress bar -- the
current value should be greater then the one 2 seconds ago.");
- previous = current;
+ for (int i = 0; i < 4; i++) {
+ ProgressBarCondition condition = new ProgressBarCondition(oldValue,
LOC_SECOND_PROGRESS_BAR_STYLE);
+ Wait.timeout(6000).failWith(format("Progress bar should move to the
right {0} times.", i + 1)).until(
+ condition);
+ oldValue = condition.getNewValue();
}
- waitFor(82000);
+ Wait.timeout(120000).interval(6000).failWith("Finished label should be
visible.").until(new Condition() {
+ public boolean isTrue() {
+ return isDisplayed(LOC_SECOND_LABEL_FINISHED);
+ }
+ });
assertFalse(isDisplayed(LOC_SECOND_LABEL_INITIAL), "Initial label should not
be visible.");
- assertTrue(isDisplayed(LOC_SECOND_LABEL_FINISHED), "Finished label should be
visible.");
}
/**