1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package net.sf.jameleon.plugin.watij.tags;
21
22 import net.sf.jameleon.exception.JameleonScriptException;
23
24 import watij.elements.SelectList;
25
26 /***
27 * Selects a given option of a select list.
28 *
29 * For example, set a select field by the displayed text option (<option>two</option>):
30 *
31 * <pre><source>
32 * <testcase xmlns="jelly:jameleon" xmlns:j="jelly:core">
33 * <watij-session baseUrl="http://some.url/some/path" beginSession="true">
34 * <watij-set-select-list
35 * functionId="Set the 'two' option of a select field"
36 * how="name"
37 * what="selectFieldName"
38 * select="two"/>
39 * </watij-session>
40 * </testcase>
41 * </source></pre>
42 *
43 * To select the option by its value attribute setting (<option value="2">two</option>)
44 *
45 * <pre><source>
46 * <testcase xmlns="jelly:jameleon" xmlns:j="jelly:core">
47 * <watij-session baseUrl="http://some.url/some/path" beginSession="true">
48 * <watij-set-select-list
49 * functionId="Set the 'two' option of a select field"
50 * how="xpath"
51 * what="//SELECT[@name='selectFieldName']"
52 * selectValue="2"/>
53 * </watij-session>
54 * </testcase>
55 * </source></pre>
56 *
57 * To clear the selected option(s):
58 *
59 * <pre><source>
60 * <testcase xmlns="jelly:jameleon" xmlns:j="jelly:core">
61 * <watij-session baseUrl="http://some.url/some/path" beginSession="true">
62 * <watij-set-select-list
63 * functionId="Clear the selected options"
64 * how="xpath"
65 * what="//SELECT[@name='selectFieldName']"
66 * clearSelection="true"/>
67 * </watij-session>
68 * </testcase>
69 * </source></pre>
70 *
71 * To select multiple values (2, and 3) against a multi select list:
72 *
73 * <pre><source>
74 * <testcase xmlns="jelly:jameleon" xmlns:j="jelly:core">
75 * <watij-session baseUrl="http://some.url/some/path" beginSession="true">
76 * <watij-set-select-list
77 * functionId="Set the 'two' option of a select field"
78 * how="xpath"
79 * what="//SELECT[@name='selectFieldName']"
80 * selectValue="2"/>
81 * <watij-set-select-list
82 * functionId="Set the 'two' option of a select field"
83 * how="name"
84 * what="selectFieldName"
85 * select="three"/>
86 * </watij-session>
87 * </testcase>
88 * </source></pre>
89 *
90 * See the javadocs on watij's {@link watij.finders.SymbolFactory SymbolFactory} for a complete list of supported symbols.
91 * @jameleon.function name="watij-set-select-list" type="action"
92 * @jameleon.step Find the matching select field
93 * @jameleon.step Verify it exists
94 * @jameleon.step Select the desired option
95 */
96 public class WatijSetSelectListTag extends WatijSelectListTag{
97
98 /***
99 * Select the option with the matching displayed text
100 * @jameleon.attribute
101 */
102 protected String select;
103 /***
104 * Select the option with the matching value attribute's value
105 * @jameleon.attribute
106 */
107 protected String selectValue;
108 /***
109 * Clear the optioh selection. If this is true and select or selectValue
110 * are set, then the list will be cleared first, and the new option will
111 * be selected. This option is for multi select boxes only.
112 * @jameleon.attribute default="false"
113 */
114 protected boolean clearSelection;
115
116 public void testBlock() throws Exception{
117 super.testBlock();
118 SelectList sl = (SelectList)getHtmlElement();
119 if (clearSelection) {
120 sl.clearSelection();
121 }
122 if (select != null && selectValue == null) {
123 sl.select(select);
124 }else if (select == null && selectValue != null) {
125 sl.selectValue(selectValue);
126 }else if (selectValue != null && selectValue != null) {
127 throw new JameleonScriptException("Both 'select' and 'selectValue' attributes can not be set! Please set only one.");
128 }
129 }
130
131 }