01: // Copyright © 2005-2007 ASERT. Released under the Canoo Webtest license.
02: package com.canoo.webtest.steps.form;
03:
04: import com.canoo.webtest.steps.Step;
05: import com.gargoylesoftware.htmlunit.html.HtmlPage;
06: import com.gargoylesoftware.htmlunit.html.HtmlRadioButtonInput;
07:
08: /**
09: * Test cases for {@link SetRadioButton}.
10: * @author Marc Guillemot
11: */
12: public class SetRadionButtonTest extends AbstractSetFieldStepTest {
13: private SetRadioButton fStep;
14:
15: protected void setUp() throws Exception {
16: super .setUp();
17: fStep = (SetRadioButton) getStep();
18: }
19:
20: protected Step createStep() {
21: return new SetRadioButton();
22: }
23:
24: public void testXPathAndHtmlId() throws Exception {
25: final String htmlContent = wrapContent("<form name='testForm'>"
26: + "<input type='radio' name='car' value='car' id='cbCar'>I have a Ford<br>"
27: + "<input type='hidden' name='car'>I have a Holden"
28: + "<input type='radio' name='car' value='bike' id='cbBike'>I have a bike<br>"
29: + "<input type='radio' name='car' value='mini' id='cbMini'><label for='cbMini'>I have a mini</label><br>"
30: + "</form>");
31: getContext().setDefaultResponse(htmlContent);
32:
33: final HtmlPage page = getContext()
34: .getCurrentHtmlResponse(fStep);
35: final HtmlRadioButtonInput radioCar = (HtmlRadioButtonInput) page
36: .getHtmlElementById("cbCar");
37: final HtmlRadioButtonInput radioBike = (HtmlRadioButtonInput) page
38: .getHtmlElementById("cbBike");
39: final HtmlRadioButtonInput radioMini = (HtmlRadioButtonInput) page
40: .getHtmlElementById("cbMini");
41:
42: assertFalse(radioCar.isChecked());
43: assertFalse(radioBike.isChecked());
44:
45: fStep.setXpath("//input[@type = 'radio' and @value = 'car']");
46: fStep.execute();
47:
48: assertTrue(radioCar.isChecked());
49: assertFalse(radioBike.isChecked());
50:
51: fStep.setHtmlId("cbBike");
52: fStep.setXpath(null);
53: fStep.execute();
54: assertFalse(radioCar.isChecked());
55: assertTrue(radioBike.isChecked());
56:
57: fStep.setHtmlId(null);
58: fStep.setForLabel("I have a mini");
59: fStep.execute();
60: assertTrue(radioMini.isChecked());
61: assertFalse(radioBike.isChecked());
62: }
63:
64: private static String wrapContent(final String content) {
65: return "<html><head><title>foo</title></head><body>" + content
66: + "</body></html>";
67: }
68:
69: public void testRedundantAttributes() {
70: fStep.setValue("foo");
71: fStep.setHtmlId("foo");
72: assertErrorOnExecute(
73: fStep,
74: "Can't specify attribute value when htmlid or xpath is specified",
75: "");
76: }
77: }
|