If i'm not completely wrong is tester.clickLink(path) a wrapper for
tester.clickLink(path, isAjax = true). So you get an ajax response.
You can check that by calling tester.dumpPage().
The problem is that wicket tester only works on page markup. It is not
working on ajax response markup (at least i didn't get it to work.
Once i've wrote an extractor. Maybe that helps you to.
<code>
package de.frontend.wicket.testtools;
public final class AjaxResponseComponentMarkup {
private final String _ajaxResponseMarkup;
private final int _componentTagStartPosition;
private final int _componentTagEndPosition;
public AjaxResponseComponentMarkup(String ajaxResponseMarkup) {
_ajaxResponseMarkup = ajaxResponseMarkup;
_componentTagStartPosition =
_ajaxResponseMarkup.indexOf("<component");
_componentTagEndPosition =
_ajaxResponseMarkup.indexOf("</component>");
}
public String extract() {
StringBuilder result = new StringBuilder();
if (hasComponentTag()) {
result.append(_ajaxResponseMarkup.substring(startOfAjaxResponseComponentMarkup(),
endOfAjaxResponseComponentMarkup()));
}
return result.toString();
}
private int startOfAjaxResponseComponentMarkup() {
String cdataTag = "<![CDATA[";
return _ajaxResponseMarkup.indexOf(cdataTag,
_componentTagStartPosition) + cdataTag.length();
}
private int endOfAjaxResponseComponentMarkup() {
String cdataTag = "]]>";
return
_ajaxResponseMarkup.substring(_componentTagStartPosition,
_componentTagEndPosition).lastIndexOf(cdataTag) + _componentTagStartPosition;
}
private boolean hasComponentTag() {
return _componentTagStartPosition != -1;
}
}
</code>
This is only extracting the markup in CDATA of ajax response.
Use it this way:
<code>
private void assertExpandedNodeAt(int row) {
List<TagTester> t = TagTester.createTagsByAttribute(new
AjaxResponseComponentMarkup(_tester.getServletResponse().getDocument()).extract(),
"wicketpath",
"brdPage_availability_tariffTable_rows_" + row
+ "_cells_1_cell_junction", true);
Assert.assertTrue("Node " + row + " is collapsed",
t.get(0).getAttributeIs("class", "tree-junction-expanded"));
}
</code>
Please see TagTester.createTagsByAttribute for concrete parameters required.
Maybe someone else has a better approach. But for me this was working.
Hth
Mike
-------- Original-Nachricht --------
> Datum: Fri, 19 Aug 2011 18:38:43 +0200
> Von: Mathilde Pellerin <[email protected]>
> An: [email protected]
> Betreff: Re: how to test what radio is checked in a radiogroup?
> hum, yes and no... I mean, page is loaded by an ajax response (AjaxLink),
> but then there is no Ajax.
> This is the entire test, maybe it can help :
>
> @SuppressWarnings("unchecked")
> @Test @Transactional @Rollback
> public void testStory23_TA21_VerificationInitialisationBoutonsRadio(){
> tester.startPage(RecapitulatifQuestionnairePage.class);
> tester.assertRenderedPage(RecapitulatifQuestionnairePage.class);
> tester.clickLink("questionnaireEnCours:1:modifier");
> tester.assertRenderedPage(CreationQuestionnairePage.class);
>
> Form<Questionnaire> form = (Form<Questionnaire>)
> tester.getComponentFromLastRenderedPage(
> "formCreationQuestionnaire");
>
> //On vérifie que le formulaire est préremplie avec le
> questionnaire
> sélectionné
> Questionnaire qObtenu = form.getModelObject();
> Assert.assertNotNull(qObtenu);
>
> //Vérification du sexe des destinataires
> String genreAttendu = qObtenu.getSexeDestinataire().toString();
> String genreObtenu =
> ((RadioGroup<String>)form.get("genre")).getDefaultModelObjectAsString();
> Assert.assertEquals(genreAttendu, genreObtenu);
>
> TagTester tagFemme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:femme");
> TagTester tagHomme =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:homme");
> TagTester tagMixte =
> tester.getTagByWicketId("formCreationQuestionnaire:genre:mixte");
> tester.debugComponentTrees();
> Assert.assertNotNull(tagFemme);
>
> Assert.assertTrue(tagFemme.hasAttribute("checked"));
> Assert.assertFalse(tagHomme.hasAttribute("checked"));
> Assert.assertFalse(tagMixte.hasAttribute("checked"));
> }
--
Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]