KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jwebunit > TextAndElementWalkerTest


1 /**
2  * User: djoiner
3  * Date: Nov 21, 2002
4  * Time: 10:34:16 AM
5  */

6 package net.sourceforge.jwebunit;
7
8 import junit.framework.TestCase;
9 import org.w3c.dom.Element JavaDoc;
10 import org.w3c.dom.Document JavaDoc;
11
12 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
13 import javax.xml.parsers.ParserConfigurationException JavaDoc;
14
15 public class TextAndElementWalkerTest extends TestCase {
16
17     public void testFindLabel() throws ParserConfigurationException JavaDoc {
18         Element JavaDoc form = buildForm();
19         TextAndElementWalker walker =
20                 new TextAndElementWalker(form,
21                     new String JavaDoc[] { "input", "select", "textarea" });
22         assertNotNull(walker.getElementAfterText("First"));
23     }
24
25
26 // <form method=GET action="TargetPage">
27
// First : <input type="text" name="param1">
28
// Second : <textarea name="param2">
29
// </form>
30
private Element JavaDoc buildForm() throws ParserConfigurationException JavaDoc {
31         Document JavaDoc doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
32         Element JavaDoc form = doc.createElement("form");
33         form.setAttribute("method", "GET");
34         form.setAttribute("action", "TargetPage");
35         form.appendChild(doc.createTextNode("First : "));
36         Element JavaDoc param1 = doc.createElement("input");
37         param1.setAttribute("type", "text");
38         param1.setAttribute("name", "param1");
39         form.appendChild(param1);
40         form.appendChild(doc.createTextNode("Second : "));
41         Element JavaDoc param2 = doc.createElement("input");
42         param2.setAttribute("type", "text");
43         param2.setAttribute("name", "param2");
44         form.appendChild(param2);
45         return form;
46     }
47
48 }
49
Popular Tags