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 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 3.0.0
47 require_once 'PHPUnit/Framework.php';
48 require_once 'PHPUnit/Util/Log/Database.php';
49 require_once 'PHPUnit/Util/Filter.php';
50 require_once 'PHPUnit/Util/Test.php';
51 require_once 'PHPUnit/Util/XML.php';
52 require_once 'PHPUnit/Extensions/SeleniumTestCase/Driver.php';
54 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
57 * TestCase class that uses Selenium to provide
58 * the functionality required for web testing.
62 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
63 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
64 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
65 * @version Release: 3.3.17
66 * @link http://www.phpunit.de/
67 * @since Class available since Release 3.0.0
69 abstract class PHPUnit_Extensions_SeleniumTestCase extends PHPUnit_Framework_TestCase
74 public static $browsers = array();
79 protected $autoStop = TRUE;
84 protected $browserName;
89 protected $collectCodeCoverageInformation = FALSE;
94 protected $coverageScriptUrl = '';
97 * @var PHPUnit_Extensions_SeleniumTestCase_Driver[]
99 protected $drivers = array();
104 protected $inDefaultAssertions = FALSE;
115 protected $verificationErrors = array();
118 * @param string $name
120 * @param string $dataName
121 * @param array $browser
122 * @throws InvalidArgumentException
124 public function __construct($name = NULL, array $data = array(), $dataName = '', array $browser = array())
126 parent::__construct($name, $data, $dataName);
127 $this->testId = md5(uniqid(rand(), TRUE));
128 $this->getDriver($browser);
132 * @param string $className
133 * @return PHPUnit_Framework_TestSuite
135 public static function suite($className)
137 $suite = new PHPUnit_Framework_TestSuite;
138 $suite->setName($className);
140 $class = new ReflectionClass($className);
141 $classGroups = PHPUnit_Util_Test::getGroups($class->getDocComment());
142 $staticProperties = $class->getStaticProperties();
144 // Create tests from Selenese/HTML files.
145 if (isset($staticProperties['seleneseDirectory']) &&
146 is_dir($staticProperties['seleneseDirectory'])) {
147 $files = array_merge(
148 self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'),
149 self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html')
152 // Create tests from Selenese/HTML files for multiple browsers.
153 if (!empty($staticProperties['browsers'])) {
154 foreach ($staticProperties['browsers'] as $browser) {
155 $browserSuite = new PHPUnit_Framework_TestSuite;
156 $browserSuite->setName($className . ': ' . $browser['name']);
158 foreach ($files as $file) {
159 $browserSuite->addTest(
160 new $className($file, array(), '', $browser),
165 $suite->addTest($browserSuite);
169 // Create tests from Selenese/HTML files for single browser.
171 foreach ($files as $file) {
172 $suite->addTest(new $className($file), $classGroups);
177 // Create tests from test methods for multiple browsers.
178 if (!empty($staticProperties['browsers'])) {
179 foreach ($staticProperties['browsers'] as $browser) {
180 $browserSuite = new PHPUnit_Framework_TestSuite;
181 $browserSuite->setName($className . ': ' . $browser['name']);
183 foreach ($class->getMethods() as $method) {
184 if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
185 $name = $method->getName();
186 $methodDocComment = $method->getDocComment();
187 $data = PHPUnit_Util_Test::getProvidedData($className, $name, $methodDocComment);
188 $groups = PHPUnit_Util_Test::getGroups($methodDocComment, $classGroups);
190 // Test method with @dataProvider.
191 if (is_array($data) || $data instanceof Iterator) {
192 $dataSuite = new PHPUnit_Framework_TestSuite(
193 $className . '::' . $name
196 foreach ($data as $_dataName => $_data) {
198 new $className($name, $_data, $_dataName, $browser),
203 $browserSuite->addTest($dataSuite);
206 // Test method without @dataProvider.
208 $browserSuite->addTest(
209 new $className($name, array(), '', $browser), $groups
215 $suite->addTest($browserSuite);
219 // Create tests from test methods for single browser.
221 foreach ($class->getMethods() as $method) {
222 if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
223 $name = $method->getName();
224 $methodDocComment = $method->getDocComment();
225 $data = PHPUnit_Util_Test::getProvidedData($className, $name, $methodDocComment);
226 $groups = PHPUnit_Util_Test::getGroups($methodDocComment, $classGroups);
228 // Test method with @dataProvider.
229 if (is_array($data) || $data instanceof Iterator) {
230 $dataSuite = new PHPUnit_Framework_TestSuite(
231 $className . '::' . $name
234 foreach ($data as $_dataName => $_data) {
236 new $className($name, $_data, $_dataName),
241 $suite->addTest($dataSuite);
244 // Test method without @dataProvider.
247 new $className($name), $groups
258 * Runs the test case and collects the results in a TestResult object.
259 * If no TestResult object is passed a new one will be created.
261 * @param PHPUnit_Framework_TestResult $result
262 * @return PHPUnit_Framework_TestResult
263 * @throws InvalidArgumentException
265 public function run(PHPUnit_Framework_TestResult $result = NULL)
267 if ($result === NULL) {
268 $result = $this->createResult();
271 $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
273 foreach ($this->drivers as $driver) {
274 $driver->setCollectCodeCoverageInformation(
275 $this->collectCodeCoverageInformation
281 if ($this->collectCodeCoverageInformation) {
282 $result->appendCodeCoverageInformation(
283 $this, $this->getCodeCoverage()
291 * @param array $browser
292 * @return PHPUnit_Extensions_SeleniumTestCase_Driver
293 * @since Method available since Release 3.3.0
295 protected function getDriver(array $browser)
297 if (isset($browser['name'])) {
298 if (!is_string($browser['name'])) {
299 throw new InvalidArgumentException;
302 $browser['name'] = '';
305 if (isset($browser['browser'])) {
306 if (!is_string($browser['browser'])) {
307 throw new InvalidArgumentException;
310 $browser['browser'] = '';
313 if (isset($browser['host'])) {
314 if (!is_string($browser['host'])) {
315 throw new InvalidArgumentException;
318 $browser['host'] = 'localhost';
321 if (isset($browser['port'])) {
322 if (!is_int($browser['port'])) {
323 throw new InvalidArgumentException;
326 $browser['port'] = 4444;
329 if (isset($browser['timeout'])) {
330 if (!is_int($browser['timeout'])) {
331 throw new InvalidArgumentException;
334 $browser['timeout'] = 30000;
337 $driver = new PHPUnit_Extensions_SeleniumTestCase_Driver;
338 $driver->setName($browser['name']);
339 $driver->setBrowser($browser['browser']);
340 $driver->setHost($browser['host']);
341 $driver->setPort($browser['port']);
342 $driver->setTimeout($browser['timeout']);
343 $driver->setTestCase($this);
344 $driver->setTestId($this->testId);
346 $this->drivers[] = $driver;
353 protected function runTest()
357 if (!is_file($this->name)) {
360 $this->runSelenese($this->name);
363 if ($this->autoStop) {
368 catch (RuntimeException $e) {
372 if (!empty($this->verificationErrors)) {
373 $this->fail(implode("\n", $this->verificationErrors));
378 * If you want to override tearDown() make sure to either call stop() or
379 * parent::tearDown(). Otherwise the Selenium RC session will not be
380 * closed upon test failure.
383 protected function tearDown()
385 if ($this->autoStop) {
390 catch (RuntimeException $e) {
396 * Returns a string representation of the test case.
400 public function toString()
402 $buffer = parent::toString();
404 if (!empty($this->browserName)) {
405 $buffer .= ' with browser ' . $this->browserName;
412 * @param boolean $autoStop
413 * @throws InvalidArgumentException
415 public function setAutoStop($autoStop)
417 if (!is_bool($autoStop)) {
418 throw new InvalidArgumentException;
421 $this->autoStop = $autoStop;
425 * Runs a test from a Selenese (HTML) specification.
427 * @param string $filename
429 public function runSelenese($filename)
431 $document = PHPUnit_Util_XML::loadFile($filename, TRUE);
432 $xpath = new DOMXPath($document);
433 $rows = $xpath->query('body/table/tbody/tr');
435 foreach ($rows as $row)
438 $arguments = array();
439 $columns = $xpath->query('td', $row);
441 foreach ($columns as $column)
443 if ($action === NULL) {
444 $action = $column->nodeValue;
446 $arguments[] = $column->nodeValue;
450 if (method_exists($this, $action)) {
451 call_user_func_array(array($this, $action), $arguments);
453 $this->__call($action, $arguments);
459 * Delegate method calls to the driver.
461 * @param string $command
462 * @param array $arguments
464 * @method unknown addLocationStrategy()
465 * @method unknown addSelection()
466 * @method unknown addSelectionAndWait()
467 * @method unknown allowNativeXpath()
468 * @method unknown altKeyDown()
469 * @method unknown altKeyDownAndWait()
470 * @method unknown altKeyUp()
471 * @method unknown altKeyUpAndWait()
472 * @method unknown answerOnNextPrompt()
473 * @method unknown assignId()
474 * @method unknown break()
475 * @method unknown captureEntirePageScreenshot()
476 * @method unknown captureScreenshot()
477 * @method unknown check()
478 * @method unknown chooseCancelOnNextConfirmation()
479 * @method unknown chooseOkOnNextConfirmation()
480 * @method unknown click()
481 * @method unknown clickAndWait()
482 * @method unknown clickAt()
483 * @method unknown clickAtAndWait()
484 * @method unknown close()
485 * @method unknown contextMenu()
486 * @method unknown contextMenuAndWait()
487 * @method unknown contextMenuAt()
488 * @method unknown contextMenuAtAndWait()
489 * @method unknown controlKeyDown()
490 * @method unknown controlKeyDownAndWait()
491 * @method unknown controlKeyUp()
492 * @method unknown controlKeyUpAndWait()
493 * @method unknown createCookie()
494 * @method unknown createCookieAndWait()
495 * @method unknown deleteAllVisibleCookies()
496 * @method unknown deleteAllVisibleCookiesAndWait()
497 * @method unknown deleteCookie()
498 * @method unknown deleteCookieAndWait()
499 * @method unknown doubleClick()
500 * @method unknown doubleClickAndWait()
501 * @method unknown doubleClickAt()
502 * @method unknown doubleClickAtAndWait()
503 * @method unknown dragAndDrop()
504 * @method unknown dragAndDropAndWait()
505 * @method unknown dragAndDropToObject()
506 * @method unknown dragAndDropToObjectAndWait()
507 * @method unknown dragDrop()
508 * @method unknown dragDropAndWait()
509 * @method unknown echo()
510 * @method unknown fireEvent()
511 * @method unknown fireEventAndWait()
512 * @method unknown focus()
513 * @method string getAlert()
514 * @method array getAllButtons()
515 * @method array getAllFields()
516 * @method array getAllLinks()
517 * @method array getAllWindowIds()
518 * @method array getAllWindowNames()
519 * @method array getAllWindowTitles()
520 * @method string getAttribute()
521 * @method array getAttributeFromAllWindows()
522 * @method string getBodyText()
523 * @method string getConfirmation()
524 * @method string getCookie()
525 * @method integer getCursorPosition()
526 * @method integer getElementHeight()
527 * @method integer getElementIndex()
528 * @method integer getElementPositionLeft()
529 * @method integer getElementPositionTop()
530 * @method integer getElementWidth()
531 * @method string getEval()
532 * @method string getExpression()
533 * @method string getHtmlSource()
534 * @method string getLocation()
535 * @method string getLogMessages()
536 * @method integer getMouseSpeed()
537 * @method string getPrompt()
538 * @method array getSelectOptions()
539 * @method string getSelectedId()
540 * @method array getSelectedIds()
541 * @method string getSelectedIndex()
542 * @method array getSelectedIndexes()
543 * @method string getSelectedLabel()
544 * @method array getSelectedLabels()
545 * @method string getSelectedValue()
546 * @method array getSelectedValues()
547 * @method unknown getSpeed()
548 * @method unknown getSpeedAndWait()
549 * @method string getTable()
550 * @method string getText()
551 * @method string getTitle()
552 * @method string getValue()
553 * @method boolean getWhetherThisFrameMatchFrameExpression()
554 * @method boolean getWhetherThisWindowMatchWindowExpression()
555 * @method integer getXpathCount()
556 * @method unknown goBack()
557 * @method unknown goBackAndWait()
558 * @method unknown highlight()
559 * @method unknown highlightAndWait()
560 * @method unknown ignoreAttributesWithoutValue()
561 * @method boolean isAlertPresent()
562 * @method boolean isChecked()
563 * @method boolean isConfirmationPresent()
564 * @method boolean isEditable()
565 * @method boolean isElementPresent()
566 * @method boolean isOrdered()
567 * @method boolean isPromptPresent()
568 * @method boolean isSomethingSelected()
569 * @method boolean isTextPresent()
570 * @method boolean isVisible()
571 * @method unknown keyDown()
572 * @method unknown keyDownAndWait()
573 * @method unknown keyPress()
574 * @method unknown keyPressAndWait()
575 * @method unknown keyUp()
576 * @method unknown keyUpAndWait()
577 * @method unknown metaKeyDown()
578 * @method unknown metaKeyDownAndWait()
579 * @method unknown metaKeyUp()
580 * @method unknown metaKeyUpAndWait()
581 * @method unknown mouseDown()
582 * @method unknown mouseDownAndWait()
583 * @method unknown mouseDownAt()
584 * @method unknown mouseDownAtAndWait()
585 * @method unknown mouseMove()
586 * @method unknown mouseMoveAndWait()
587 * @method unknown mouseMoveAt()
588 * @method unknown mouseMoveAtAndWait()
589 * @method unknown mouseOut()
590 * @method unknown mouseOutAndWait()
591 * @method unknown mouseOver()
592 * @method unknown mouseOverAndWait()
593 * @method unknown mouseUp()
594 * @method unknown mouseUpAndWait()
595 * @method unknown mouseUpAt()
596 * @method unknown mouseUpAtAndWait()
597 * @method unknown mouseUpRight()
598 * @method unknown mouseUpRightAndWait()
599 * @method unknown mouseUpRightAt()
600 * @method unknown mouseUpRightAtAndWait()
601 * @method unknown open()
602 * @method unknown openWindow()
603 * @method unknown openWindowAndWait()
604 * @method unknown pause()
605 * @method unknown refresh()
606 * @method unknown refreshAndWait()
607 * @method unknown removeAllSelections()
608 * @method unknown removeAllSelectionsAndWait()
609 * @method unknown removeSelection()
610 * @method unknown removeSelectionAndWait()
611 * @method unknown runScript()
612 * @method unknown select()
613 * @method unknown selectAndWait()
614 * @method unknown selectFrame()
615 * @method unknown selectWindow()
616 * @method unknown setBrowserLogLevel()
617 * @method unknown setContext()
618 * @method unknown setCursorPosition()
619 * @method unknown setCursorPositionAndWait()
620 * @method unknown setMouseSpeed()
621 * @method unknown setMouseSpeedAndWait()
622 * @method unknown setSpeed()
623 * @method unknown setSpeedAndWait()
624 * @method unknown shiftKeyDown()
625 * @method unknown shiftKeyDownAndWait()
626 * @method unknown shiftKeyUp()
627 * @method unknown shiftKeyUpAndWait()
628 * @method unknown store()
629 * @method unknown storeAlert()
630 * @method unknown storeAlertPresent()
631 * @method unknown storeAllButtons()
632 * @method unknown storeAllFields()
633 * @method unknown storeAllLinks()
634 * @method unknown storeAllWindowIds()
635 * @method unknown storeAllWindowNames()
636 * @method unknown storeAllWindowTitle()s
637 * @method unknown storeAttribute()
638 * @method unknown storeAttributeFromAllWindows()
639 * @method unknown storeBodyText()
640 * @method unknown storeChecked()
641 * @method unknown storeConfirmation()
642 * @method unknown storeConfirmationPresent()
643 * @method unknown storeCookie()
644 * @method unknown storeCookieByName()
645 * @method unknown storeCookiePresent()
646 * @method unknown storeCursorPosition()
647 * @method unknown storeEditable()
648 * @method unknown storeElementHeight()
649 * @method unknown storeElementIndex()
650 * @method unknown storeElementPositionLeft()
651 * @method unknown storeElementPositionTop()
652 * @method unknown storeElementPresent()
653 * @method unknown storeElementWidth()
654 * @method unknown storeEval()
655 * @method unknown storeExpression()
656 * @method unknown storeHtmlSource()
657 * @method unknown storeLocation()
658 * @method unknown storeMouseSpeed()
659 * @method unknown storeOrdered()
660 * @method unknown storePrompt()
661 * @method unknown storePromptPresent()
662 * @method unknown storeSelectOptions()
663 * @method unknown storeSelectedId()
664 * @method unknown storeSelectedIds()
665 * @method unknown storeSelectedIndex()
666 * @method unknown storeSelectedIndexes()
667 * @method unknown storeSelectedLabel()
668 * @method unknown storeSelectedLabels()
669 * @method unknown storeSelectedValue()
670 * @method unknown storeSelectedValues()
671 * @method unknown storeSomethingSelected()
672 * @method unknown storeSpeed()
673 * @method unknown storeTable()
674 * @method unknown storeText()
675 * @method unknown storeTextPresent()
676 * @method unknown storeTitle()
677 * @method unknown storeValue()
678 * @method unknown storeVisible()
679 * @method unknown storeWhetherThisFrameMatchFrameExpression()
680 * @method unknown storeWhetherThisWindowMatchWindowExpression()
681 * @method unknown storeXpathCount()
682 * @method unknown submit()
683 * @method unknown submitAndWait()
684 * @method unknown type()
685 * @method unknown typeAndWait()
686 * @method unknown typeKeys()
687 * @method unknown typeKeysAndWait()
688 * @method unknown uncheck()
689 * @method unknown uncheckAndWait()
690 * @method unknown waitForCondition()
691 * @method unknown waitForPageToLoad()
692 * @method unknown waitForPopUp()
693 * @method unknown windowFocus()
694 * @method unknown windowMaximize()
696 public function __call($command, $arguments)
698 return call_user_func_array(
699 array($this->drivers[0], $command), $arguments
704 * Asserts that an alert is present.
706 * @param string $message
708 public function assertAlertPresent($message = 'No alert present.')
710 $this->assertTrue($this->isAlertPresent(), $message);
714 * Asserts that no alert is present.
716 * @param string $message
718 public function assertNoAlertPresent($message = 'Alert present.')
720 $this->assertFalse($this->isAlertPresent(), $message);
724 * Asserts that an option is checked.
726 * @param string $locator
727 * @param string $message
729 public function assertChecked($locator, $message = '')
731 if ($message == '') {
738 $this->assertTrue($this->isChecked($locator), $message);
742 * Asserts that an option is not checked.
744 * @param string $locator
745 * @param string $message
747 public function assertNotChecked($locator, $message = '')
749 if ($message == '') {
756 $this->assertFalse($this->isChecked($locator), $message);
760 * Assert that a confirmation is present.
762 * @param string $message
764 public function assertConfirmationPresent($message = 'No confirmation present.')
766 $this->assertTrue($this->isConfirmationPresent(), $message);
770 * Assert that no confirmation is present.
772 * @param string $message
774 public function assertNoConfirmationPresent($message = 'Confirmation present.')
776 $this->assertFalse($this->isConfirmationPresent(), $message);
780 * Asserts that an input field is editable.
782 * @param string $locator
783 * @param string $message
785 public function assertEditable($locator, $message = '')
787 if ($message == '') {
789 '"%s" not editable.',
794 $this->assertTrue($this->isEditable($locator), $message);
798 * Asserts that an input field is not editable.
800 * @param string $locator
801 * @param string $message
803 public function assertNotEditable($locator, $message = '')
805 if ($message == '') {
812 $this->assertFalse($this->isEditable($locator), $message);
816 * Asserts that an element's value is equal to a given string.
818 * @param string $locator
819 * @param string $text
820 * @param string $message
822 public function assertElementValueEquals($locator, $text, $message = '')
824 $this->assertEquals($text, $this->getValue($locator), $message);
828 * Asserts that an element's value is not equal to a given string.
830 * @param string $locator
831 * @param string $text
832 * @param string $message
834 public function assertElementValueNotEquals($locator, $text, $message = '')
836 $this->assertNotEquals($text, $this->getValue($locator), $message);
840 * Asserts that an element contains a given string.
842 * @param string $locator
843 * @param string $text
844 * @param string $message
846 public function assertElementContainsText($locator, $text, $message = '')
848 $this->assertContains($text, $this->getValue($locator), $message);
852 * Asserts that an element does not contain a given string.
854 * @param string $locator
855 * @param string $text
856 * @param string $message
858 public function assertElementNotContainsText($locator, $text, $message = '')
860 $this->assertNotContains($text, $this->getValue($locator), $message);
864 * Asserts than an element is present.
866 * @param string $locator
867 * @param string $message
869 public function assertElementPresent($locator, $message = '')
871 if ($message == '') {
873 'Element "%s" not present.',
878 $this->assertTrue($this->isElementPresent($locator), $message);
882 * Asserts than an element is not present.
884 * @param string $locator
885 * @param string $message
887 public function assertElementNotPresent($locator, $message = '')
889 if ($message == '') {
891 'Element "%s" present.',
896 $this->assertFalse($this->isElementPresent($locator), $message);
900 * Asserts that the location is equal to a specified one.
902 * @param string $location
903 * @param string $message
905 public function assertLocationEquals($location, $message = '')
907 $this->assertEquals($location, $this->getLocation(), $message);
911 * Asserts that the location is not equal to a specified one.
913 * @param string $location
914 * @param string $message
916 public function assertLocationNotEquals($location, $message = '')
918 $this->assertNotEquals($location, $this->getLocation(), $message);
922 * Asserts than a prompt is present.
924 * @param string $message
926 public function assertPromptPresent($message = 'No prompt present.')
928 $this->assertTrue($this->isPromptPresent(), $message);
932 * Asserts than no prompt is present.
934 * @param string $message
936 public function assertNoPromptPresent($message = 'Prompt present.')
938 $this->assertFalse($this->isPromptPresent(), $message);
942 * Asserts that a select element has a specific option.
944 * @param string $selectLocator
945 * @param string $option
946 * @param string $message
947 * @since Method available since Release 3.2.0
949 public function assertSelectHasOption($selectLocator, $option, $message = '')
951 $this->assertContains($option, $this->getSelectOptions($selectLocator), $message);
955 * Asserts that a select element does not have a specific option.
957 * @param string $selectLocator
958 * @param string $option
959 * @param string $message
960 * @since Method available since Release 3.2.0
962 public function assertSelectNotHasOption($selectLocator, $option, $message = '')
964 $this->assertNotContains($option, $this->getSelectOptions($selectLocator), $message);
968 * Asserts that a specific label is selected.
970 * @param string $selectLocator
971 * @param string $value
972 * @param string $message
973 * @since Method available since Release 3.2.0
975 public function assertSelected($selectLocator, $option, $message = '')
977 if ($message == '') {
979 'Label "%s" not selected in "%s".',
987 $this->getSelectedLabel($selectLocator),
993 * Asserts that a specific label is not selected.
995 * @param string $selectLocator
996 * @param string $value
997 * @param string $message
998 * @since Method available since Release 3.2.0
1000 public function assertNotSelected($selectLocator, $option, $message = '')
1002 if ($message == '') {
1004 'Label "%s" selected in "%s".',
1010 $this->assertNotEquals(
1012 $this->getSelectedLabel($selectLocator),
1018 * Asserts that a specific value is selected.
1020 * @param string $selectLocator
1021 * @param string $value
1022 * @param string $message
1024 public function assertIsSelected($selectLocator, $value, $message = '')
1026 if ($message == '') {
1028 'Value "%s" not selected in "%s".',
1034 $this->assertEquals(
1035 $value, $this->getSelectedValue($selectLocator),
1041 * Asserts that a specific value is not selected.
1043 * @param string $selectLocator
1044 * @param string $value
1045 * @param string $message
1047 public function assertIsNotSelected($selectLocator, $value, $message = '')
1049 if ($message == '') {
1051 'Value "%s" selected in "%s".',
1057 $this->assertNotEquals(
1059 $this->getSelectedValue($selectLocator),
1065 * Asserts that something is selected.
1067 * @param string $selectLocator
1068 * @param string $message
1070 public function assertSomethingSelected($selectLocator, $message = '')
1072 if ($message == '') {
1074 'Nothing selected from "%s".',
1079 $this->assertTrue($this->isSomethingSelected($selectLocator), $message);
1083 * Asserts that nothing is selected.
1085 * @param string $selectLocator
1086 * @param string $message
1088 public function assertNothingSelected($selectLocator, $message = '')
1090 if ($message == '') {
1092 'Something selected from "%s".',
1097 $this->assertFalse($this->isSomethingSelected($selectLocator), $message);
1101 * Asserts that a given text is present.
1103 * @param string $pattern
1104 * @param string $message
1106 public function assertTextPresent($pattern, $message = '')
1108 if ($message == '') {
1110 '"%s" not present.',
1115 $this->assertTrue($this->isTextPresent($pattern), $message);
1119 * Asserts that a given text is not present.
1121 * @param string $pattern
1122 * @param string $message
1124 public function assertTextNotPresent($pattern, $message = '')
1126 if ($message == '') {
1133 $this->assertFalse($this->isTextPresent($pattern), $message);
1137 * Asserts that the title is equal to a given string.
1139 * @param string $title
1140 * @param string $message
1142 public function assertTitleEquals($title, $message = '')
1144 $this->assertEquals($title, $this->getTitle(), $message);
1148 * Asserts that the title is not equal to a given string.
1150 * @param string $title
1151 * @param string $message
1153 public function assertTitleNotEquals($title, $message = '')
1155 $this->assertNotEquals($title, $this->getTitle(), $message);
1159 * Asserts that something is visible.
1161 * @param string $locator
1162 * @param string $message
1164 public function assertVisible($locator, $message = '')
1166 if ($message == '') {
1168 '"%s" not visible.',
1173 $this->assertTrue($this->isVisible($locator), $message);
1177 * Asserts that something is not visible.
1179 * @param string $locator
1180 * @param string $message
1182 public function assertNotVisible($locator, $message = '')
1184 if ($message == '') {
1191 $this->assertFalse($this->isVisible($locator), $message);
1195 * Template Method that is called after Selenium actions.
1197 * @param string $action
1198 * @since Method available since Release 3.1.0
1200 protected function defaultAssertions($action)
1206 * @since Method available since Release 3.2.0
1208 protected function getCodeCoverage()
1210 if (!empty($this->coverageScriptUrl)) {
1212 '%s?PHPUNIT_SELENIUM_TEST_ID=%s',
1213 $this->coverageScriptUrl,
1217 $buffer = @file_get_contents($url);
1219 if ($buffer !== FALSE) {
1220 return $this->matchLocalAndRemotePaths(unserialize($buffer));
1228 * @param array $coverage
1230 * @author Mattis Stordalen Flister <mattis@xait.no>
1231 * @since Method available since Release 3.2.9
1233 protected function matchLocalAndRemotePaths(array $coverage)
1235 $coverageWithLocalPaths = array();
1237 foreach ($coverage as $originalRemotePath => $data) {
1238 $remotePath = $originalRemotePath;
1239 $separator = $this->findDirectorySeparator($remotePath);
1241 while (!($localpath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) &&
1242 strpos($remotePath, $separator) !== FALSE) {
1243 $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1);
1246 if ($localpath && md5_file($localpath) == $data['md5']) {
1247 $coverageWithLocalPaths[$localpath] = $data['coverage'];
1251 return $coverageWithLocalPaths;
1255 * @param string $path
1257 * @author Mattis Stordalen Flister <mattis@xait.no>
1258 * @since Method available since Release 3.2.9
1260 protected function findDirectorySeparator($path)
1262 if (strpos($path, '/') !== FALSE) {
1270 * @param string $path
1272 * @author Mattis Stordalen Flister <mattis@xait.no>
1273 * @since Method available since Release 3.2.9
1275 protected function explodeDirectories($path)
1277 return explode($this->findDirectorySeparator($path), dirname($path));
1281 * @param string $directory
1282 * @param string $suffix
1284 * @since Method available since Release 3.3.0
1286 protected static function getSeleneseFiles($directory, $suffix)
1290 $iterator = new PHPUnit_Util_FilterIterator(
1291 new RecursiveIteratorIterator(
1292 new RecursiveDirectoryIterator($directory)
1297 foreach ($iterator as $file) {
1298 $files[] = (string)$file;
1305 * @param string $action
1306 * @since Method available since Release 3.2.0
1308 public function runDefaultAssertions($action)
1310 if (!$this->inDefaultAssertions) {
1311 $this->inDefaultAssertions = TRUE;
1312 $this->defaultAssertions($action);
1313 $this->inDefaultAssertions = FALSE;