5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
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
44 * @link http://www.phpunit.de/
45 * @since File available since Release 3.0.0
48 require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
51 * Tests for PHPUnit_Extensions_SeleniumTestCase.
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
63 class Extensions_SeleniumTestCaseTest extends PHPUnit_Extensions_SeleniumTestCase
67 public function setUp()
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.'
77 'http://%s:%d/selenium-server/tests/',
78 $GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_HOST'],
79 $GLOBALS['PHPUNIT_TESTSUITE_EXTENSION_SELENIUM_PORT']
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);
88 public function testOpen()
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());
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());
99 public function testClick()
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());
110 $this->click('linkWithEnclosedImage');
111 $this->waitForPageToLoad(500);
112 $this->assertEquals('Click Page Target', $this->getTitle());
113 $this->click('previousPage');
114 $this->waitForPageToLoad(500);
116 $this->click('enclosedImage');
117 $this->waitForPageToLoad(500);
118 $this->assertEquals('Click Page Target', $this->getTitle());
119 $this->click('previousPage');
120 $this->waitForPageToLoad(500);
122 $this->click('linkToAnchorOnThisPage');
123 $this->assertEquals('Click Page 1', $this->getTitle());
124 $this->click('linkWithOnclickReturnsFalse');
125 $this->assertEquals('Click Page 1', $this->getTitle());
129 public function testClickJavaScriptHref()
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());
136 $this->click('linkWithMultipleJavascriptStatements');
137 $this->assertEquals('alert1', $this->getAlert());
138 $this->assertEquals('alert2', $this->getAlert());
139 $this->assertEquals('alert3', $this->getAlert());
141 $this->click('linkWithJavascriptVoidHref');
142 $this->assertEquals('onclick', $this->getAlert());
143 $this->assertEquals('Click Page 1', $this->getTitle());
145 $this->click('linkWithOnclickReturnsFalse');
146 $this->assertEquals('Click Page 1', $this->getTitle());
148 $this->click('enclosedImage');
149 $this->assertEquals('enclosedImage clicked', $this->getAlert());
152 public function testType()
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'));
160 $this->click('submitButton');
161 $this->waitForPageToLoad(500);
162 $this->assertRegExp('/Welcome, TestUser!/', $this->getText('//h2'));
165 public function testSelect()
167 $this->open($this->url . 'html/test_select.html');
168 $this->assertEquals('Second Option', $this->getSelectedLabel('theSelect'));
169 $this->assertEquals('option2', $this->getSelectedValue('theSelect'));
171 $this->select('theSelect', 'index=4');
172 $this->assertEquals('Fifth Option', $this->getSelectedLabel('theSelect'));
173 $this->assertEquals('o4', $this->getSelectedId('theSelect'));
175 $this->select('theSelect', 'Third Option');
176 $this->assertEquals('Third Option', $this->getSelectedLabel('theSelect'));
178 $this->select('theSelect', 'label=Fourth Option');
179 $this->assertEquals('Fourth Option', $this->getSelectedLabel('theSelect'));
181 $this->select('theSelect', 'value=option6');
182 $this->assertEquals('Sixth Option', $this->getSelectedLabel('theSelect'));
184 $this->select('theSelect', 'value=');
185 $this->assertEquals('Empty Value Option', $this->getSelectedLabel('theSelect'));
187 $this->select('theSelect', 'id=o4');
188 $this->assertEquals('Fourth Option', $this->getSelectedLabel('theSelect'));
190 $this->select('theSelect', '');
191 $this->assertEquals('', $this->getSelectedLabel('theSelect'));
195 public function testMultiSelect()
197 $this->open($this->url . 'html/test_multiselect.html');
198 $this->assertEquals('Second Option', $this->getSelectedLabel('theSelect'));
200 $this->select('theSelect', 'index=4');
201 $this->assertEquals('Fifth Option', $this->getSelectedLabel('theSelect'));
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')));
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')));
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')));
218 $this->addSelection('theSelect', '');
219 $this->assertEquals(2, count($this->getSelectedLabels('theSelect')));
222 public function testSubmit()
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());
229 $this->check('okayToSubmit');
230 $this->submit('searchForm');
231 $this->assertEquals('onsubmit called', $this->getAlert());
232 $this->assertEquals('form submitted', $this->getAlert());
235 public function testCheckUncheck()
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'));
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'));
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'));
258 public function testSelectWindow()
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());
267 $this->selectWindow('null');
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());
275 $this->selectWindow('null');
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');
284 public function testJavaScriptParameters()
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'));
290 $this->type('theText', 'javascript{10 * 5}');
291 $this->assertEquals('50', $this->getValue('theText'));
294 public function testWait()
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());
301 $this->waitForPageToLoad(5000);
303 $this->type('theTextbox', 'new value');
304 $this->fireEvent('theTextbox', 'blur');
305 $this->waitForPageToLoad(5000);
306 $this->assertEquals('Slow Loading Page', $this->getTitle());
309 $this->waitForPageToLoad(5000);
311 $this->click('theSubmit');
312 $this->waitForPageToLoad(5000);
313 $this->assertEquals('Slow Loading Page', $this->getTitle());
315 $this->click('slowPage_reload');
316 $this->waitForPageToLoad(5000);
317 $this->assertEquals('Slow Loading Page', $this->getTitle());
320 public function testWaitInPopupWindow()
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());
328 $this->setTimeout(2000);
329 $this->click('link=Click to load new page');
331 $this->waitForPageToLoad(2000);
332 $this->assertEquals('Reload Page', $this->getTitle());
334 $this->setTimeout(30000);
335 $this->click('link=Click here');
337 $this->waitForPageToLoad(30000);
338 $this->assertEquals('Slow Loading Page', $this->getTitle());
341 $this->selectWindow('null');
344 public function testLocators()
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'));
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'));
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'));
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'));
369 public function testImplicitLocators()
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'));
375 $this->assertEquals('this is the second element', $this->getText('name1'));
376 $this->assertEquals('a2', $this->getAttribute('name1@class'));
378 $this->assertEquals('this is the second element', $this->getText('document.links[1]'));
379 $this->assertEquals('a2', $this->getAttribute('document.links[1]@class'));
381 $this->assertEquals('this is the second element', $this->getText('//body/a[2]'));
384 public function testXPathLocators()
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']"));
393 $this->assertEquals('a1', $this->getAttribute("xpath=//a[contains(@href, '#id1')]/@class"));
394 $this->assertTrue($this->isElementPresent("//a[text()='this is the second element']"));
396 $this->assertEquals('this is the first element', $this->getText('xpath=//a'));
397 $this->assertEquals('a1', $this->getAttribute("//a[contains(@href, '#id1')]/@class"));
399 $this->assertEquals('theCellText', $this->getText("xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td"));
401 $this->click("//input[@name='name2' and @value='yes']");
404 public function testGoBack()
406 $this->open($this->url . 'html/test_click_page1.html');
407 $this->assertEquals('Click Page 1', $this->getTitle());
409 $this->click('link');
410 $this->waitForPageToLoad(500);
411 $this->assertEquals('Click Page Target', $this->getTitle());
414 $this->waitForPageToLoad(500);
415 $this->assertEquals('Click Page 1', $this->getTitle());
418 public function testRefresh()
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());
424 $this->click('changeSpan');
425 $this->assertEquals('Changed the text', $this->getText('theSpan'));
427 $this->waitForPageToLoad(500);
428 $this->assertNotEquals('Changed the text', $this->getText('theSpan'));
430 $this->click('changeSpan');
431 $this->assertEquals('Changed the text', $this->getText('theSpan'));
432 $this->click('slowRefresh');
435 public function testLinkEvents()
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');
445 public function testButtonEvents()
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', '');
453 $this->click('theSubmit');
454 $this->assertEquals('{focus(theSubmit)} {click(theSubmit)} {submit}', $this->getValue('eventlog'));
458 public function testSelectEvents()
460 $this->open($this->url . 'html/test_form_events.html');
461 $this->assertEquals('', $this->getValue('theSelect'));
462 $this->assertEquals('', $this->getValue('eventlog'));
464 $this->select('theSelect', 'First Option');
465 $this->assertEquals('option1', $this->getValue('theSelect'));
466 $this->assertEquals('{focus(theSelect)} {change(theSelect)}', $this->getValue('eventlog'));
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'));
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'));
480 public function testRadioEvents()
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'));
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'));
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'));
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'));
506 public function testCheckboxEvents()
508 $this->open($this->url . 'html/test_form_events.html');
509 $this->assertEquals('off', $this->getValue('theCheckbox'));
510 $this->assertEquals('', $this->getValue('eventlog'));
512 $this->click('theCheckbox');
513 $this->assertEquals('on', $this->getValue('theCheckbox'));
514 $this->assertEquals('{focus(theCheckbox)} {click(theCheckbox)} {change(theCheckbox)}', $this->getValue('eventlog'));
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'));
522 public function testTextEvents()
524 $this->open($this->url . 'html/test_form_events.html');
525 $this->assertEquals('', $this->getValue('theTextbox'));
526 $this->assertEquals('', $this->getValue('eventlog'));
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'));
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'));
538 public function testFireEvents()
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'));
545 $this->type('eventlog', '');
546 $this->fireEvent('theSelect', 'change');
547 $this->fireEvent('theSelect', 'blur');
548 $this->assertEquals('{change(theSelect)} {blur(theSelect)}', $this->getValue('eventlog'));
550 $this->type('theTextbox', 'changed value');
553 public function testMouseEvents()
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'));
563 public function testKeyEvents()
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'));
573 public function testFocusOnBlur()
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');
582 public function testAlerts()
584 $this->open($this->url . 'html/test_verify_alert.html');
585 $this->assertFalse($this->isAlertPresent());
587 $this->click('oneAlert');
588 $this->assertTrue($this->isAlertPresent());
589 $this->assertEquals('Store Below 494 degrees K!', $this->getAlert());
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());
599 public function testConfirmations()
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());
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());
614 public function testPrompt()
616 $this->open($this->url . 'html/test_prompt.html');
617 $this->assertFalse($this->isPromptPresent());
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');
626 $this->waitForPageToLoad(500);
627 $this->assertEquals("Type 'yes' and click OK", $this->getPrompt());
628 $this->assertEquals('Dummy Page', $this->getTitle());
631 public function testVisibility()
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'));
645 public function testEditable()
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'));
654 protected function assertEndsWith($substring, $actual)
656 $this->assertRegExp('/' . preg_quote($substring, '/') . '$/', $actual);