@@ -32,79 +32,98 @@ protected function setUp()
3232
3333 public function testIsMultiple ()
3434 {
35- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
36- $ this ->assertTrue ($ c ->isMultiple ());
35+ $ checkboxes = new WebDriverCheckboxes (
36+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
37+ );
38+
39+ $ this ->assertTrue ($ checkboxes ->isMultiple ());
3740 }
3841
3942 public function testGetOptions ()
4043 {
41- $ c = new WebDriverCheckboxes (
44+ $ checkboxes = new WebDriverCheckboxes (
4245 $ this ->driver ->findElement (WebDriverBy::xpath ('//form[2]//input[@type="checkbox"] ' ))
4346 );
44- $ this ->assertNotEmpty ($ c ->getOptions ());
47+
48+ $ this ->assertNotEmpty ($ checkboxes ->getOptions ());
4549 }
4650
4751 public function testGetFirstSelectedOption ()
4852 {
49- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
50- $ c ->selectByValue ('j2a ' );
51- $ this ->assertSame ('j2a ' , $ c ->getFirstSelectedOption ()->getAttribute ('value ' ));
53+ $ checkboxes = new WebDriverCheckboxes (
54+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
55+ );
56+
57+ $ checkboxes ->selectByValue ('j2a ' );
58+
59+ $ this ->assertSame ('j2a ' , $ checkboxes ->getFirstSelectedOption ()->getAttribute ('value ' ));
5260 }
5361
54- public function testGetFirstSelectedOptionWithSameNameDifferentForm ()
62+ public function testShouldGetFirstSelectedOptionConsideringOnlyElementsAssociatedWithCurrentForm ()
5563 {
56- $ radio = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@id="j5b"] ' )));
57- $ this ->assertEquals ('j5b ' , $ radio ->getFirstSelectedOption ()->getAttribute ('value ' ));
64+ $ checkboxes = new WebDriverCheckboxes (
65+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@id="j5b"] ' ))
66+ );
67+
68+ $ this ->assertEquals ('j5b ' , $ checkboxes ->getFirstSelectedOption ()->getAttribute ('value ' ));
5869 }
5970
6071 public function testSelectByValue ()
6172 {
6273 $ selectedOptions = ['j2b ' , 'j2c ' ];
6374
64- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
75+ $ checkboxes = new WebDriverCheckboxes (
76+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
77+ );
6578 foreach ($ selectedOptions as $ index => $ selectedOption ) {
66- $ c ->selectByValue ($ selectedOption );
79+ $ checkboxes ->selectByValue ($ selectedOption );
6780 }
6881
6982 $ selectedValues = [];
70- foreach ($ c ->getAllSelectedOptions () as $ option ) {
83+ foreach ($ checkboxes ->getAllSelectedOptions () as $ option ) {
7184 $ selectedValues [] = $ option ->getAttribute ('value ' );
7285 }
7386 $ this ->assertSame ($ selectedOptions , $ selectedValues );
7487 }
7588
7689 public function testSelectByValueInvalid ()
7790 {
78- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
91+ $ checkboxes = new WebDriverCheckboxes (
92+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
93+ );
7994
8095 $ this ->expectException (NoSuchElementException::class);
8196 $ this ->expectExceptionMessage ('Cannot locate checkbox with value: notexist ' );
82- $ c ->selectByValue ('notexist ' );
97+ $ checkboxes ->selectByValue ('notexist ' );
8398 }
8499
85100 public function testSelectByIndex ()
86101 {
87102 $ selectedOptions = [1 => 'j2b ' , 2 => 'j2c ' ];
88103
89- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
104+ $ checkboxes = new WebDriverCheckboxes (
105+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
106+ );
90107 foreach ($ selectedOptions as $ index => $ selectedOption ) {
91- $ c ->selectByIndex ($ index );
108+ $ checkboxes ->selectByIndex ($ index );
92109 }
93110
94111 $ selectedValues = [];
95- foreach ($ c ->getAllSelectedOptions () as $ option ) {
112+ foreach ($ checkboxes ->getAllSelectedOptions () as $ option ) {
96113 $ selectedValues [] = $ option ->getAttribute ('value ' );
97114 }
98115 $ this ->assertSame (array_values ($ selectedOptions ), $ selectedValues );
99116 }
100117
101118 public function testSelectByIndexInvalid ()
102119 {
103- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
120+ $ checkboxes = new WebDriverCheckboxes (
121+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
122+ );
104123
105124 $ this ->expectException (NoSuchElementException::class);
106125 $ this ->expectExceptionMessage ('Cannot locate checkbox with index: ' . PHP_INT_MAX );
107- $ c ->selectByIndex (PHP_INT_MAX );
126+ $ checkboxes ->selectByIndex (PHP_INT_MAX );
108127 }
109128
110129 /**
@@ -115,9 +134,13 @@ public function testSelectByIndexInvalid()
115134 */
116135 public function testSelectByVisibleText ($ text , $ value )
117136 {
118- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
119- $ c ->selectByVisibleText ($ text );
120- $ this ->assertSame ($ value , $ c ->getFirstSelectedOption ()->getAttribute ('value ' ));
137+ $ checkboxes = new WebDriverCheckboxes (
138+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
139+ );
140+
141+ $ checkboxes ->selectByVisibleText ($ text );
142+
143+ $ this ->assertSame ($ value , $ checkboxes ->getFirstSelectedOption ()->getAttribute ('value ' ));
121144 }
122145
123146 /**
@@ -139,9 +162,13 @@ public function selectByVisibleTextDataProvider()
139162 */
140163 public function testSelectByVisiblePartialText ($ text , $ value )
141164 {
142- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
143- $ c ->selectByVisiblePartialText ($ text );
144- $ this ->assertSame ($ value , $ c ->getFirstSelectedOption ()->getAttribute ('value ' ));
165+ $ checkboxes = new WebDriverCheckboxes (
166+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
167+ );
168+
169+ $ checkboxes ->selectByVisiblePartialText ($ text );
170+
171+ $ this ->assertSame ($ value , $ checkboxes ->getFirstSelectedOption ()->getAttribute ('value ' ));
145172 }
146173
147174 /**
@@ -157,51 +184,61 @@ public function selectByVisiblePartialTextDataProvider()
157184
158185 public function testDeselectAll ()
159186 {
160- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
187+ $ checkboxes = new WebDriverCheckboxes (
188+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
189+ );
161190
162- $ c ->selectByIndex (0 );
163- $ this ->assertCount (1 , $ c ->getAllSelectedOptions ());
164- $ c ->deselectAll ();
165- $ this ->assertEmpty ($ c ->getAllSelectedOptions ());
191+ $ checkboxes ->selectByIndex (0 );
192+ $ this ->assertCount (1 , $ checkboxes ->getAllSelectedOptions ());
193+ $ checkboxes ->deselectAll ();
194+ $ this ->assertEmpty ($ checkboxes ->getAllSelectedOptions ());
166195 }
167196
168197 public function testDeselectByIndex ()
169198 {
170- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
199+ $ checkboxes = new WebDriverCheckboxes (
200+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
201+ );
171202
172- $ c ->selectByIndex (0 );
173- $ this ->assertCount (1 , $ c ->getAllSelectedOptions ());
174- $ c ->deselectByIndex (0 );
175- $ this ->assertEmpty ($ c ->getAllSelectedOptions ());
203+ $ checkboxes ->selectByIndex (0 );
204+ $ this ->assertCount (1 , $ checkboxes ->getAllSelectedOptions ());
205+ $ checkboxes ->deselectByIndex (0 );
206+ $ this ->assertEmpty ($ checkboxes ->getAllSelectedOptions ());
176207 }
177208
178209 public function testDeselectByValue ()
179210 {
180- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
211+ $ checkboxes = new WebDriverCheckboxes (
212+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
213+ );
181214
182- $ c ->selectByValue ('j2a ' );
183- $ this ->assertCount (1 , $ c ->getAllSelectedOptions ());
184- $ c ->deselectByValue ('j2a ' );
185- $ this ->assertEmpty ($ c ->getAllSelectedOptions ());
215+ $ checkboxes ->selectByValue ('j2a ' );
216+ $ this ->assertCount (1 , $ checkboxes ->getAllSelectedOptions ());
217+ $ checkboxes ->deselectByValue ('j2a ' );
218+ $ this ->assertEmpty ($ checkboxes ->getAllSelectedOptions ());
186219 }
187220
188221 public function testDeselectByVisibleText ()
189222 {
190- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
223+ $ checkboxes = new WebDriverCheckboxes (
224+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
225+ );
191226
192- $ c ->selectByVisibleText ('J 2 B ' );
193- $ this ->assertCount (1 , $ c ->getAllSelectedOptions ());
194- $ c ->deselectByVisibleText ('J 2 B ' );
195- $ this ->assertEmpty ($ c ->getAllSelectedOptions ());
227+ $ checkboxes ->selectByVisibleText ('J 2 B ' );
228+ $ this ->assertCount (1 , $ checkboxes ->getAllSelectedOptions ());
229+ $ checkboxes ->deselectByVisibleText ('J 2 B ' );
230+ $ this ->assertEmpty ($ checkboxes ->getAllSelectedOptions ());
196231 }
197232
198233 public function testDeselectByVisiblePartialText ()
199234 {
200- $ c = new WebDriverCheckboxes ($ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' )));
235+ $ checkboxes = new WebDriverCheckboxes (
236+ $ this ->driver ->findElement (WebDriverBy::xpath ('//input[@type="checkbox"] ' ))
237+ );
201238
202- $ c ->selectByVisiblePartialText ('2C ' );
203- $ this ->assertCount (1 , $ c ->getAllSelectedOptions ());
204- $ c ->deselectByVisiblePartialText ('2C ' );
205- $ this ->assertEmpty ($ c ->getAllSelectedOptions ());
239+ $ checkboxes ->selectByVisiblePartialText ('2C ' );
240+ $ this ->assertCount (1 , $ checkboxes ->getAllSelectedOptions ());
241+ $ checkboxes ->deselectByVisiblePartialText ('2C ' );
242+ $ this ->assertEmpty ($ checkboxes ->getAllSelectedOptions ());
206243 }
207244}
0 commit comments