001: package watij.elements;
002:
003: import watij.WatijTestCase;
004: import static watij.finders.SymbolFactory.name;
005: import static watij.finders.SymbolFactory.xpath;
006:
007: public class DivXpathTest extends WatijTestCase {
008:
009: protected void setUp() throws Exception {
010: super .setUp();
011: ie.goTo(HTML_ROOT + "div.html");
012: }
013:
014: public void testDivs() throws Exception {
015: assertRaisesUnknownObjectExceptionForMethodClick(ie.div(xpath,
016: "//DIV[@id='div77']"));
017: assertRaisesUnknownObjectExceptionForMethodClick(ie.div(xpath,
018: "//DIV[@title='div77']"));
019:
020: assertTrue(ie.textField(xpath, "//INPUT[@name='text1']")
021: .verifyContains("0"));
022: ie.div(xpath, "//DIV[@id='div3']").click();
023: assertTrue(ie.textField(xpath, "//INPUT[@name='text1']")
024: .verifyContains("1"));
025: ie.div(xpath, "//DIV[@id='div4']").click();
026: assertTrue(ie.textField(xpath, "//INPUT[@name='text1']")
027: .verifyContains("0"));
028: }
029:
030: public void testDivProperties() throws Exception {
031: assertRaisesUnknownObjectExceptionForMethodText(ie.div(xpath,
032: "//DIV[@id='div77']"));
033: assertRaisesUnknownObjectExceptionForMethodText(ie.div(xpath,
034: "//DIV[@title='div77']"));
035:
036: assertEquals("This div has an onClick that increments text1",
037: ie.div(xpath, "//DIV[@id='div3']").text().trim());
038: assertEquals(
039: "This text is in a div with an id of div1 and title of test1",
040: ie.div(xpath, "//DIV[@title='Test1']").text().trim());
041:
042: assertRaisesUnknownObjectExceptionForMethodClassName(ie.div(
043: xpath, "//DIV[@id='div77']"));
044: assertEquals("blueText", ie.div(xpath, "//DIV[@id='div2']")
045: .className());
046: assertEquals("", ie.div(xpath, "//DIV[@id='div1']").className());
047: }
048:
049: public void testobjects_in_div() throws Exception {
050:
051: assertTrue(ie.div(xpath, "//DIV[@id='buttons1']").button(0)
052: .exists());
053: assertFalse(ie.div(xpath, "//DIV[@id='buttons1']").button(2)
054: .exists());
055: assertTrue(ie.div(xpath, "//DIV[@id='buttons1']").button(name,
056: "b1").exists());
057:
058: assertTrue(ie.div(xpath, "//DIV[@id='buttons2']").button(0)
059: .exists());
060: assertTrue(ie.div(xpath, "//DIV[@id='buttons2']").button(1)
061: .exists());
062: assertFalse(ie.div(xpath, "//DIV[@id='buttons1']").button(2)
063: .exists());
064:
065: ie.div(xpath, "//DIV[@id='buttons1']").button(0).click();
066:
067: assertEquals("button1", ie.div(xpath,
068: "//DIV[@id='text_fields1']").textField(0).value());
069:
070: assertEquals(3, ie.div(xpath, "//DIV[@id='text_fields1']")
071: .textFields().length());
072: }
073:
074: public void testSpanProperties() throws Exception {
075: assertRaisesUnknownObjectExceptionForMethodText(ie.span(xpath,
076: "//SPAN[@id='span77']"));
077: assertRaisesUnknownObjectExceptionForMethodText(ie.span(xpath,
078: "//SPAN[@title='span77']"));
079:
080: assertEquals("This span has an onClick that increments text2",
081: ie.span(xpath, "//SPAN[@id='span3']").text().trim());
082: assertEquals(
083: "This text is in a span with an id of span1 and title of test2",
084: ie.span(xpath, "//SPAN[@title='Test2']").text().trim());
085:
086: assertRaisesUnknownObjectExceptionForMethodClassName(ie.span(
087: xpath, "//SPAN[@id='span77']"));
088: assertEquals("blueText", ie.span(xpath, "//SPAN[@id='span2']")
089: .className());
090: assertEquals("", ie.span(xpath, "//SPAN[@id='span1']")
091: .className());
092: }
093:
094: public void testObjectsInSpan() throws Exception {
095:
096: assertTrue(ie.span(xpath, "//SPAN[@id='buttons1']").button(0)
097: .exists());
098: assertFalse(ie.span(xpath, "//SPAN[@id='buttons1']").button(2)
099: .exists());
100: assertTrue(ie.span(xpath, "//SPAN[@id='buttons1']").button(
101: name, "b1").exists());
102:
103: assertTrue(ie.span(xpath, "//SPAN[@id='buttons2']").button(0)
104: .exists());
105: assertTrue(ie.span(xpath, "//SPAN[@id='buttons2']").button(1)
106: .exists());
107: assertFalse(ie.span(xpath, "//SPAN[@id='buttons1']").button(2)
108: .exists());
109:
110: ie.span(xpath, "//SPAN[@id='buttons1']").button(0).click();
111:
112: assertEquals("button1", ie.span(xpath,
113: "//SPAN[@id='text_fields1']").textField(0).value());
114:
115: assertEquals(3, ie.span(xpath, "//SPAN[@id='text_fields1']")
116: .textFields().length());
117: }
118:
119: public void testP() throws Exception {
120: //P tag has not yet been implemented
121:
122: // assertTrue(ie.p(xpath, "//P[@id='number1']").exists());
123: // assertTrue(ie.p(xpath, "//P[@title='test_3']").exists());
124: //
125: // assertFalse(ie.p(xpath, "//P[@id='missing']").exists());
126: // assertFalse(ie.p(xpath, "//P[@title='test_55']").exists());
127: //
128: // assertRaisesUnknownObjectExceptionForMethodClassName(ie.p(xpath, "//P[@id='missing']"));
129: // assertRaisesUnknownObjectExceptionForMethodText(ie.p(xpath, "//P[@id='missing']"));
130: // assertRaisesUnknownObjectExceptionForMethodTitle(ie.p(xpath, "//P[@id='missing']"));
131: // assertRaisesUnknownObjectExceptionForMethodToString(ie.p(xpath, "//P[@id='missing']"));
132: // assertRaisesUnknownObjectExceptionForMethodDisabled(ie.p(xpath, "//P[@id='missing']"));
133: }
134: }
|