Revision: 902 http://jwebunit.svn.sourceforge.net/jwebunit/?rev=902&view=rev Author: jevonwright Date: 2011-03-28 23:30:22 +0000 (Mon, 28 Mar 2011)
Log Message: ----------- clarifying the functionality of assertButtonPresentWithText() when the Button is currently invisible adding test case to check functionality fixing a bug in assertButtonPresentWithText() where <button>s were treated differently from <input>s Modified Paths: -------------- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ButtonAssertionsTest.java trunk/jwebunit-commons-tests/src/main/resources/testcases/ButtonAssertionsTest/pageWithOneForm.html trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java Modified: trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ButtonAssertionsTest.java =================================================================== --- trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ButtonAssertionsTest.java 2011-03-21 16:20:16 UTC (rev 901) +++ trunk/jwebunit-commons-tests/src/main/java/net/sourceforge/jwebunit/tests/ButtonAssertionsTest.java 2011-03-28 23:30:22 UTC (rev 902) @@ -21,6 +21,8 @@ import static net.sourceforge.jwebunit.junit.JWebUnit.*; +import net.sourceforge.jwebunit.junit.WebTester; + import org.junit.Test; public class ButtonAssertionsTest extends JWebUnitAPITestCase { @@ -85,5 +87,16 @@ assertButtonPresentWithText("Testbutton2"); assertButtonPresentWithText("Outside"); } + + /** + * As per the semantics of {@link WebTester#assertButtonPresentWithText(String)}, + * buttons that are not currently displayed are still "present". + */ + @Test + public void testHiddenButtonsAreStillFound() { + beginAt("/pageWithOneForm.html"); + assertButtonPresentWithText("Hidden Input"); + assertButtonPresentWithText("Hidden Button"); + } } Modified: trunk/jwebunit-commons-tests/src/main/resources/testcases/ButtonAssertionsTest/pageWithOneForm.html =================================================================== --- trunk/jwebunit-commons-tests/src/main/resources/testcases/ButtonAssertionsTest/pageWithOneForm.html 2011-03-21 16:20:16 UTC (rev 901) +++ trunk/jwebunit-commons-tests/src/main/resources/testcases/ButtonAssertionsTest/pageWithOneForm.html 2011-03-28 23:30:22 UTC (rev 902) @@ -30,5 +30,8 @@ </form> <button id="buttonOutside">Outside</button> <input type="button" value="Input button" /> + +<input type="button" value="Hidden Input" style="display: none;" /> +<button style="display: none;">Hidden Button</button> </body> </html> Modified: trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java =================================================================== --- trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-03-21 16:20:16 UTC (rev 901) +++ trunk/jwebunit-htmlunit-plugin/src/main/java/net/sourceforge/jwebunit/htmlunit/HtmlUnitTestingEngineImpl.java 2011-03-28 23:30:22 UTC (rev 902) @@ -1359,7 +1359,11 @@ * Checks whether a button containing the specified text as its label exists. * For HTML input tags of type submit, reset, or button, this checks the * value attribute. For HTML button tags, this checks the element's - * content by converting it to text. + * content by retrieving the text content. + * + * <p>This method does not check whether the button is currently visible to the + * client. + * * @param text the text of the button (between <button></button>) * or the value of the "value" attribute. * @return <code>true</code> when the button with text could be found. @@ -1372,19 +1376,29 @@ * Returns the first button that contains the specified text as its label. * For HTML input tags of type submit, reset, or button, this checks the * value attribute. For HTML button tags, this checks the element's - * content by converting it to text. + * content by retrieving the text content. + * + * <p>This method does not check whether the button is currently visible to the + * client. + * * @param buttonValueText the text of the button (between <button></button>) * or the value of the "value" attribute. * @return the ClickableElement with the specified text or null if * no such button is found. */ public HtmlElement getButtonWithText(String buttonValueText) { + if (buttonValueText == null) + throw new NullPointerException("Cannot search for button with null text"); + List<? extends HtmlElement> l = ((HtmlPage) win.getEnclosedPage()).getDocumentElement() .getHtmlElementsByTagNames( Arrays.asList(new String[] { "button", "input" })); for (HtmlElement e : l) { if ( e instanceof HtmlButton ) { - if (((HtmlButton) e).asText().equals(buttonValueText)) { + // we cannot use asText(), as this returns an empty string if the + // button is not currently displayed, resulting in different + // behaviour as the <input> Buttons + if (buttonValueText.equals(((HtmlButton) e).getTextContent())) { return e; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Create and publish websites with WebMatrix Use the most popular FREE web apps or write code yourself; WebMatrix provides all the features you need to develop and publish your website. http://p.sf.net/sfu/ms-webmatrix-sf _______________________________________________ JWebUnit-development mailing list JWebUnit-development@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jwebunit-development