001: package watij.elements;
002:
003: import watij.WatijTestCase;
004: import static watij.finders.SymbolFactory.*;
005:
006: public class RadiosTest extends WatijTestCase {
007:
008: protected void setUp() throws Exception {
009: super .setUp();
010: ie.goTo(HTML_ROOT + "radioButtons1.html");
011: }
012:
013: public void testRadioExists() throws Exception {
014: assertTrue(ie.radio(name, "box1").exists());
015: assertTrue(ie.radio(id, "box5").exists());
016:
017: assertFalse(ie.radio(name, "missingname").exists());
018: assertFalse(ie.radio(id, "missingid").exists());
019: }
020:
021: public void testRadioClass() throws Exception {
022: assertRaisesUnknownObjectExceptionForMethodClassName(ie.radio(
023: name, "noName"));
024: assertEquals("radio_style", ie.radio(name, "box1").className());
025: assertEquals("", ie.radio(id, "box5").className());
026:
027: }
028:
029: public void testRadioEnabled() throws Exception {
030: assertRaisesUnknownObjectExceptionForMethodEnabled(ie.radio(
031: name, "noName"));
032: assertRaisesUnknownObjectExceptionForMethodEnabled(ie.radio(id,
033: "noName"));
034: assertRaisesUnknownObjectExceptionForMethodEnabled(ie.radio(
035: name, "box4", 6));
036:
037: assertFalse(ie.radio(name, "box2").enabled());
038: assertTrue(ie.radio(id, "box5").enabled());
039: assertTrue(ie.radio(name, "box1").enabled());
040:
041: }
042:
043: public void testLittle() throws Exception {
044: assertFalse(ie.button(value, "foo").enabled());
045: }
046:
047: public void testOnClick() throws Exception {
048: assertFalse(ie.radio(name, "box5").isSet());
049: assertFalse(ie.button(value, "foo").enabled());
050:
051: // first click the button is enabled and the radio is set
052: ie.radio(name, "box5", 1).set();
053: assertTrue(ie.button(value, "foo").enabled());
054:
055: // second click the button is disabled and the radio is still set
056: ie.radio(name, "box5", 1).set();
057: assertTrue(ie.radio(name, "box5", 1).isSet());
058: assertFalse(ie.button(value, "foo").enabled());
059:
060: // third click the button is enabled and the radio is still set
061: ie.radio(name, "box5", 1).set();
062: assertTrue(ie.radio(name, "box5", 1).isSet());
063: assertTrue(ie.button(value, "foo").enabled());
064:
065: // click the radio with a value of 2 , button is disabled and the radio
066: // is still set
067: ie.radio(name, "box5", 2).set();
068: assertFalse(ie.radio(name, "box5", 1).isSet());
069: assertTrue(ie.radio(name, "box5", 2).isSet());
070: assertFalse(ie.button(value, "foo").enabled());
071: }
072:
073: public void testRadioIsSet() throws Exception {
074: assertRaisesUnknownObjectExceptionForMethodIsSet(ie.radio(name,
075: "noName"));
076: assertFalse(ie.radio(name, "box1").isSet());
077: assertTrue(ie.radio(name, "box3").isSet());
078: assertFalse(ie.radio(name, "box2").isSet());
079: assertTrue(ie.radio(name, "box4", 1).isSet());
080: assertFalse(ie.radio(name, "box4", 2).isSet());
081: }
082:
083: public void testRadioClear() throws Exception {
084: assertRaisesUnknownObjectExceptionForMethodClear(ie.radio(name,
085: "noName"));
086:
087: ie.radio(name, "box1").clear();
088: assertFalse(ie.radio(name, "box1").isSet());
089:
090: assertRaisesDisabledObjectExceptionForMethodClear(ie.radio(
091: name, "box2"));
092: assertFalse(ie.radio(name, "box2").isSet());
093:
094: ie.radio(name, "box3").clear();
095: assertFalse(ie.radio(name, "box2").isSet());
096:
097: ie.radio(name, "box4", 1).clear();
098: assertFalse(ie.radio(name, "box4", 1).isSet());
099:
100: }
101:
102: public void testRadioGetState() throws Exception {
103: assertRaisesUnknownObjectExceptionForMethodGetState(ie.radio(
104: name, "noName"));
105:
106: assertEquals(false, ie.radio(name, "box1").getState());
107: assertEquals(true, ie.radio(name, "box3").getState());
108:
109: // radioes that have the same name but different values
110: assertEquals(false, ie.radio(name, "box4", 2).getState());
111: assertEquals(true, ie.radio(name, "box4", 1).getState());
112:
113: }
114:
115: public void testRadioSet() throws Exception {
116: assertRaisesUnknownObjectExceptionForMethodSet(ie.radio(name,
117: "noName"));
118: ie.radio(name, "box1").set();
119: assertTrue(ie.radio(name, "box1").isSet());
120:
121: assertRaisesDisabledObjectExceptionForMethodSet(ie.radio(name,
122: "box2"));
123:
124: ie.radio(name, "box3").set();
125: assertTrue(ie.radio(name, "box3").isSet());
126:
127: // radioes that have the same name but different values
128: ie.radio(name, "box4", 3).set();
129: assertTrue(ie.radio(name, "box4", 3).isSet());
130:
131: }
132:
133: public void testRadioProperties() throws Exception {
134: assertRaisesUnknownObjectExceptionForMethodValue(ie.radio(999));
135: assertRaisesUnknownObjectExceptionForMethodName(ie.radio(999));
136: assertRaisesUnknownObjectExceptionForMethodId(ie.radio(999));
137: assertRaisesUnknownObjectExceptionForMethodType(ie.radio(999));
138:
139: assertEquals("on", ie.radio(0).value());
140: assertEquals("box1", ie.radio(0).name());
141: assertEquals("", ie.radio(0).id());
142: assertEquals("radio", ie.radio(0).type());
143:
144: assertEquals(false, ie.radio(0).disabled());
145: assertEquals(true, ie.radio(2).disabled());
146:
147: assertEquals("box5", ie.radio(1).id());
148: assertEquals("", ie.radio(1).name());
149:
150: assertEquals("box4-value5", ie.radio(name, "box4", 5).title());
151: assertEquals("", ie.radio(name, "box4", 4).title());
152:
153: }
154:
155: public void testRadioIterators() throws Exception {
156: Radios radios = ie.radios();
157: assertEquals(11, radios.length());
158: assertEquals("box5", radios.get(1).id());
159: assertEquals(true, radios.get(2).disabled());
160: assertEquals(false, radios.get(0).disabled());
161:
162: int i = 0;
163: for (Radio radio : radios) {
164: assertEquals(ie.radio(i).name(), radio.name());
165: assertEquals(ie.radio(i).id(), radio.id());
166: assertEquals(ie.radio(i).value(), radio.value());
167: assertEquals(ie.radio(i).disabled(), radio.disabled());
168: i += 1;
169:
170: }
171: assertEquals(i, radios.length());
172: }
173: }
|