1<?php 2 3// To run this test, You need to install PHPUnit and Selenium RC Server 4// Selenium RC Server is available the following website. 5// http://openqa.org/selenium-rc/ 6//error_reporting(E_ALL|E_STRICT); 7 8require_once 'Testing/Selenium.php'; 9require_once 'PHPUnit/Framework/TestCase.php'; 10 11class SeleniumTest extends PHPUnit_Framework_TestCase 12{ 13 private $selenium; 14 15 public function __construct() 16 { 17 $this->browserUrl = "http://localhost:4444/selenium-server/tests/"; 18 parent::__construct(); 19 } 20 21 public function assertEndsWith($substring, $actual) 22 { 23 $this->assertRegExp("/".preg_quote($substring, "/")."$/", $actual); 24 } 25// {{{ setUp and tearDown 26 public function setUp() 27 { 28 $errno = null; 29 $errstr = null; 30 $resource = @fsockopen('127.0.0.1', 4444, $errno, $errstr, 10); 31 if (!$resource) { 32 $this->markTestSkipped($errstr); 33 } else { 34 fclose($resource); 35 } 36 try { 37 $this->selenium = new Testing_Selenium("*firefox", $this->browserUrl); 38 $this->selenium->start(); 39 } catch (Testing_Selenium_Exception $e) { 40 $this->selenium->stop(); 41 echo $e; 42 } 43 } 44 45 public function tearDown() 46 { 47 if (isset($this->selenium)) { 48 try { 49 $this->selenium->stop(); 50 } catch (Testing_Selenium_Exception $e) { 51 echo $e; 52 } 53 } 54 } 55 // }}} 56 // {{{ testOpen 57 public function testOpen() 58 { 59 $this->selenium->open($this->browserUrl . "html/test_open.html"); 60 $this->assertEndsWith("html/test_open.html", $this->selenium->getLocation()); 61 $this->assertEquals("This is a test of the open command.", $this->selenium->getBodyText()); 62 63 $this->selenium->open($this->browserUrl . "html/test_page.slow.html"); 64 $this->assertEndsWith("html/test_page.slow.html", $this->selenium->getLocation()); 65 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 66 } 67 // }}} 68 // {{{ testClick 69 public function testClick() 70 { 71 $this->selenium->open($this->browserUrl . "html/test_click_page1.html"); 72 $this->assertEquals("Click here for next page", $this->selenium->getText("link")); 73 $this->selenium->click("link"); 74 $this->selenium->waitForPageToLoad(500); 75 $this->assertEquals("Click Page Target", $this->selenium->getTitle()); 76 $this->selenium->click("previousPage"); 77 $this->selenium->waitForPageToLoad(500); 78 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 79 80 $this->selenium->click("linkWithEnclosedImage"); 81 $this->selenium->waitForPageToLoad(500); 82 $this->assertEquals("Click Page Target", $this->selenium->getTitle()); 83 $this->selenium->click("previousPage"); 84 $this->selenium->waitForPageToLoad(500); 85 86 $this->selenium->click("enclosedImage"); 87 $this->selenium->waitForPageToLoad(500); 88 $this->assertEquals("Click Page Target", $this->selenium->getTitle()); 89 $this->selenium->click("previousPage"); 90 $this->selenium->waitForPageToLoad(500); 91 92 $this->selenium->click("linkToAnchorOnThisPage"); 93 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 94 $this->selenium->click("linkWithOnclickReturnsFalse"); 95 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 96 97 } 98 // }}} 99/* 100 // {{{ testClickJavaScriptHref 101 public function testClickJavaScriptHref() 102 { 103 $this->selenium->open($this->browserUrl . "html/test_click_javascript_page.html"); 104 $this->selenium->click("link"); 105 $this->assertTrue($this->selenium->isAlertPresent()); 106 $this->assertEquals("link clicked: foo", $this->selenium->getAlert()); 107 108 $this->selenium->click("linkWithMultipleJavascriptStatements"); 109 $this->assertEquals("alert1", $this->selenium->getAlert()); 110 $this->assertEquals("alert2", $this->selenium->getAlert()); 111 $this->assertEquals("alert3", $this->selenium->getAlert()); 112 113 $this->selenium->click("linkWithJavascriptVoidHref"); 114 $this->assertEquals("onclick", $this->selenium->getAlert()); 115 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 116 117 $this->selenium->click("linkWithOnclickReturnsFalse"); 118 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 119 120 $this->selenium->click("enclosedImage"); 121 $this->assertEquals("enclosedImage clicked", $this->selenium->getAlert()); 122 } 123 // }}} 124 // {{{ testType 125 public function testType() 126 { 127 $this->selenium->open($this->browserUrl . "html/test_type_page1.html"); 128 $this->selenium->type("username", "TestUser"); 129 $this->assertEquals("TestUser", $this->selenium->getValue("username")); 130 $this->selenium->type("password", "testUserPassword"); 131 $this->assertEquals("testUserPassword", $this->selenium->getValue("password")); 132 133 $this->selenium->click("submitButton"); 134 $this->selenium->waitForPageToLoad(500); 135 $this->assertRegExp("/Welcome, TestUser!/", $this->selenium->getText("//h2")); 136 } 137 // }}} 138 // {{{ testSelect 139 public function testSelect() 140 { 141 $this->selenium->open($this->browserUrl . "html/test_select.html"); 142 $this->assertEquals("Second Option", $this->selenium->getSelectedLabel("theSelect")); 143 $this->assertEquals("option2", $this->selenium->getSelectedValue("theSelect")); 144 145 $this->selenium->select("theSelect", "index=4"); 146 $this->assertEquals("Fifth Option", $this->selenium->getSelectedLabel("theSelect")); 147 $this->assertEquals("o4", $this->selenium->getSelectedId("theSelect")); 148 149 $this->selenium->select("theSelect", "Third Option"); 150 $this->assertEquals("Third Option", $this->selenium->getSelectedLabel("theSelect")); 151 152 $this->selenium->select("theSelect", "label=Fourth Option"); 153 $this->assertEquals("Fourth Option", $this->selenium->getSelectedLabel("theSelect")); 154 155 $this->selenium->select("theSelect", "value=option6"); 156 $this->assertEquals("Sixth Option", $this->selenium->getSelectedLabel("theSelect")); 157 158 $this->selenium->select("theSelect", "value="); 159 $this->assertEquals("Empty Value Option", $this->selenium->getSelectedLabel("theSelect")); 160 161 $this->selenium->select("theSelect", "id=o4"); 162 $this->assertEquals("Fourth Option", $this->selenium->getSelectedLabel("theSelect")); 163 164 $this->selenium->select("theSelect", ""); 165 $this->assertEquals("", $this->selenium->getSelectedLabel("theSelect")); 166 167 } 168 // }}} 169 // {{{ testMultiSelect 170 public function testMultiSelect() 171 { 172 $this->selenium->open($this->browserUrl . "html/test_multiselect.html"); 173 $this->assertEquals("Second Option", $this->selenium->getSelectedLabel("theSelect")); 174 175 $this->selenium->select("theSelect", "index=4"); 176 $this->assertEquals("Fifth Option", $this->selenium->getSelectedLabel("theSelect")); 177 178 $this->selenium->addSelection("theSelect", "Third Option"); 179 $this->selenium->addSelection("theSelect", "value="); 180 $this->assertTrue(in_array("Third Option", $this->selenium->getSelectedLabels("theSelect"))); 181 $this->assertTrue(in_array("Fifth Option", $this->selenium->getSelectedLabels("theSelect"))); 182 $this->assertTrue(in_array("Empty Value Option", $this->selenium->getSelectedLabels("theSelect"))); 183 $this->assertEquals(3, count($this->selenium->getSelectedLabels("theSelect"))); 184 185 $this->selenium->removeSelection("theSelect", "id=o7"); 186 $this->assertFalse(in_array("Empty Value Option", $this->selenium->getSelectedLabels("theSelect"))); 187 $this->assertEquals(2, count($this->selenium->getSelectedLabels("theSelect"))); 188 189 $this->selenium->removeSelection("theSelect", "label=Fifth Option"); 190 $this->assertFalse(in_array("Fifth Option", $this->selenium->getSelectedLabels("theSelect"))); 191 $this->assertEquals(1, count($this->selenium->getSelectedLabels("theSelect"))); 192 193 $this->selenium->addSelection("theSelect", ""); 194 $this->assertEquals(2, count($this->selenium->getSelectedLabels("theSelect"))); 195 } 196 // }}} 197 // {{{ testSubmit 198 public function testSubmit() 199 { 200 $this->selenium->open($this->browserUrl . "html/test_submit.html"); 201 $this->selenium->submit("searchForm"); 202 $this->assertTrue($this->selenium->isAlertPresent()); 203 $this->assertEquals("onsubmit called", $this->selenium->getAlert()); 204 205 $this->selenium->check("okayToSubmit"); 206 $this->selenium->submit("searchForm"); 207 $this->assertEquals("onsubmit called", $this->selenium->getAlert()); 208 $this->assertEquals("form submitted", $this->selenium->getAlert()); 209 } 210 // }}} 211 // {{{ testCheckUncheck 212 public function testCheckUncheck() 213 { 214 $this->selenium->open($this->browserUrl . "html/test_check_uncheck.html"); 215 $this->assertEquals("on", $this->selenium->getValue("base-spud")); 216 $this->assertNotEquals("on", $this->selenium->getValue("base-rice")); 217 $this->assertEquals("on", $this->selenium->getValue("option-cheese")); 218 $this->assertNotEquals("on", $this->selenium->getValue("option-onions")); 219 220 $this->selenium->check("base-rice"); 221 $this->assertNotEquals("on", $this->selenium->getValue("base-spud")); 222 $this->assertEquals("on", $this->selenium->getValue("base-rice")); 223 $this->selenium->uncheck("option-cheese"); 224 $this->assertEquals("off", $this->selenium->getValue("option-cheese")); 225 $this->selenium->check("option-onions"); 226 $this->assertNotEquals("off", $this->selenium->getValue("option-onions")); 227 228 $this->assertNotEquals("on", $this->selenium->getValue("option-chilli")); 229 $this->selenium->check("option-chilli"); 230 $this->assertEquals("on", $this->selenium->getValue("option-chilli")); 231 $this->selenium->uncheck("option index=3"); 232 $this->assertNotEquals("on", $this->selenium->getValue("option-chilli")); 233 } 234 // }}} 235 // {{{ testSelectWindow 236 public function testSelectWidndow() 237 { 238 $this->selenium->open($this->browserUrl . "html/test_select_window.html"); 239 $this->selenium->click("popupPage"); 240 $this->selenium->waitForPopUp("myPopupWindow", 1000); 241 $this->selenium->selectWindow("myPopupWindow"); 242 $this->assertEndsWith("html/test_select_window_popup.html", $this->selenium->getLocation()); 243 $this->assertEquals("Select Window Popup", $this->selenium->getTitle()); 244 $this->selenium->close(); 245 $this->selenium->selectWindow("null"); 246 247 $this->assertEndsWith("html/test_select_window.html", $this->selenium->getLocation()); 248 $this->selenium->click("popupPage"); 249 $this->selenium->waitForPopUp("myNewWindow", 1000); 250 $this->selenium->selectWindow("myNewWindow"); 251 $this->assertEndsWith("html/test_select_window_popup.html", $this->selenium->getLocation()); 252 $this->selenium->close(); 253 $this->selenium->selectWindow("null"); 254 255 $this->selenium->click("popupAnonymous"); 256 $this->selenium->waitForPopUp("anonymouspopup", 1000); 257 $this->selenium->selectWindow("anonymouspopup"); 258 $this->assertEndsWith("html/test_select_window_popup.html", $this->selenium->getLocation()); 259 $this->selenium->click("closePage"); 260 261 } 262 // }}} 263 // {{{ testStore NO USE 264 // public function testStore() 265 // {} 266 // }}} 267 // {{{ testJavaScriptParameters 268 public function testJavaScriptParameters() 269 { 270 $this->selenium->open($this->browserUrl . "html/test_store_value.html"); 271 $this->selenium->type("theText", "javascript{[1,2,3,4,5].join(':')}"); 272 $this->assertEquals("1:2:3:4:5", $this->selenium->getValue("theText")); 273 274 $this->selenium->type("theText", "javascript{10 * 5}"); 275 $this->assertEquals("50", $this->selenium->getValue("theText")); 276 } 277 // }}} 278 // {{{ testPause NO USE 279 // public function testPause() 280 //{} 281 // }}} 282 // {{{ testWait 283 public function testWait() 284 { 285 $this->selenium->open($this->browserUrl . "html/test_reload_onchange_page.html"); 286 $this->selenium->select("theSelect", "Second Option"); 287 $this->selenium->waitForPageToLoad(5000); 288 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 289 $this->selenium->goBack(); 290 $this->selenium->waitForPageToLoad(5000); 291 292 $this->selenium->type("theTextbox", "new value"); 293 $this->selenium->fireEvent("theTextbox", "blur"); 294 $this->selenium->waitForPageToLoad(5000); 295 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 296 297 $this->selenium->goBack(); 298 $this->selenium->waitForPageToLoad(5000); 299 300 $this->selenium->click("theSubmit"); 301 $this->selenium->waitForPageToLoad(5000); 302 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 303 304 $this->selenium->click("slowPage_reload"); 305 $this->selenium->waitForPageToLoad(5000); 306 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 307 } 308 // }}} 309 310 // {{{ testWaitInPopupWindow 311 public function testWaitInPopupWindow() 312 { 313 $this->selenium->open($this->browserUrl . "html/test_select_window.html"); 314 $this->selenium->click("popupPage"); 315 $this->selenium->waitForPopUp("myPopupWindow", 500); 316 $this->selenium->selectWindow("myPopupWindow"); 317 $this->assertEquals("Select Window Popup", $this->selenium->getTitle()); 318 319 $this->selenium->setTimeout(2000); 320 $this->selenium->click("link=Click to load new page"); 321 // XXX NEED TO CHECK 322 $this->selenium->waitForPageToLoad(2000); 323 $this->assertEquals("Reload Page", $this->selenium->getTitle()); 324 325 $this->selenium->setTimeout(30000); 326 $this->selenium->click("link=Click here"); 327 // XXX NEED TO CHECK 328 $this->selenium->waitForPageToLoad(30000); 329 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 330 331 $this->selenium->close(); 332 $this->selenium->selectWindow("null"); 333 } 334 // }}} 335 336 // {{{ testWaitFor NOT USE 337 // public function testWaitFor() 338 // {} 339 // }}} 340 // {{{ testWaitForNot NOT USE 341 // public function testWaitForNot() 342 // {} 343 // }}} 344 // {{{ testVerification NO USE Maybe... 345 // public function testVerification() 346 //{} 347 // }}} 348 // {{{ testTextWhiteSpace NOT USE 349 //public function testTextWhiteSpace() 350 //{} 351 // }}} 352 // {{{ testPatternMatching NO USE 353 // public function testPatternMatching() 354 // {} 355 // }}} 356 // {{{ testLocators 357 public function testLocators() 358 { 359 $this->selenium->open($this->browserUrl . "html/test_locators.html"); 360 $this->assertEquals("this is the first element", $this->selenium->getText("id=id1")); 361 $this->assertFalse($this->selenium->isElementPresent("id=name1")); 362 $this->assertFalse($this->selenium->isElementPresent("id=id4")); 363 $this->assertEquals("a1", $this->selenium->getAttribute("id=id1@class")); 364 365 $this->assertEquals("this is the second element", $this->selenium->getText("name=name1")); 366 $this->assertFalse($this->selenium->isElementPresent("name=id1")); 367 $this->assertFalse($this->selenium->isElementPresent("name=notAName")); 368 $this->assertEquals("a2", $this->selenium->getAttribute("name=name1@class")); 369 370 $this->assertEquals("this is the first element", $this->selenium->getText("identifier=id1")); 371 $this->assertFalse($this->selenium->isElementPresent("identifier=id4")); 372 $this->assertEquals("a1", $this->selenium->getAttribute("identifier=id1@class")); 373 $this->assertEquals("this is the second element", $this->selenium->getText("identifier=name1")); 374 $this->assertEquals("a2", $this->selenium->getAttribute("identifier=name1@class")); 375 376 $this->assertEquals("this is the second element", $this->selenium->getText("dom=document.links[1]")); 377 $this->assertEquals("a2", $this->selenium->getAttribute("dom=document.links[1]@class")); 378 $this->assertFalse($this->selenium->isElementPresent("dom=document.links[9]")); 379 $this->assertFalse($this->selenium->isElementPresent("dom=foo")); 380 } 381 // }}} 382 // {{{ testImplicitLocators 383 public function testImplicitLocators() 384 { 385 $this->selenium->open($this->browserUrl . "html/test_locators.html"); 386 $this->assertEquals("this is the first element", $this->selenium->getText("id1")); 387 $this->assertEquals("a1", $this->selenium->getAttribute("id1@class")); 388 389 $this->assertEquals("this is the second element", $this->selenium->getText("name1")); 390 $this->assertEquals("a2", $this->selenium->getAttribute("name1@class")); 391 392 $this->assertEquals("this is the second element", $this->selenium->getText("document.links[1]")); 393 $this->assertEquals("a2", $this->selenium->getAttribute("document.links[1]@class")); 394 395 $this->assertEquals("this is the second element", $this->selenium->getText("//body/a[2]")); 396 } 397 // }}} 398 399 // {{{ testXPathLocators 400 public function testXPathLocators() 401 { 402 $this->selenium->open($this->browserUrl . "html/test_locators.html"); 403 $this->assertEquals("this is the first element", $this->selenium->getText("xpath=//a")); 404 $this->assertEquals("this is the second element", $this->selenium->getText("xpath=//a[@class='a2']")); 405 $this->assertEquals("this is the second element", $this->selenium->getText("xpath=//*[@class='a2']")); 406 $this->assertEquals("this is the second element", $this->selenium->getText("xpath=//a[2]")); 407 $this->assertFalse($this->selenium->isElementPresent("xpath=//a[@href='foo']")); 408 409 $this->assertEquals("a1", $this->selenium->getAttribute("xpath=//a[contains(@href, '#id1')]/@class")); 410 $this->assertTrue($this->selenium->isElementPresent("//a[text()='this is the second element']")); 411 412 $this->assertEquals("this is the first element", $this->selenium->getText("xpath=//a")); 413 $this->assertEquals("a1", $this->selenium->getAttribute("//a[contains(@href, '#id1')]/@class")); 414 415 $this->assertEquals("theCellText", $this->selenium->getText("xpath=(//table[@class='stylee'])//th[text()='theHeaderText']/../td")); 416 417 $this->selenium->click("//input[@name='name2' and @value='yes']"); 418 } 419 // }}} 420 421 // {{{ testGoBack 422 public function testGoBack() 423 { 424 $this->selenium->open($this->browserUrl . "html/test_click_page1.html"); 425 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 426 427 $this->selenium->click("link"); 428 $this->selenium->waitForPageToLoad(500); 429 $this->assertEquals("Click Page Target", $this->selenium->getTitle()); 430 431 $this->selenium->goBack(); 432 $this->selenium->waitForPageToLoad(500); 433 $this->assertEquals("Click Page 1", $this->selenium->getTitle()); 434 } 435 // }}} 436 // {{{ testRefresh 437 public function testRefresh() 438 { 439 $this->selenium->open($this->browserUrl . "html/test_page.slow.html"); 440 $this->assertEndsWith("html/test_page.slow.html", $this->selenium->getLocation()); 441 $this->assertEquals("Slow Loading Page", $this->selenium->getTitle()); 442 443 $this->selenium->click("changeSpan"); 444 $this->assertEquals("Changed the text", $this->selenium->getText("theSpan")); 445 $this->selenium->refresh(); 446 $this->selenium->waitForPageToLoad(500); 447 $this->assertNotEquals("Changed the text", $this->selenium->getText("theSpan")); 448 449 $this->selenium->click("changeSpan"); 450 $this->assertEquals("Changed the text", $this->selenium->getText("theSpan")); 451 $this->selenium->click("slowRefresh"); 452 // Does not work! 453 // $this->selenium->waitForPageToLoad(500); 454 // $this->assertNotEquals("Changed the text", $this->selenium->getText("theSpan")); 455 456 } 457 // }}} 458 // {{{ testCommenta NO USE 459 // public function testComments 460 //{} 461 // }}} 462 // {{{ testLinkEvents 463 public function testLinkEvents() 464 { 465 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 466 $this->assertEquals("", $this->selenium->getValue("eventlog")); 467 $this->selenium->click("theLink"); 468 $this->assertEquals("{focus(theLink)} {click(theLink)}", $this->selenium->getValue("eventlog")); 469 $this->assertEquals("link clicked", $this->selenium->getAlert()); 470 $this->selenium->click("theButton"); 471 } 472 // }}} 473 // {{{ testButtonEvents 474 public function testButtonEvents() 475 { 476 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 477 $this->assertEquals("", $this->selenium->getValue("eventlog")); 478 $this->selenium->click("theButton"); 479 $this->assertEquals("{focus(theButton)} {click(theButton)}", $this->selenium->getValue("eventlog")); 480 $this->selenium->type("eventlog", ""); 481 482 $this->selenium->click("theSubmit"); 483 $this->assertEquals("{focus(theSubmit)} {click(theSubmit)} {submit}", $this->selenium->getValue("eventlog")); 484 485 } 486 // }}} 487 // {{{ testSelectEvents 488 public function testSelectEvents() 489 { 490 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 491 $this->assertEquals("", $this->selenium->getValue("theSelect")); 492 $this->assertEquals("", $this->selenium->getValue("eventlog")); 493 494 $this->selenium->select("theSelect", "First Option"); 495 $this->assertEquals("option1", $this->selenium->getValue("theSelect")); 496 $this->assertEquals("{focus(theSelect)} {change(theSelect)}", $this->selenium->getValue("eventlog")); 497 498 $this->selenium->type("eventlog", ""); 499 $this->selenium->select("theSelect", "First Option"); 500 $this->assertEquals("option1", $this->selenium->getValue("theSelect")); 501 $this->assertEquals("{focus(theSelect)}", $this->selenium->getValue("eventlog")); 502 503 $this->selenium->type("eventlog", ""); 504 $this->selenium->select("theSelect", "Empty Option"); 505 $this->assertEquals("", $this->selenium->getValue("theSelect")); 506 $this->assertEquals("{focus(theSelect)} {change(theSelect)}", $this->selenium->getValue("eventlog")); 507 508 } 509 // }}} 510 // {{{ testRadioEvents 511 public function testRadioEvents() 512 { 513 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 514 $this->assertEquals("off", $this->selenium->getValue("theRadio1")); 515 $this->assertEquals("off", $this->selenium->getValue("theRadio2")); 516 $this->assertEquals("", $this->selenium->getValue("eventlog")); 517 518 $this->selenium->click("theRadio1"); 519 $this->assertEquals("on", $this->selenium->getValue("theRadio1")); 520 $this->assertEquals("off", $this->selenium->getValue("theRadio2")); 521 $this->assertEquals("{focus(theRadio1)} {click(theRadio1)} {change(theRadio1)}", $this->selenium->getValue("eventlog")); 522 523 $this->selenium->type("eventlog", ""); 524 $this->selenium->click("theRadio2"); 525 $this->assertEquals("off", $this->selenium->getValue("theRadio1")); 526 $this->assertEquals("on", $this->selenium->getValue("theRadio2")); 527 $this->assertEquals("{focus(theRadio2)} {click(theRadio2)} {change(theRadio2)}", $this->selenium->getValue("eventlog")); 528 529 530 $this->selenium->type("eventlog", ""); 531 $this->selenium->click("theRadio2"); 532 $this->assertEquals("off", $this->selenium->getValue("theRadio1")); 533 $this->assertEquals("on", $this->selenium->getValue("theRadio2")); 534 $this->assertEquals("{focus(theRadio2)} {click(theRadio2)}", $this->selenium->getValue("eventlog")); 535 } 536 // }}} 537 // {{{ testCheckboxEvents 538 public function testCheckboxEvents() 539 { 540 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 541 $this->assertEquals("off", $this->selenium->getValue("theCheckbox")); 542 $this->assertEquals("", $this->selenium->getValue("eventlog")); 543 544 $this->selenium->click("theCheckbox"); 545 $this->assertEquals("on", $this->selenium->getValue("theCheckbox")); 546 $this->assertEquals("{focus(theCheckbox)} {click(theCheckbox)} {change(theCheckbox)}", $this->selenium->getValue("eventlog")); 547 548 $this->selenium->type("eventlog", ""); 549 $this->selenium->click("theCheckbox"); 550 $this->assertEquals("off", $this->selenium->getValue("theCheckbox")); 551 $this->assertEquals("{focus(theCheckbox)} {click(theCheckbox)} {change(theCheckbox)}", $this->selenium->getValue("eventlog")); 552 } 553 // }}} 554 // {{{ testTextEvents 555 public function testTextEvents() 556 { 557 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 558 $this->assertEquals("", $this->selenium->getValue("theTextbox")); 559 $this->assertEquals("", $this->selenium->getValue("eventlog")); 560 561 $this->selenium->type("theTextbox", "first value"); 562 $this->assertEquals("first value", $this->selenium->getValue("theTextbox")); 563 $this->assertEquals("{focus(theTextbox)} {select(theTextbox)} {change(theTextbox)}", $this->selenium->getValue("eventlog")); 564 565 $this->selenium->type("eventlog", ""); 566 $this->selenium->type("theTextbox", "changed value"); 567 $this->assertEquals("changed value", $this->selenium->getValue("theTextbox")); 568 $this->assertEquals("{focus(theTextbox)} {select(theTextbox)} {change(theTextbox)}", $this->selenium->getValue("eventlog")); 569 } 570 // }}} 571 // {{{ testFireEvents 572 public function testFireEvents() 573 { 574 $this->selenium->open($this->browserUrl ."html/test_form_events.html"); 575 $this->assertEquals("", $this->selenium->getValue("eventlog")); 576 $this->selenium->fireEvent("theTextbox", "focus"); 577 $this->assertEquals("{focus(theTextbox)}", $this->selenium->getValue("eventlog")); 578 579 $this->selenium->type("eventlog", ""); 580 $this->selenium->fireEvent("theSelect", "change"); 581 $this->selenium->fireEvent("theSelect", "blur"); 582 $this->assertEquals("{change(theSelect)} {blur(theSelect)}", $this->selenium->getValue("eventlog")); 583 584 $this->selenium->type("theTextbox", "changed value"); 585 } 586 // }}} 587 // {{{ testMouseEvents 588 public function testMouseEvents() 589 { 590 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 591 $this->selenium->mouseOver("theTextbox"); 592 $this->selenium->mouseOver("theButton"); 593 $this->selenium->mouseDown("theTextbox"); 594 $this->selenium->mouseDown("theButton"); 595 $this->assertEquals("{mouseover(theTextbox)} {mouseover(theButton)} {mousedown(theTextbox)} {mousedown(theButton)}", $this->selenium->getValue("eventlog")); 596 } 597 // }}} 598 // {{{ testKeyEvents 599 public function testKeyEvents() 600 { 601 $this->selenium->open($this->browserUrl . "html/test_form_events.html"); 602 $this->selenium->keyPress("theTextbox", "119"); 603 $this->selenium->keyPress("theTextbox", "115"); 604 $this->selenium->keyUp("theTextbox", "44"); 605 $this->selenium->keyDown("theTextbox", "98"); 606 $this->assertEquals("{keypress(theTextbox - 119)} {keypress(theTextbox - 115)} {keyup(theTextbox - 44)} {keydown(theTextbox - 98)}", $this->selenium->getValue("eventlog")); 607 } 608 // }}} 609 // {{{ testFocusOnBlur 610 public function testFocusOnBlur() 611 { 612 $this->selenium->open($this->browserUrl . "html/test_focus_on_blur.html"); 613 $this->selenium->type("testInput", "test"); 614 $this->selenium->fireEvent("testInput", "blur"); 615 $this->assertEquals("Bad value", $this->selenium->getAlert()); 616 $this->selenium->type("testInput", "somethingelse"); 617 } 618 // }}} 619 // {{{ testAlerts 620 public function testAlerts() 621 { 622 $this->selenium->open($this->browserUrl . "html/test_verify_alert.html"); 623 $this->assertFalse($this->selenium->isAlertPresent()); 624 625 $this->selenium->click("oneAlert"); 626 $this->assertTrue($this->selenium->isAlertPresent()); 627 $this->assertEquals("Store Below 494 degrees K!", $this->selenium->getAlert()); 628 629 $this->selenium->click("twoAlerts"); 630 $this->assertEquals("Store Below 220 degrees C!", $this->selenium->getAlert()); 631 $this->assertEquals("Store Below 429 degrees F!", $this->selenium->getAlert()); 632 $this->selenium->click("alertAndLeave"); 633 $this->selenium->waitForPageToLoad(500); 634 $this->assertEquals("I'm Melting! I'm Melting!", $this->selenium->getAlert()); 635 } 636 // }}} 637 // {{{ testConfirmations 638 public function testConfirmations() 639 { 640 $this->selenium->open($this->browserUrl . "html/test_confirm.html"); 641 $this->selenium->chooseCancelOnNextConfirmation(); 642 $this->selenium->click("confirmAndLeave"); 643 $this->assertTrue($this->selenium->isConfirmationPresent()); 644 $this->assertEquals("You are about to go to a dummy page.", $this->selenium->getConfirmation()); 645 $this->assertEquals("Test Confirm", $this->selenium->getTitle()); 646 647 $this->selenium->click("confirmAndLeave"); 648 $this->selenium->waitForPageToLoad(500); 649 $this->assertEquals("You are about to go to a dummy page.", $this->selenium->getConfirmation()); 650 $this->assertEquals("Dummy Page", $this->selenium->getTitle()); 651 } 652 // }}} 653 // {{{ testPrompt 654 public function testPrompt() 655 { 656 $this->selenium->open($this->browserUrl . "html/test_prompt.html"); 657 $this->assertFalse($this->selenium->isPromptPresent()); 658 659 $this->selenium->click("promptAndLeave"); 660 $this->assertTrue($this->selenium->isPromptPresent()); 661 $this->assertEquals("Type 'yes' and click OK", $this->selenium->getPrompt()); 662 $this->assertEquals("Test Prompt", $this->selenium->getTitle()); 663 $this->selenium->answerOnNextPrompt("yes"); 664 $this->selenium->click("promptAndLeave"); 665 666 $this->selenium->waitForPageToLoad(500); 667 $this->assertEquals("Type 'yes' and click OK", $this->selenium->getPrompt()); 668 $this->assertEquals("Dummy Page", $this->selenium->getTitle()); 669 } 670 // }}} 671 // {{{ testVisibility 672 public function testVisibility() 673 { 674 $this->selenium->open($this->browserUrl . "html/test_visibility.html"); 675 $this->assertTrue($this->selenium->isVisible("visibleParagraph")); 676 $this->assertFalse($this->selenium->isVisible("hiddenParagraph")); 677 $this->assertFalse($this->selenium->isVisible("suppressedParagraph")); 678 $this->assertFalse($this->selenium->isVisible("classSuppressedParagraph")); 679 $this->assertFalse($this->selenium->isVisible("jsClassSuppressedParagraph")); 680 $this->assertFalse($this->selenium->isVisible("hiddenSubElement")); 681 $this->assertTrue($this->selenium->isVisible("visibleSubElement")); 682 $this->assertFalse($this->selenium->isVisible("suppressedSubElement")); 683 $this->assertFalse($this->selenium->isVisible("jsHiddenParagraph")); 684 } 685 // }}} 686 // {{{ testEditable 687 public function testEditable() 688 { 689 $this->selenium->open($this->browserUrl . "html/test_editable.html"); 690 $this->assertTrue($this->selenium->isEditable("normal_text")); 691 $this->assertTrue($this->selenium->isEditable("normal_select")); 692 $this->assertFalse($this->selenium->isEditable("disabled_text")); 693 $this->assertFalse($this->selenium->isEditable("disabled_select")); 694 } 695 // }}} 696 // {{{ testFallingVerifications 697 // public function testFallingVerifications() 698 // {} 699 // }}} 700 // {{{ testFallingAssert 701 // public function testFallingAssert 702 // {} 703 // }}} 704 // {{{ testCommandError 705 // public function testCommandError 706 // {} 707 // }}} 708 */ 709} 710?> 711