If you read the API docs for the FromTester you'll find out that you can only
submit it once.
After that you need to grab a new FormTester and submit it again.
As such, on each step of your wizard you should create a new FormTester and
submit it using the corresponding button, not invoking the Button.onSumit() but
by calling gormTester.submit(myNextOrFinishButtonPath).
This is a small example on how I complete a wizard step:
private void completeUserGroupDetailsStep(ConsoleWicketTester tester) {
FormTester formTester = getHelper().getWizardFormTester(tester);
tester.setValue(formTester, tester.findComponent("**:name",
TextField.class), testUserGroup.getName());
tester.setValue(formTester, tester.findComponent("**:description",
TextArea.class), testUserGroup.getDescription());
tester.submit(formTester, getHelper().getWizardNextButton(tester),
false); // same as FormTester.submit()
tester.assertRenderedPage(EditUserGroupPage.class);
tester.assertNoErrorMessage();
tester.cleanupFeedbackMessages();
}
Where tester.submit takes in a reference to a FormTester and invokes its
sumit() method after a bunch of asserts which I won't bore you with right now.
However, I'll be nice and share my wizard helper methods to give you an idea :)
/////////////////////////
// Wizard Methods //
/////////////////////////
/** @see #getWizardFormTester(ConsoleWicketTester, String) */
public FormTester getWizardFormTester(ConsoleWicketTester tester) {
return getWizardFormTester(tester, "wizard");
}
/**
* Given the Wicket id for the Wizard, return a {@link FormTester} to it
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @return The {@link FormTester} for the given Wizard
*/
public FormTester getWizardFormTester(ConsoleWicketTester tester, String
wizardId) {
Form<?> form = (Form<?>)tester.findComponent("**:"+wizardId+":form",
Form.class);
return tester.newFormTester(form);
}
/** @see #getWizardPreviousButton(ConsoleWicketTester, String) */
public Button getWizardPreviousButton(ConsoleWicketTester tester) {
return getWizardPreviousButton(tester, "wizard");
}
/**
* Given the Wicket id for the Wizard, return its {@link PreviousButton}
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @return {@link PreviousButton} down cast to a {@link
Button}
*/
public Button getWizardPreviousButton(ConsoleWicketTester tester, String
wizardId) {
return
(PreviousButton)tester.findComponent("**:"+wizardId+":**:buttons:previous",
PreviousButton.class);
}
/** @see #getWizardCancelButton(ConsoleWicketTester, String) */
public Button getWizardCancelButton(ConsoleWicketTester tester) {
return getWizardCancelButton(tester, "wizard");
}
/**
* Given the Wicket id for the Wizard, return its {@link CancelButton}
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @return {@link CancelButton} down cast to a {@link
Button}
*/
public Button getWizardCancelButton(ConsoleWicketTester tester, String
wizardId) {
return
(CancelButton)tester.findComponent("**:"+wizardId+":**:buttons:cancel",
CancelButton.class);
}
/** @see #getWizardNextButton(ConsoleWicketTester, String) */
public Button getWizardNextButton(ConsoleWicketTester tester) {
return getWizardNextButton(tester, "wizard");
}
/**
* Given the Wicket id for the Wizard, return its {@link NextButton}
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @return {@link NextButton} down cast to a {@link Button}
*/
public Button getWizardNextButton(ConsoleWicketTester tester, String
wizardId) {
return
(NextButton)tester.findComponent("**:"+wizardId+":**:buttons:next",
NextButton.class);
}
/** @see #getWizardFinishButton(ConsoleWicketTester, String) */
public Button getWizardFinishButton(ConsoleWicketTester tester) {
return getWizardFinishButton(tester, "wizard");
}
/**
* Given the Wicket id for the Wizard, return its {@link MyFinishButton}
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @return {@link MyFinishButton} down cast to a {@link
Button}
*/
public Button getWizardFinishButton(ConsoleWicketTester tester, String
wizardId) {
return
(MyFinishButton)tester.findComponent("**:"+wizardId+":**:buttons:finish",
MyFinishButton.class);
}
/** @see #assertWizardButtonsEnabledState(ConsoleWicketTester, String,
boolean, boolean, boolean, boolean) */
public void assertWizardButtonsEnabledState(ConsoleWicketTester tester,
boolean previous, boolean next, boolean cancel, boolean finish) {
assertWizardButtonsEnabledState(tester, "wizard", previous, next,
cancel, finish);
}
/**
* Assert the button enable state given the Wicket id for the Wizard and
the states for the
* Previous, Next, Cancel and Finish buttons.
*
* @param tester {@link ConsoleWicketTester} within the page
context
* @param wizardId Wicket id for the Wizard
* @param previous <code>true</code> if the Previous button is to
be enabled, <code>false</code> otherwise
* @param next <code>true</code> if the Next button is to be
enabled, <code>false</code> otherwise
* @param cancel <code>true</code> if the Cancel button is to be
enabled, <code>false</code> otherwise
* @param finish <code>true</code> if the Finish button is to be
enabled, <code>false</code> otherwise
* @return
*/
public void assertWizardButtonsEnabledState(ConsoleWicketTester tester,
String wizardId, boolean previous, boolean next, boolean cancel, boolean
finish) {
Assert.assertTrue(getWizardPreviousButton(tester, wizardId).isEnabled()
== previous,
String.format("Previous button was expected %s be enabled!",
previous ? "to" : "not to"));
Assert.assertTrue(getWizardNextButton(tester, wizardId) .isEnabled()
== next,
String.format("Next button was expected %s be enabled!", next ?
"to" : "not "));
Assert.assertTrue(getWizardCancelButton(tester, wizardId) .isEnabled()
== cancel,
String.format("Cancel button was expected %s be enabled!",
cancel ? "to" : "not to"));
Assert.assertTrue(getWizardFinishButton(tester, wizardId) .isEnabled()
== finish,
String.format("Finish button was expected %s be enabled!",
finish ? "to" : "not to"));
}
~ Thank you,
Paul Bors
-----Original Message-----
From: ludo_xiv [mailto:[email protected]]
Sent: Tuesday, July 02, 2013 11:51 AM
To: [email protected]
Subject: wickettester and wizard next step submit response
hi,
i'm using wickettester with wicket 1.5.5 and i need to submit wizard and get
response with next step (panel with form) but i can't get it working.
Example:
1. FormTester firstWizardForm = tester.newFormTester("wizard:form");
2. firstWizardForm.select("view:items:type", 1);
3.
tester.executeAjaxEvent(tester.getComponentFromLastRenderedPage("wizard:form:view:items:type"),
"onchange");
4. firstWizardForm.setValue("view:items:amount", "1");
5.
tester.executeAjaxEvent(tester.getComponentFromLastRenderedPage("wizard:form:view:items:amount"),
"onchange");
6. WizardButton nextButton = (WizardButton)
tester.getComponentFromLastRenderedPage("wizard:form:buttons:next");
7. nextButton.onSubmit();
8. tester.getLastResponseAsString();
Everythink works fine but in the last command i didn't get expected html markup.
Instead of expected, last response is the same as after line 5.
Thanks a lot.
_____________________________________________________________________
Hladate spisovny vyraz? http://www.jazykovaporadna.sk
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]