]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/PHPUnit/Tests/Extensions/SeleniumTestCaseTest.php
Added unit tests.
[Github/sugarcrm.git] / tests / PHPUnit / Tests / Extensions / SeleniumTestCaseTest.php
1 <?php
2 /**
3  * PHPUnit
4  *
5  * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  *   * Redistributions of source code must retain the above copyright
13  *     notice, this list of conditions and the following disclaimer.
14  *
15  *   * Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in
17  *     the documentation and/or other materials provided with the
18  *     distribution.
19  *
20  *   * Neither the name of Sebastian Bergmann nor the names of his
21  *     contributors may be used to endorse or promote products derived
22  *     from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * @category   Testing
38  * @package    PHPUnit
39  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40  * @author     Shin Ohno <ganchiku@gmail.com>
41  * @copyright  2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
42  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
43
44  * @link       http://www.phpunit.de/
45  * @since      File available since Release 3.0.0
46  */
47
48 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
49
50 /**
51  * Tests for PHPUnit_Extensions_SeleniumTestCase.
52  *
53  * @category   Testing
54  * @package    PHPUnit
55  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
56  * @author     Shin Ohno <ganchiku@gmail.com>
57  * @copyright  2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
58  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
59  * @version    Release: 3.3.17
60  * @link       http://www.phpunit.de/
61  * @since      Class available since Release 3.0.0
62  */
63 class Extensions_SeleniumTestCaseTest extends PHPUnit_Extensions_SeleniumTestCase
64 {
65     protected $url;
66
67     public function setUp()
68     {
69         if (!isset($GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_ENABLED']) ||
70             !$GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_ENABLED']) {
71             $this->markTestSkipped(
72               'The Selenium tests are disabled.'
73             );
74         }
75
76         $this->url = sprintf(
77           'http://%s:%d/selenium-server/tests/',
78           $GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST'],
79           $GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT']
80         );
81
82         $this->setHost($GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST']);
83         $this->setPort((int)$GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT']);
84         $this->setBrowser($GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_BROWSER']);
85         $this->setBrowserUrl($this->url);
86     }
87
88     public function testOpen()
89     {
90         $this->open($this->url . 'html/test_open.html');
91         $this->assertEndsWith('html/test_open.html', $this->getLocation());
92         $this->assertEquals('This is a test of the open command.', $this->getBodyText());
93
94         $this->open($this->url . 'html/test_page.slow.html');
95         $this->assertEndsWith('html/test_page.slow.html', $this->getLocation());
96         $this->assertEquals('Slow Loading Page', $this->getTitle());
97     }
98
99     public function testClick()
100     {
101         $this->open($this->url . 'html/test_click_page1.html');
102         $this->assertEquals('Click here for next page', $this->getText('link'));
103         $this->click('link');
104         $this->waitForPageToLoad(500);
105         $this->assertEquals('Click Page Target', $this->getTitle());
106         $this->click('previousPage');
107         $this->waitForPageToLoad(500);
108         $this->assertEquals('Click Page 1', $this->getTitle());
109
110         $this->click('linkWithEnclosedImage');
111         $this->waitForPageToLoad(500);
112         $this->assertEquals('Click Page Target', $this->getTitle());
113         $this->click('previousPage');
114         $this->waitForPageToLoad(500);
115
116         $this->click('enclosedImage');
117         $this->waitForPageToLoad(500);
118         $this->assertEquals('Click Page Target', $this->getTitle());
119         $this->click('previousPage');
120         $this->waitForPageToLoad(500);
121
122         $this->click('linkToAnchorOnThisPage');
123         $this->assertEquals('Click Page 1', $this->getTitle());
124         $this->click('linkWithOnclickReturnsFalse');
125         $this->assertEquals('Click Page 1', $this->getTitle());
126
127     }
128
129     public function testClickJavaScriptHref()
130     {
131         $this->open($this->url . 'html/test_click_javascript_page.html');
132         $this->click('link');
133         $this->assertTrue($this->isAlertPresent());
134         $this->assertEquals('link clicked: foo', $this->getAlert());
135
136         $this->click('linkWithMultipleJavascriptStatements');
137         $this->assertEquals('alert1', $this->getAlert());
138         $this->assertEquals('alert2', $this->getAlert());
139         $this->assertEquals('alert3', $this->getAlert());
140
141         $this->click('linkWithJavascriptVoidHref');
142         $this->assertEquals('onclick', $this->getAlert());
143         $this->assertEquals('Click Page 1', $this->getTitle());
144
145         $this->click('linkWithOnclickReturnsFalse');
146         $this->assertEquals('Click Page 1', $this->getTitle());
147
148         $this->click('enclosedImage');
149         $this->assertEquals('enclosedImage clicked', $this->getAlert());
150     }
151
152     public function testType()
153     {
154         $this->open($this->url . 'html/test_type_page1.html');
155         $this->type('username', 'TestUser');
156         $this->assertEquals('TestUser', $this->getValue('username'));
157         $this->type('password', 'testUserPassword');
158         $this->assertEquals('testUserPassword', $this->getValue('password'));
159
160         $this->click('submitButton');
161         $this->waitForPageToLoad(500);
162         $this->assertRegExp('/Welcome, TestUser!/', $this->getText('//h2'));
163     }
164
165     public function testSelect()
166     {
167         $this->open($this->url . 'html/test_select.html');
168         $this->assertEquals('Second Option', $this->getSelectedLabel('theSelect'));
169         $this->assertEquals('option2', $this->getSelectedValue('theSelect'));
170
171         $this->select('theSelect', 'index=4');
172         $this->assertEquals('Fifth Option', $this->getSelectedLabel('theSelect'));
173         $this->assertEquals('o4', $this->getSelectedId('theSelect'));
174
175         $this->select('theSelect', 'Third Option');
176         $this->assertEquals('Third Option', $this->getSelectedLabel('theSelect'));
177
178         $this->select('theSelect', 'label=Fourth Option');
179         $this->assertEquals('Fourth Option', $this->getSelectedLabel('theSelect'));
180
181         $this->select('theSelect', 'value=option6');
182         $this->assertEquals('Sixth Option', $this->getSelectedLabel('theSelect'));
183
184         $this->select('theSelect', 'value=');
185         $this->assertEquals('Empty Value Option', $this->getSelectedLabel('theSelect'));
186
187         $this->select('theSelect', 'id=o4');
188         $this->assertEquals('Fourth Option', $this->getSelectedLabel('theSelect'));
189
190         $this->select('theSelect', '');
191         $this->assertEquals('', $this->getSelectedLabel('theSelect'));
192
193     }
194
195     public function testMultiSelect()
196     {
197         $this->open($this->url . 'html/test_multiselect.html');
198         $this->assertEquals('Second Option', $this->getSelectedLabel('theSelect'));
199
200         $this->select('theSelect', 'index=4');
201         $this->assertEquals('Fifth Option', $this->getSelectedLabel('theSelect'));
202
203         $this->addSelection('theSelect', 'Third Option');
204         $this->addSelection('theSelect', 'value=');
205         $this->assertTrue(in_array('Third Option', $this->getSelectedLabels('theSelect')));
206         $this->assertTrue(in_array('Fifth Option', $this->getSelectedLabels('theSelect')));
207         $this->assertTrue(in_array('Empty Value Option', $this->getSelectedLabels('theSelect')));
208         $this->assertEquals(3, count($this->getSelectedLabels('theSelect')));
209
210         $this->removeSelection('theSelect', 'id=o7');
211         $this->assertFalse(in_array('Empty Value Option', $this->getSelectedLabels('theSelect')));
212         $this->assertEquals(2, count($this->getSelectedLabels('theSelect')));
213
214         $this->removeSelection('theSelect', 'label=Fifth Option');
215         $this->assertFalse(in_array('Fifth Option', $this->getSelectedLabels('theSelect')));
216         $this->assertEquals(1, count($this->getSelectedLabels('theSelect')));
217
218         $this->addSelection('theSelect', '');
219         $this->assertEquals(2, count($this->getSelectedLabels('theSelect')));
220     }
221
222     public function testSubmit()
223     {
224         $this->open($this->url . 'html/test_submit.html');
225         $this->submit('searchForm');
226         $this->assertTrue($this->isAlertPresent());
227         $this->assertEquals('onsubmit called', $this->getAlert());
228
229         $this->check('okayToSubmit');
230         $this->submit('searchForm');
231         $this->assertEquals('onsubmit called', $this->getAlert());
232         $this->assertEquals('form submitted', $this->getAlert());
233     }
234
235     public function testCheckUncheck()
236     {
237         $this->open($this->url . 'html/test_check_uncheck.html');
238         $this->assertEquals('on', $this->getValue('base-spud'));
239         $this->assertNotEquals('on', $this->getValue('base-rice'));
240         $this->assertEquals('on', $this->getValue('option-cheese'));
241         $this->assertNotEquals('on', $this->getValue('option-onions'));
242
243         $this->check('base-rice');
244         $this->assertNotEquals('on', $this->getValue('base-spud'));
245         $this->assertEquals('on', $this->getValue('base-rice'));
246         $this->uncheck('option-cheese');
247         $this->assertEquals('off', $this->getValue('option-cheese'));
248         $this->check('option-onions');
249         $this->assertNotEquals('off', $this->getValue('option-onions'));
250
251         $this->assertNotEquals('on', $this->getValue('option-chilli'));
252         $this->check('option-chilli');
253         $this->assertEquals('on', $this->getValue('option-chilli'));
254         $this->uncheck('option index=3');
255         $this->assertNotEquals('on', $this->getValue('option-chilli'));
256     }
257
258     public function testSelectWindow()
259     {
260         $this->open($this->url . 'html/test_select_window.html');
261         $this->click('popupPage');
262         $this->waitForPopUp('myPopupWindow', 1000);
263         $this->selectWindow('myPopupWindow');
264         $this->assertEndsWith('html/test_select_window_popup.html', $this->getLocation());
265         $this->assertEquals('Select Window Popup', $this->getTitle());
266         $this->close();
267         $this->selectWindow('null');
268
269         $this->assertEndsWith('html/test_select_window.html', $this->getLocation());
270         $this->click('popupPage');
271         $this->waitForPopUp('myNewWindow', 1000);
272         $this->selectWindow('myNewWindow');
273         $this->assertEndsWith('html/test_select_window_popup.html', $this->getLocation());
274         $this->close();
275         $this->selectWindow('null');
276
277         $this->click('popupAnonymous');
278         $this->waitForPopUp('anonymouspopup', 1000);
279         $this->selectWindow('anonymouspopup');
280         $this->assertEndsWith('html/test_select_window_popup.html', $this->getLocation());
281         $this->click('closePage');
282     }
283
284     public function testJavaScriptParameters()
285     {
286         $this->open($this->url . 'html/test_store_value.html');
287         $this->type('theText', "javascript{[1,2,3,4,5].join(':')}");
288         $this->assertEquals('1:2:3:4:5', $this->getValue('theText'));
289
290         $this->type('theText', 'javascript{10 * 5}');
291         $this->assertEquals('50', $this->getValue('theText'));
292     }
293
294     public function testWait()
295     {
296         $this->open($this->url . 'html/test_reload_onchange_page.html');
297         $this->select('theSelect', 'Second Option');
298         $this->waitForPageToLoad(5000);
299         $this->assertEquals('Slow Loading Page', $this->getTitle());
300         $this->goBack();
301         $this->waitForPageToLoad(5000);
302
303         $this->type('theTextbox', 'new value');
304         $this->fireEvent('theTextbox', 'blur');
305         $this->waitForPageToLoad(5000);
306         $this->assertEquals('Slow Loading Page', $this->getTitle());
307
308         $this->goBack();
309         $this->waitForPageToLoad(5000);
310
311         $this->click('theSubmit');
312         $this->waitForPageToLoad(5000);
313         $this->assertEquals('Slow Loading Page', $this->getTitle());
314
315         $this->click('slowPage_reload');
316         $this->waitForPageToLoad(5000);
317         $this->assertEquals('Slow Loading Page', $this->getTitle());
318     }
319
320     public function testWaitInPopupWindow()
321     {
322         $this->open($this->url . 'html/test_select_window.html');
323         $this->click('popupPage');
324         $this->waitForPopUp('myPopupWindow', 500);
325         $this->selectWindow('myPopupWindow');
326         $this->assertEquals('Select Window Popup', $this->getTitle());
327
328         $this->setTimeout(2000);
329         $this->click('link=Click to load new page');
330         // XXX NEED TO CHECK
331         $this->waitForPageToLoad(2000);
332         $this->assertEquals('Reload Page', $this->getTitle());
333
334         $this->setTimeout(30000);
335         $this->click('link=Click here');
336         // XXX NEED TO CHECK
337         $this->waitForPageToLoad(30000);
338         $this->assertEquals('Slow Loading Page', $this->getTitle());
339
340         $this->close();
341         $this->selectWindow('null');
342     }
343
344     public function testLocators()
345     {
346         $this->open($this->url . 'html/test_locators.html');
347         $this->assertEquals('this is the first element', $this->getText('id=id1'));
348         $this->assertFalse($this->isElementPresent('id=name1'));
349         $this->assertFalse($this->isElementPresent('id=id4'));
350         $this->assertEquals('a1', $this->getAttribute('id=id1@class'));
351
352         $this->assertEquals('this is the second element', $this->getText('name=name1'));
353         $this->assertFalse($this->isElementPresent('name=id1'));
354         $this->assertFalse($this->isElementPresent('name=notAName'));
355         $this->assertEquals('a2', $this->getAttribute('name=name1@class'));
356
357         $this->assertEquals('this is the first element', $this->getText('identifier=id1'));
358         $this->assertFalse($this->isElementPresent('identifier=id4'));
359         $this->assertEquals('a1', $this->getAttribute('identifier=id1@class'));
360         $this->assertEquals('this is the second element', $this->getText('identifier=name1'));
361         $this->assertEquals('a2', $this->getAttribute('identifier=name1@class'));
362
363         $this->assertEquals('this is the second element', $this->getText('dom=document.links[1]'));
364         $this->assertEquals('a2', $this->getAttribute('dom=document.links[1]@class'));
365         $this->assertFalse($this->isElementPresent('dom=document.links[9]'));
366         $this->assertFalse($this->isElementPresent('dom=foo'));
367     }
368
369     public function testImplicitLocators()
370     {
371         $this->open($this->url . 'html/test_locators.html');
372         $this->assertEquals('this is the first element', $this->getText('id1'));
373         $this->assertEquals('a1', $this->getAttribute('id1@class'));
374
375         $this->assertEquals('this is the second element', $this->getText('name1'));
376         $this->assertEquals('a2', $this->getAttribute('name1@class'));
377
378         $this->assertEquals('this is the second element', $this->getText('document.links[1]'));
379         $this->assertEquals('a2', $this->getAttribute('document.links[1]@class'));
380
381         $this->assertEquals('this is the second element', $this->getText('//body/a[2]'));
382     }
383
384     public function testXPathLocators()
385     {
386         $this->open($this->url . 'html/test_locators.html');
387         $this->assertEquals('this is the first element', $this->getText('xpath=//a'));
388         $this->assertEquals('this is the second element', $this->getText("xpath=//a[@class='a2']"));
389         $this->assertEquals('this is the second element', $this->getText("xpath=//*[@class='a2']"));
390         $this->assertEquals('this is the second element', $this->getText('xpath=//a[2]'));
391         $this->assertFalse($this->isElementPresent("xpath=//a[@href='foo']"));
392
393         $this->assertEquals('a1', $this->getAttribute("xpath=//a[contains(@href, '#id1')]/@class"));
394         $this->assertTrue($this->isElementPresent("//a[text()='this is the second element']"));
395
396         $this->assertEquals('this is the first element', $this->getText('xpath=//a'));
397         $this->assertEquals('a1', $this->getAttribute("//a[contains(@href, '#id1')]/@class"));
398
399         $this->assertEquals('theCellText', $this->getText("xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td"));
400
401         $this->click("//input[@name='name2' and @value='yes']");
402     }
403
404     public function testGoBack()
405     {
406         $this->open($this->url . 'html/test_click_page1.html');
407         $this->assertEquals('Click Page 1', $this->getTitle());
408
409         $this->click('link');
410         $this->waitForPageToLoad(500);
411         $this->assertEquals('Click Page Target', $this->getTitle());
412
413         $this->goBack();
414         $this->waitForPageToLoad(500);
415         $this->assertEquals('Click Page 1', $this->getTitle());
416     }
417
418     public function testRefresh()
419     {
420         $this->open($this->url . 'html/test_page.slow.html');
421         $this->assertEndsWith('html/test_page.slow.html', $this->getLocation());
422         $this->assertEquals('Slow Loading Page', $this->getTitle());
423
424         $this->click('changeSpan');
425         $this->assertEquals('Changed the text', $this->getText('theSpan'));
426         $this->refresh();
427         $this->waitForPageToLoad(500);
428         $this->assertNotEquals('Changed the text', $this->getText('theSpan'));
429
430         $this->click('changeSpan');
431         $this->assertEquals('Changed the text', $this->getText('theSpan'));
432         $this->click('slowRefresh');
433     }
434
435     public function testLinkEvents()
436     {
437         $this->open($this->url . 'html/test_form_events.html');
438         $this->assertEquals('', $this->getValue('eventlog'));
439         $this->click('theLink');
440         $this->assertEquals('{focus(theLink)} {click(theLink)}', $this->getValue('eventlog'));
441         $this->assertEquals('link clicked', $this->getAlert());
442         $this->click('theButton');
443     }
444
445     public function testButtonEvents()
446     {
447         $this->open($this->url . 'html/test_form_events.html');
448         $this->assertEquals('', $this->getValue('eventlog'));
449         $this->click('theButton');
450         $this->assertEquals('{focus(theButton)} {click(theButton)}', $this->getValue('eventlog'));
451         $this->type('eventlog', '');
452
453         $this->click('theSubmit');
454         $this->assertEquals('{focus(theSubmit)} {click(theSubmit)} {submit}', $this->getValue('eventlog'));
455
456     }
457
458     public function testSelectEvents()
459     {
460         $this->open($this->url . 'html/test_form_events.html');
461         $this->assertEquals('', $this->getValue('theSelect'));
462         $this->assertEquals('', $this->getValue('eventlog'));
463
464         $this->select('theSelect', 'First Option');
465         $this->assertEquals('option1', $this->getValue('theSelect'));
466         $this->assertEquals('{focus(theSelect)} {change(theSelect)}', $this->getValue('eventlog'));
467
468         $this->type('eventlog', '');
469         $this->select('theSelect', 'First Option');
470         $this->assertEquals('option1', $this->getValue('theSelect'));
471         $this->assertEquals('{focus(theSelect)}', $this->getValue('eventlog'));
472
473         $this->type('eventlog', '');
474         $this->select('theSelect', 'Empty Option');
475         $this->assertEquals('', $this->getValue('theSelect'));
476         $this->assertEquals('{focus(theSelect)} {change(theSelect)}', $this->getValue('eventlog'));
477
478     }
479
480     public function testRadioEvents()
481     {
482         $this->open($this->url . 'html/test_form_events.html');
483         $this->assertEquals('off', $this->getValue('theRadio1'));
484         $this->assertEquals('off', $this->getValue('theRadio2'));
485         $this->assertEquals('', $this->getValue('eventlog'));
486
487         $this->click('theRadio1');
488         $this->assertEquals('on', $this->getValue('theRadio1'));
489         $this->assertEquals('off', $this->getValue('theRadio2'));
490         $this->assertEquals('{focus(theRadio1)} {click(theRadio1)} {change(theRadio1)}', $this->getValue('eventlog'));
491
492         $this->type('eventlog', '');
493         $this->click('theRadio2');
494         $this->assertEquals('off', $this->getValue('theRadio1'));
495         $this->assertEquals('on', $this->getValue('theRadio2'));
496         $this->assertEquals('{focus(theRadio2)} {click(theRadio2)} {change(theRadio2)}', $this->getValue('eventlog'));
497
498
499         $this->type('eventlog', '');
500         $this->click('theRadio2');
501         $this->assertEquals('off', $this->getValue('theRadio1'));
502         $this->assertEquals('on', $this->getValue('theRadio2'));
503         $this->assertEquals('{focus(theRadio2)} {click(theRadio2)}', $this->getValue('eventlog'));
504     }
505
506     public function testCheckboxEvents()
507     {
508         $this->open($this->url . 'html/test_form_events.html');
509         $this->assertEquals('off', $this->getValue('theCheckbox'));
510         $this->assertEquals('', $this->getValue('eventlog'));
511
512         $this->click('theCheckbox');
513         $this->assertEquals('on', $this->getValue('theCheckbox'));
514         $this->assertEquals('{focus(theCheckbox)} {click(theCheckbox)} {change(theCheckbox)}', $this->getValue('eventlog'));
515
516         $this->type('eventlog', '');
517         $this->click('theCheckbox');
518         $this->assertEquals('off', $this->getValue('theCheckbox'));
519         $this->assertEquals('{focus(theCheckbox)} {click(theCheckbox)} {change(theCheckbox)}', $this->getValue('eventlog'));
520     }
521
522     public function testTextEvents()
523     {
524         $this->open($this->url . 'html/test_form_events.html');
525         $this->assertEquals('', $this->getValue('theTextbox'));
526         $this->assertEquals('', $this->getValue('eventlog'));
527
528         $this->type('theTextbox', 'first value');
529         $this->assertEquals('first value', $this->getValue('theTextbox'));
530         $this->assertEquals('{focus(theTextbox)} {select(theTextbox)} {change(theTextbox)}', $this->getValue('eventlog'));
531
532         $this->type('eventlog', '');
533         $this->type('theTextbox', 'changed value');
534         $this->assertEquals('changed value', $this->getValue('theTextbox'));
535         $this->assertEquals('{focus(theTextbox)} {select(theTextbox)} {change(theTextbox)}', $this->getValue('eventlog'));
536     }
537
538     public function testFireEvents()
539     {
540         $this->open($this->url .'html/test_form_events.html');
541         $this->assertEquals('', $this->getValue('eventlog'));
542         $this->fireEvent('theTextbox', 'focus');
543         $this->assertEquals('{focus(theTextbox)}', $this->getValue('eventlog'));
544
545         $this->type('eventlog', '');
546         $this->fireEvent('theSelect', 'change');
547         $this->fireEvent('theSelect', 'blur');
548         $this->assertEquals('{change(theSelect)} {blur(theSelect)}', $this->getValue('eventlog'));
549
550         $this->type('theTextbox', 'changed value');
551     }
552
553     public function testMouseEvents()
554     {
555         $this->open($this->url . 'html/test_form_events.html');
556         $this->mouseOver('theTextbox');
557         $this->mouseOver('theButton');
558         $this->mouseDown('theTextbox');
559         $this->mouseDown('theButton');
560         $this->assertEquals('{mouseover(theTextbox)} {mouseover(theButton)} {mousedown(theTextbox)} {mousedown(theButton)}', $this->getValue('eventlog'));
561     }
562
563     public function testKeyEvents()
564     {
565         $this->open($this->url . 'html/test_form_events.html');
566         $this->keyPress('theTextbox', '119');
567         $this->keyPress('theTextbox', '115');
568         $this->keyUp('theTextbox', '44');
569         $this->keyDown('theTextbox', '98');
570         $this->assertEquals('{keypress(theTextbox - 119)} {keypress(theTextbox - 115)} {keyup(theTextbox - 44)} {keydown(theTextbox - 98)}', $this->getValue('eventlog'));
571     }
572
573     public function testFocusOnBlur()
574     {
575         $this->open($this->url . 'html/test_focus_on_blur.html');
576         $this->type('testInput', 'test');
577         $this->fireEvent('testInput', 'blur');
578         $this->assertEquals('Bad value', $this->getAlert());
579         $this->type('testInput', 'somethingelse');
580     }
581
582     public function testAlerts()
583     {
584         $this->open($this->url . 'html/test_verify_alert.html');
585         $this->assertFalse($this->isAlertPresent());
586
587         $this->click('oneAlert');
588         $this->assertTrue($this->isAlertPresent());
589         $this->assertEquals('Store Below 494 degrees K!', $this->getAlert());
590
591         $this->click('twoAlerts');
592         $this->assertEquals('Store Below 220 degrees C!', $this->getAlert());
593         $this->assertEquals('Store Below 429 degrees F!', $this->getAlert());
594         $this->click('alertAndLeave');
595         $this->waitForPageToLoad(500);
596         $this->assertEquals("I'm Melting! I'm Melting!", $this->getAlert());
597     }
598
599     public function testConfirmations()
600     {
601         $this->open($this->url . 'html/test_confirm.html');
602         $this->chooseCancelOnNextConfirmation();
603         $this->click('confirmAndLeave');
604         $this->assertTrue($this->isConfirmationPresent());
605         $this->assertEquals('You are about to go to a dummy page.', $this->getConfirmation());
606         $this->assertEquals('Test Confirm', $this->getTitle());
607
608         $this->click('confirmAndLeave');
609         $this->waitForPageToLoad(500);
610         $this->assertEquals('You are about to go to a dummy page.', $this->getConfirmation());
611         $this->assertEquals('Dummy Page', $this->getTitle());
612     }
613
614     public function testPrompt()
615     {
616         $this->open($this->url . 'html/test_prompt.html');
617         $this->assertFalse($this->isPromptPresent());
618
619         $this->click('promptAndLeave');
620         $this->assertTrue($this->isPromptPresent());
621         $this->assertEquals("Type 'yes' and click OK", $this->getPrompt());
622         $this->assertEquals('Test Prompt', $this->getTitle());
623         $this->answerOnNextPrompt('yes');
624         $this->click('promptAndLeave');
625
626         $this->waitForPageToLoad(500);
627         $this->assertEquals("Type 'yes' and click OK", $this->getPrompt());
628         $this->assertEquals('Dummy Page', $this->getTitle());
629     }
630
631     public function testVisibility()
632     {
633         $this->open($this->url . 'html/test_visibility.html');
634         $this->assertTrue($this->isVisible('visibleParagraph'));
635         $this->assertFalse($this->isVisible('hiddenParagraph'));
636         $this->assertFalse($this->isVisible('suppressedParagraph'));
637         $this->assertFalse($this->isVisible('classSuppressedParagraph'));
638         $this->assertFalse($this->isVisible('jsClassSuppressedParagraph'));
639         $this->assertFalse($this->isVisible('hiddenSubElement'));
640         $this->assertTrue($this->isVisible('visibleSubElement'));
641         $this->assertFalse($this->isVisible('suppressedSubElement'));
642         $this->assertFalse($this->isVisible('jsHiddenParagraph'));
643     }
644
645     public function testEditable()
646     {
647         $this->open($this->url . 'html/test_editable.html');
648         $this->assertTrue($this->isEditable('normal_text'));
649         $this->assertTrue($this->isEditable('normal_select'));
650         $this->assertFalse($this->isEditable('disabled_text'));
651         $this->assertFalse($this->isEditable('disabled_select'));
652     }
653
654     protected function assertEndsWith($substring, $actual)
655     {
656         $this->assertRegExp('/' . preg_quote($substring, '/') . '$/', $actual);
657     }
658 }
659 ?>