/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Static factory method for creating a <code>TagTester</code> based on a tag found by an * attribute with a specific value. Please note that it will return the first tag which matches * the criteria. It's therefore good for attributes suck as "id" or "wicket:id", but only if * "wicket:id" is unique in the specified markup. * * @param markup * the markup to look for the tag to create the <code>TagTester</code> from * @param attribute * the attribute which should be on the tag in the markup * @param value * the value which the attribute must have * @return the <code>TagTester</code> which matches the tag in the markup, that has the given * value on the given attribute */ @Deprecated public static TagTester createTagsByAttribute(String markup, String attribute, String value) { return createTagByAttribute(markup, attribute, value); }
/** * Gets a child tag for testing. If this tag contains child tags, you can get one of them as a * {@link TagTester} instance. * * @param attribute * an attribute on the child tag to search for * @param value * a value that the attribute must have * @return the <code>TagTester</code> for the child tag */ public TagTester getChild(String attribute, String value) { TagTester childTag = null; if (openTag.isOpen()) { // Generate the markup for this tag String markup = getMarkup(); if (Strings.isEmpty(markup) == false) { childTag = TagTester.createTagByAttribute(markup, attribute, value); } } return childTag; }
TagTester.createTagByAttribute( html, "wicketPath", path.replace(":", "_") + "_itemProperties_4_component_menu"); String onchange = menuTester.getAttribute("onchange"); assertThat( onchange,
@Test public void buttonWithIconIsAddedToLeftNavigation() { Navbar navbar = new Navbar("id"); navbar.addComponents(new INavbarComponent() { @Override public Component create(String markupId) { return new NavbarButton<Page>(Page.class, Model.of("Link Name")).setIconType(IconType.aligncenter); } @Override public Navbar.ComponentPosition getPosition() { return Navbar.ComponentPosition.LEFT; } }); tester().startComponentInPage(navbar); Assert.assertThat(tester().getTagByWicketId(Navbar.COMPONENT_ID).hasChildTag("i"), is(equalTo(true))); Assert.assertThat(tester().getTagByWicketId("icon").getAttribute("class"), containsString("icon-align-center")); } }
XmlTag foundTag = findOpenTag(xmlTag, stack); if (foundTag == null) TagTester tester = new TagTester(parser, openTag, closeTag); testers.add(tester); openTag = null;
@Test public void initialLeftNavigationIsEmpty() { Navbar navbar = new Navbar("id"); tester().startComponentInPage(navbar); TagTester tagTester = tester().getTagById("nav-collapse"); TagTester ulTag = tagTester.getChild("style", "display:none"); Assert.assertThat(ulTag.getValue(), is(equalTo(""))); Assert.assertThat(ulTag.getName(), is(equalTo("ul"))); }
tester = new TagTester(parser, openTag, closeTag);
@Test public void buttonIsAddedToLeftNavigation() { Navbar navbar = new Navbar("id"); navbar.addComponents(new INavbarComponent() { @Override public Component create(String markupId) { return new NavbarButton<Page>(Page.class, Model.of("Link Name")); } @Override public Navbar.ComponentPosition getPosition() { return Navbar.ComponentPosition.LEFT; } }); tester().startComponentInPage(navbar); TagTester tagTester = tester().getTagByWicketId("navLeftList"); Assert.assertThat(tagTester.hasChildTag("a"), is(equalTo(true))); Assert.assertThat(tester().getTagByWicketId(Navbar.COMPONENT_ID).hasAttribute("href"), is(equalTo(true))); Assert.assertThat(tester().getTagByWicketId(Navbar.COMPONENT_ID).getValue(), containsString("Link Name")); }
/** * Static factory method for creating a <code>TagTester</code> based on a tag found by an * attribute with a specific value. Please note that it will return the first tag which matches * the criteria. It's therefore good for attributes such as "id" or "wicket:id", but only if * "wicket:id" is unique in the specified markup. * * @param markup * the markup to look for the tag to create the <code>TagTester</code> from * @param attribute * the attribute which should be on the tag in the markup * @param value * the value which the attribute must have * @return the <code>TagTester</code> which matches the tag in the markup, that has the given * value on the given attribute */ public static TagTester createTagByAttribute(String markup, String attribute, String value) { List<TagTester> tester = createTagsByAttribute(markup, attribute, value, true); if ((tester == null) || (tester.size() == 0)) { return null; } return tester.get(0); }
@Test public void testUpdate() throws Exception { SimpleDateFormat formatter = new SimpleDateFormat(SystemStatusMonitorPanel.datePattern); tester.assertRenderedPage(StatusPage.class); tester.clickLink("tabs:tabs-container:tabs:2:link", true); TagTester time1 = tester.getTagByWicketId("time"); assertNotNull(time1); Date firstTime = formatter.parse(time1.getValue()); System.out.println(firstTime.getTime()); // Execute timer Thread.sleep(1000); tester.executeAllTimerBehaviors(tester.getLastRenderedPage()); TagTester time2 = tester.getTagByWicketId("time"); assertNotNull(time2); Date secondTime = formatter.parse(time2.getValue()); // Check if update time is changed assertTrue(secondTime.getTime() > firstTime.getTime()); Thread.sleep(1000); tester.executeAllTimerBehaviors(tester.getLastRenderedPage()); TagTester time3 = tester.getTagByWicketId("time"); assertNotNull(time3); Date thirdTime = formatter.parse(time3.getValue()); // Check if update time is changed (use 500ms due to time imprecision) assertTrue(thirdTime.getTime() > secondTime.getTime()); } }
XmlTag foundTag = findOpenTag(xmlTag, stack); if (foundTag == null) TagTester tester = new TagTester(parser, openTag, closeTag); testers.add(tester); openTag = null;
tester = new TagTester(parser, openTag, closeTag);
/** * Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags * instead of just the first. * * @param wicketId * @return List of Tags */ public List<TagTester> getTagsByWicketId(String wicketId) { return TagTester.createTagsByAttribute(getLastResponseAsString(), "wicket:id", wicketId, false); }
@Test public void brandNameIsRendered() { Navbar navbar = new Navbar("id"); navbar.brandName(Model.of("Brand Name")); tester().startComponentInPage(navbar); TagTester tagTester = tester().getTagByWicketId("brandLabel"); Assert.assertThat(tagTester.getValue(), is(equalTo("Brand Name"))); }
/** * Tests if the tag contains the given attribute. Please note that this is non case-sensitive, * because attributes in HTML may be non case-sensitive. * * @param attribute * an attribute to look for in the tag * @return <code>true</code> if the tag has the attribute, <code>false</code> if not. */ public boolean hasAttribute(String attribute) { boolean hasAttribute = false; if (getAttribute(attribute) != null) { hasAttribute = true; } return hasAttribute; }
/** * Retrieves a <code>TagTester</code> based on an DOM id. If more <code>Component</code>s exist * with the same id in the markup, only the first one is returned. * * @param id * the DOM id to search for. * @return the <code>TagTester</code> for the tag which has the given DOM id */ public TagTester getTagById(String id) { return TagTester.createTagByAttribute(getLastResponseAsString(), "id", id); }
/** * Gets a child tag for testing. If this tag contains child tags, you can get one of them as a * {@link TagTester} instance. * * @param attribute * an attribute on the child tag to search for * @param value * a value that the attribute must have * @return the <code>TagTester</code> for the child tag */ public TagTester getChild(String attribute, String value) { TagTester childTag = null; if (openTag.isOpen()) { // Generate the markup for this tag String markup = getMarkup(); if (Strings.isEmpty(markup) == false) { childTag = TagTester.createTagByAttribute(markup, attribute, value); } } return childTag; }
TagTester tester = new TagTester(parser, openTag, closeTag); testers.add(tester); openTag = null;
/** * Modified version of BaseWicketTester#getTagByWicketId(String) that returns all matching tags * instead of just the first. * * @param wicketId * @return List of Tags */ public List<TagTester> getTagsByWicketId(String wicketId) { return TagTester.createTagsByAttribute(getLastResponseAsString(), "wicket:id", wicketId, false); }