Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, 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
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link       http://www.phpunit.de/
43
 * @since      File available since Release 3.0.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Log/Database.php';
48
require_once 'PHPUnit/Util/Filter.php';
49
require_once 'PHPUnit/Util/Test.php';
50
require_once 'PHPUnit/Util/XML.php';
51
require_once 'PHPUnit/Extensions/SeleniumTestCase/Driver.php';
52
 
53
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
54
 
55
/**
56
 * TestCase class that uses Selenium to provide
57
 * the functionality required for web testing.
58
 *
59
 * @category   Testing
60
 * @package    PHPUnit
61
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
62
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
63
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
64
 * @version    Release: 3.4.15
65
 * @link       http://www.phpunit.de/
66
 * @since      Class available since Release 3.0.0
67
 */
68
abstract class PHPUnit_Extensions_SeleniumTestCase extends PHPUnit_Framework_TestCase
69
{
70
    /**
71
     * @var    array
72
     */
73
    public static $browsers = array();
74
 
75
    /**
76
     * @var    boolean
77
     */
78
    protected $autoStop = TRUE;
79
 
80
    /**
81
     * @var    string
82
     */
83
    protected $browserName;
84
 
85
    /**
86
     * @var    boolean
87
     */
88
    protected $collectCodeCoverageInformation = FALSE;
89
 
90
    /**
91
     * @var    string
92
     */
93
    protected $coverageScriptUrl = '';
94
 
95
    /**
96
     * @var    PHPUnit_Extensions_SeleniumTestCase_Driver[]
97
     */
98
    protected $drivers = array();
99
 
100
    /**
101
     * @var    boolean
102
     */
103
    protected $inDefaultAssertions = FALSE;
104
 
105
    /**
106
     * @var    string
107
     */
108
    protected $testId;
109
 
110
    /**
111
     * @var    array
112
     * @access protected
113
     */
114
    protected $verificationErrors = array();
115
 
116
    /**
117
     * @var    boolean
118
     */
119
    protected $captureScreenshotOnFailure = FALSE;
120
 
121
    /**
122
     * @var    string
123
     */
124
    protected $screenshotPath = '';
125
 
126
    /**
127
     * @var    string
128
     */
129
    protected $screenshotUrl = '';
130
 
131
    /**
132
     * @param  string $name
133
     * @param  array  $data
134
     * @param  string $dataName
135
     * @param  array  $browser
136
     * @throws InvalidArgumentException
137
     */
138
    public function __construct($name = NULL, array $data = array(), $dataName = '', array $browser = array())
139
    {
140
        parent::__construct($name, $data, $dataName);
141
        $this->testId = md5(uniqid(rand(), TRUE));
142
        $this->getDriver($browser);
143
    }
144
 
145
    /**
146
     * @param  string $className
147
     * @return PHPUnit_Framework_TestSuite
148
     */
149
    public static function suite($className)
150
    {
151
        $suite = new PHPUnit_Framework_TestSuite;
152
        $suite->setName($className);
153
 
154
        $class            = new ReflectionClass($className);
155
        $classGroups      = PHPUnit_Util_Test::getGroups($className);
156
        $staticProperties = $class->getStaticProperties();
157
 
158
        // Create tests from Selenese/HTML files.
159
        if (isset($staticProperties['seleneseDirectory']) &&
160
            is_dir($staticProperties['seleneseDirectory'])) {
161
            $files = array_merge(
162
              self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.htm'),
163
              self::getSeleneseFiles($staticProperties['seleneseDirectory'], '.html')
164
            );
165
 
166
            // Create tests from Selenese/HTML files for multiple browsers.
167
            if (!empty($staticProperties['browsers'])) {
168
                foreach ($staticProperties['browsers'] as $browser) {
169
                    $browserSuite = new PHPUnit_Framework_TestSuite;
170
                    $browserSuite->setName($className . ': ' . $browser['name']);
171
 
172
                    foreach ($files as $file) {
173
                        $browserSuite->addTest(
174
                          new $className($file, array(), '', $browser),
175
                          $classGroups
176
                        );
177
                    }
178
 
179
                    $suite->addTest($browserSuite);
180
                }
181
            }
182
 
183
            // Create tests from Selenese/HTML files for single browser.
184
            else {
185
                foreach ($files as $file) {
186
                    $suite->addTest(new $className($file), $classGroups);
187
                }
188
            }
189
        }
190
 
191
        // Create tests from test methods for multiple browsers.
192
        if (!empty($staticProperties['browsers'])) {
193
            foreach ($staticProperties['browsers'] as $browser) {
194
                $browserSuite = new PHPUnit_Framework_TestSuite;
195
                $browserSuite->setName($className . ': ' . $browser['name']);
196
 
197
                foreach ($class->getMethods() as $method) {
198
                    if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
199
                        $name   = $method->getName();
200
                        $data   = PHPUnit_Util_Test::getProvidedData($className, $name);
201
                        $groups = PHPUnit_Util_Test::getGroups($className, $name);
202
 
203
                        // Test method with @dataProvider.
204
                        if (is_array($data) || $data instanceof Iterator) {
205
                            $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider(
206
                              $className . '::' . $name
207
                            );
208
 
209
                            foreach ($data as $_dataName => $_data) {
210
                                $dataSuite->addTest(
211
                                  new $className($name, $_data, $_dataName, $browser),
212
                                  $groups
213
                                );
214
                            }
215
 
216
                            $browserSuite->addTest($dataSuite);
217
                        }
218
 
219
                        // Test method with invalid @dataProvider.
220
                        else if ($data === FALSE) {
221
                            $browserSuite->addTest(
222
                              new PHPUnit_Framework_Warning(
223
                                sprintf(
224
                                  'The data provider specified for %s::%s is invalid.',
225
                                  $className,
226
                                  $name
227
                                )
228
                              )
229
                            );
230
                        }
231
 
232
                        // Test method without @dataProvider.
233
                        else {
234
                            $browserSuite->addTest(
235
                              new $className($name, array(), '', $browser), $groups
236
                            );
237
                        }
238
                    }
239
                }
240
 
241
                $suite->addTest($browserSuite);
242
            }
243
        }
244
 
245
        // Create tests from test methods for single browser.
246
        else {
247
            foreach ($class->getMethods() as $method) {
248
                if (PHPUnit_Framework_TestSuite::isPublicTestMethod($method)) {
249
                    $name   = $method->getName();
250
                    $data   = PHPUnit_Util_Test::getProvidedData($className, $name);
251
                    $groups = PHPUnit_Util_Test::getGroups($className, $name);
252
 
253
                    // Test method with @dataProvider.
254
                    if (is_array($data) || $data instanceof Iterator) {
255
                        $dataSuite = new PHPUnit_Framework_TestSuite_DataProvider(
256
                          $className . '::' . $name
257
                        );
258
 
259
                        foreach ($data as $_dataName => $_data) {
260
                            $dataSuite->addTest(
261
                              new $className($name, $_data, $_dataName),
262
                              $groups
263
                            );
264
                        }
265
 
266
                        $suite->addTest($dataSuite);
267
                    }
268
 
269
                    // Test method with invalid @dataProvider.
270
                    else if ($data === FALSE) {
271
                        $suite->addTest(
272
                          new PHPUnit_Framework_Warning(
273
                            sprintf(
274
                              'The data provider specified for %s::%s is invalid.',
275
                              $className,
276
                              $name
277
                            )
278
                          )
279
                        );
280
                    }
281
 
282
                    // Test method without @dataProvider.
283
                    else {
284
                        $suite->addTest(
285
                          new $className($name), $groups
286
                        );
287
                    }
288
                }
289
            }
290
        }
291
 
292
        return $suite;
293
    }
294
 
295
    /**
296
     * Runs the test case and collects the results in a TestResult object.
297
     * If no TestResult object is passed a new one will be created.
298
     *
299
     * @param  PHPUnit_Framework_TestResult $result
300
     * @return PHPUnit_Framework_TestResult
301
     * @throws InvalidArgumentException
302
     */
303
    public function run(PHPUnit_Framework_TestResult $result = NULL)
304
    {
305
        if ($result === NULL) {
306
            $result = $this->createResult();
307
        }
308
 
309
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
310
 
311
        foreach ($this->drivers as $driver) {
312
            $driver->setCollectCodeCoverageInformation(
313
              $this->collectCodeCoverageInformation
314
            );
315
        }
316
 
317
        $result->run($this);
318
 
319
        if ($this->collectCodeCoverageInformation) {
320
            $result->appendCodeCoverageInformation(
321
              $this, $this->getCodeCoverage()
322
            );
323
        }
324
 
325
        return $result;
326
    }
327
 
328
    /**
329
     * @param  array $browser
330
     * @return PHPUnit_Extensions_SeleniumTestCase_Driver
331
     * @since  Method available since Release 3.3.0
332
     */
333
    protected function getDriver(array $browser)
334
    {
335
        if (isset($browser['name'])) {
336
            if (!is_string($browser['name'])) {
337
                throw new InvalidArgumentException(
338
                  'Array element "name" is no string.'
339
                );
340
            }
341
        } else {
342
            $browser['name'] = '';
343
        }
344
 
345
        if (isset($browser['browser'])) {
346
            if (!is_string($browser['browser'])) {
347
                throw new InvalidArgumentException(
348
                  'Array element "browser" is no string.'
349
                );
350
            }
351
        } else {
352
            $browser['browser'] = '';
353
        }
354
 
355
        if (isset($browser['host'])) {
356
            if (!is_string($browser['host'])) {
357
                throw new InvalidArgumentException(
358
                  'Array element "host" is no string.'
359
                );
360
            }
361
        } else {
362
            $browser['host'] = 'localhost';
363
        }
364
 
365
        if (isset($browser['port'])) {
366
            if (!is_int($browser['port'])) {
367
                throw new InvalidArgumentException(
368
                  'Array element "port" is no integer.'
369
                );
370
            }
371
        } else {
372
            $browser['port'] = 4444;
373
        }
374
 
375
        if (isset($browser['timeout'])) {
376
            if (!is_int($browser['timeout'])) {
377
                throw new InvalidArgumentException(
378
                  'Array element "timeout" is no integer.'
379
                );
380
            }
381
        } else {
382
            $browser['timeout'] = 30;
383
        }
384
 
385
        if (isset($browser['httpTimeout'])) {
386
            if (!is_int($browser['httpTimeout'])) {
387
                throw new InvalidArgumentException(
388
                  'Array element "httpTimeout" is no integer.'
389
                );
390
            }
391
        } else {
392
            $browser['httpTimeout'] = 45;
393
        }
394
 
395
        $driver = new PHPUnit_Extensions_SeleniumTestCase_Driver;
396
        $driver->setName($browser['name']);
397
        $driver->setBrowser($browser['browser']);
398
        $driver->setHost($browser['host']);
399
        $driver->setPort($browser['port']);
400
        $driver->setTimeout($browser['timeout']);
401
        $driver->setHttpTimeout($browser['httpTimeout']);
402
        $driver->setTestCase($this);
403
        $driver->setTestId($this->testId);
404
 
405
        $this->drivers[] = $driver;
406
 
407
        return $driver;
408
    }
409
 
410
    /**
411
     * @throws RuntimeException
412
     */
413
    protected function runTest()
414
    {
415
        $this->start();
416
 
417
        if (!is_file($this->name)) {
418
            parent::runTest();
419
        } else {
420
            $this->runSelenese($this->name);
421
        }
422
 
423
        if (!empty($this->verificationErrors)) {
424
            $this->fail(implode("\n", $this->verificationErrors));
425
        }
426
 
427
        if ($this->autoStop) {
428
            try {
429
                $this->stop();
430
            }
431
 
432
            catch (RuntimeException $e) {
433
            }
434
        }
435
    }
436
 
437
    /**
438
     * Returns a string representation of the test case.
439
     *
440
     * @return string
441
     */
442
    public function toString()
443
    {
444
        $buffer = parent::toString();
445
 
446
        if (!empty($this->browserName)) {
447
            $buffer .= ' with browser ' . $this->browserName;
448
        }
449
 
450
        return $buffer;
451
    }
452
 
453
    /**
454
     * @param  boolean $autoStop
455
     * @throws InvalidArgumentException
456
     */
457
    public function setAutoStop($autoStop)
458
    {
459
        if (!is_bool($autoStop)) {
460
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
461
        }
462
 
463
        $this->autoStop = $autoStop;
464
    }
465
 
466
    /**
467
     * Runs a test from a Selenese (HTML) specification.
468
     *
469
     * @param string $filename
470
     */
471
    public function runSelenese($filename)
472
    {
473
        $document = PHPUnit_Util_XML::loadFile($filename, TRUE);
474
        $xpath    = new DOMXPath($document);
475
        $rows     = $xpath->query('body/table/tbody/tr');
476
 
477
        foreach ($rows as $row) {
478
            $action    = NULL;
479
            $arguments = array();
480
            $columns   = $xpath->query('td', $row);
481
 
482
            foreach ($columns as $column) {
483
                if ($action === NULL) {
484
                    $action = PHPUnit_Util_XML::nodeToText($column);
485
                } else {
486
                    $arguments[] = PHPUnit_Util_XML::nodeToText($column);
487
                }
488
            }
489
 
490
            if (method_exists($this, $action)) {
491
                call_user_func_array(array($this, $action), $arguments);
492
            } else {
493
                $this->__call($action, $arguments);
494
            }
495
        }
496
    }
497
 
498
    /**
499
     * Delegate method calls to the driver.
500
     *
501
     * @param  string $command
502
     * @param  array  $arguments
503
     * @return mixed
504
     * @method unknown  addLocationStrategy()
505
     * @method unknown  addLocationStrategyAndWait()
506
     * @method unknown  addScript()
507
     * @method unknown  addScriptAndWait()
508
     * @method unknown  addSelection()
509
     * @method unknown  addSelectionAndWait()
510
     * @method unknown  allowNativeXpath()
511
     * @method unknown  allowNativeXpathAndWait()
512
     * @method unknown  altKeyDown()
513
     * @method unknown  altKeyDownAndWait()
514
     * @method unknown  altKeyUp()
515
     * @method unknown  altKeyUpAndWait()
516
     * @method unknown  answerOnNextPrompt()
517
     * @method unknown  assignId()
518
     * @method unknown  assignIdAndWait()
519
     * @method unknown  attachFile()
520
     * @method unknown  break()
521
     * @method unknown  captureEntirePageScreenshot()
522
     * @method unknown  captureEntirePageScreenshotAndWait()
523
     * @method unknown  captureEntirePageScreenshotToStringAndWait()
524
     * @method unknown  captureScreenshotAndWait()
525
     * @method unknown  captureScreenshotToStringAndWait()
526
     * @method unknown  check()
527
     * @method unknown  checkAndWait()
528
     * @method unknown  chooseCancelOnNextConfirmation()
529
     * @method unknown  chooseCancelOnNextConfirmationAndWait()
530
     * @method unknown  chooseOkOnNextConfirmation()
531
     * @method unknown  chooseOkOnNextConfirmationAndWait()
532
     * @method unknown  click()
533
     * @method unknown  clickAndWait()
534
     * @method unknown  clickAt()
535
     * @method unknown  clickAtAndWait()
536
     * @method unknown  close()
537
     * @method unknown  contextMenu()
538
     * @method unknown  contextMenuAndWait()
539
     * @method unknown  contextMenuAt()
540
     * @method unknown  contextMenuAtAndWait()
541
     * @method unknown  controlKeyDown()
542
     * @method unknown  controlKeyDownAndWait()
543
     * @method unknown  controlKeyUp()
544
     * @method unknown  controlKeyUpAndWait()
545
     * @method unknown  createCookie()
546
     * @method unknown  createCookieAndWait()
547
     * @method unknown  deleteAllVisibleCookies()
548
     * @method unknown  deleteAllVisibleCookiesAndWait()
549
     * @method unknown  deleteCookie()
550
     * @method unknown  deleteCookieAndWait()
551
     * @method unknown  deselectPopUp()
552
     * @method unknown  deselectPopUpAndWait()
553
     * @method unknown  doubleClick()
554
     * @method unknown  doubleClickAndWait()
555
     * @method unknown  doubleClickAt()
556
     * @method unknown  doubleClickAtAndWait()
557
     * @method unknown  dragAndDrop()
558
     * @method unknown  dragAndDropAndWait()
559
     * @method unknown  dragAndDropToObject()
560
     * @method unknown  dragAndDropToObjectAndWait()
561
     * @method unknown  dragDrop()
562
     * @method unknown  dragDropAndWait()
563
     * @method unknown  echo()
564
     * @method unknown  fireEvent()
565
     * @method unknown  fireEventAndWait()
566
     * @method unknown  focus()
567
     * @method unknown  focusAndWait()
568
     * @method string   getAlert()
569
     * @method array    getAllButtons()
570
     * @method array    getAllFields()
571
     * @method array    getAllLinks()
572
     * @method array    getAllWindowIds()
573
     * @method array    getAllWindowNames()
574
     * @method array    getAllWindowTitles()
575
     * @method string   getAttribute()
576
     * @method array    getAttributeFromAllWindows()
577
     * @method string   getBodyText()
578
     * @method string   getConfirmation()
579
     * @method string   getCookie()
580
     * @method string   getCookieByName()
581
     * @method integer  getCursorPosition()
582
     * @method integer  getElementHeight()
583
     * @method integer  getElementIndex()
584
     * @method integer  getElementPositionLeft()
585
     * @method integer  getElementPositionTop()
586
     * @method integer  getElementWidth()
587
     * @method string   getEval()
588
     * @method string   getExpression()
589
     * @method string   getHtmlSource()
590
     * @method string   getLocation()
591
     * @method string   getLogMessages()
592
     * @method integer  getMouseSpeed()
593
     * @method string   getPrompt()
594
     * @method array    getSelectOptions()
595
     * @method string   getSelectedId()
596
     * @method array    getSelectedIds()
597
     * @method string   getSelectedIndex()
598
     * @method array    getSelectedIndexes()
599
     * @method string   getSelectedLabel()
600
     * @method array    getSelectedLabels()
601
     * @method string   getSelectedValue()
602
     * @method array    getSelectedValues()
603
     * @method unknown  getSpeed()
604
     * @method unknown  getSpeedAndWait()
605
     * @method string   getTable()
606
     * @method string   getText()
607
     * @method string   getTitle()
608
     * @method string   getValue()
609
     * @method boolean  getWhetherThisFrameMatchFrameExpression()
610
     * @method boolean  getWhetherThisWindowMatchWindowExpression()
611
     * @method integer  getXpathCount()
612
     * @method unknown  goBack()
613
     * @method unknown  goBackAndWait()
614
     * @method unknown  highlight()
615
     * @method unknown  highlightAndWait()
616
     * @method unknown  ignoreAttributesWithoutValue()
617
     * @method unknown  ignoreAttributesWithoutValueAndWait()
618
     * @method boolean  isAlertPresent()
619
     * @method boolean  isChecked()
620
     * @method boolean  isConfirmationPresent()
621
     * @method boolean  isCookiePresent()
622
     * @method boolean  isEditable()
623
     * @method boolean  isElementPresent()
624
     * @method boolean  isOrdered()
625
     * @method boolean  isPromptPresent()
626
     * @method boolean  isSomethingSelected()
627
     * @method boolean  isTextPresent()
628
     * @method boolean  isVisible()
629
     * @method unknown  keyDown()
630
     * @method unknown  keyDownAndWait()
631
     * @method unknown  keyDownNative()
632
     * @method unknown  keyDownNativeAndWait()
633
     * @method unknown  keyPress()
634
     * @method unknown  keyPressAndWait()
635
     * @method unknown  keyPressNative()
636
     * @method unknown  keyPressNativeAndWait()
637
     * @method unknown  keyUp()
638
     * @method unknown  keyUpAndWait()
639
     * @method unknown  keyUpNative()
640
     * @method unknown  keyUpNativeAndWait()
641
     * @method unknown  metaKeyDown()
642
     * @method unknown  metaKeyDownAndWait()
643
     * @method unknown  metaKeyUp()
644
     * @method unknown  metaKeyUpAndWait()
645
     * @method unknown  mouseDown()
646
     * @method unknown  mouseDownAndWait()
647
     * @method unknown  mouseDownAt()
648
     * @method unknown  mouseDownAtAndWait()
649
     * @method unknown  mouseMove()
650
     * @method unknown  mouseMoveAndWait()
651
     * @method unknown  mouseMoveAt()
652
     * @method unknown  mouseMoveAtAndWait()
653
     * @method unknown  mouseOut()
654
     * @method unknown  mouseOutAndWait()
655
     * @method unknown  mouseOver()
656
     * @method unknown  mouseOverAndWait()
657
     * @method unknown  mouseUp()
658
     * @method unknown  mouseUpAndWait()
659
     * @method unknown  mouseUpAt()
660
     * @method unknown  mouseUpAtAndWait()
661
     * @method unknown  mouseUpRight()
662
     * @method unknown  mouseUpRightAndWait()
663
     * @method unknown  mouseUpRightAt()
664
     * @method unknown  mouseUpRightAtAndWait()
665
     * @method unknown  open()
666
     * @method unknown  openWindow()
667
     * @method unknown  openWindowAndWait()
668
     * @method unknown  pause()
669
     * @method unknown  refresh()
670
     * @method unknown  refreshAndWait()
671
     * @method unknown  removeAllSelections()
672
     * @method unknown  removeAllSelectionsAndWait()
673
     * @method unknown  removeScript()
674
     * @method unknown  removeScriptAndWait()
675
     * @method unknown  removeSelection()
676
     * @method unknown  removeSelectionAndWait()
677
     * @method unknown  retrieveLastRemoteControlLogs()
678
     * @method unknown  rollup()
679
     * @method unknown  rollupAndWait()
680
     * @method unknown  runScript()
681
     * @method unknown  runScriptAndWait()
682
     * @method unknown  select()
683
     * @method unknown  selectAndWait()
684
     * @method unknown  selectFrame()
685
     * @method unknown  selectPopUp()
686
     * @method unknown  selectPopUpAndWait()
687
     * @method unknown  selectWindow()
688
     * @method unknown  setBrowserLogLevel()
689
     * @method unknown  setBrowserLogLevelAndWait()
690
     * @method unknown  setContext()
691
     * @method unknown  setCursorPosition()
692
     * @method unknown  setCursorPositionAndWait()
693
     * @method unknown  setMouseSpeed()
694
     * @method unknown  setMouseSpeedAndWait()
695
     * @method unknown  setSpeed()
696
     * @method unknown  setSpeedAndWait()
697
     * @method unknown  shiftKeyDown()
698
     * @method unknown  shiftKeyDownAndWait()
699
     * @method unknown  shiftKeyUp()
700
     * @method unknown  shiftKeyUpAndWait()
701
     * @method unknown  shutDownSeleniumServer()
702
     * @method unknown  store()
703
     * @method unknown  submit()
704
     * @method unknown  submitAndWait()
705
     * @method unknown  type()
706
     * @method unknown  typeAndWait()
707
     * @method unknown  typeKeys()
708
     * @method unknown  typeKeysAndWait()
709
     * @method unknown  uncheck()
710
     * @method unknown  uncheckAndWait()
711
     * @method unknown  useXpathLibrary()
712
     * @method unknown  useXpathLibraryAndWait()
713
     * @method unknown  waitForCondition()
714
     * @method unknown  waitForPageToLoad()
715
     * @method unknown  waitForPopUp()
716
     * @method unknown  windowFocus()
717
     * @method unknown  windowMaximize()
718
     */
719
    public function __call($command, $arguments)
720
    {
721
        $result = call_user_func_array(
722
          array($this->drivers[0], $command), $arguments
723
        );
724
 
725
        $this->verificationErrors = array_merge(
726
          $this->verificationErrors, $this->drivers[0]->getVerificationErrors()
727
        );
728
 
729
        $this->drivers[0]->clearVerificationErrors();
730
 
731
        return $result;
732
    }
733
 
734
    /**
735
     * Asserts that an element's value is equal to a given string.
736
     *
737
     * @param  string $locator
738
     * @param  string $text
739
     * @param  string $message
740
     */
741
    public function assertElementValueEquals($locator, $text, $message = '')
742
    {
743
        $this->assertEquals($text, $this->getValue($locator), $message);
744
    }
745
 
746
    /**
747
     * Asserts that an element's value is not equal to a given string.
748
     *
749
     * @param  string $locator
750
     * @param  string $text
751
     * @param  string $message
752
     */
753
    public function assertElementValueNotEquals($locator, $text, $message = '')
754
    {
755
        $this->assertNotEquals($text, $this->getValue($locator), $message);
756
    }
757
 
758
    /**
759
     * Asserts that an element's value contains a given string.
760
     *
761
     * @param  string $locator
762
     * @param  string $text
763
     * @param  string $message
764
     */
765
    public function assertElementValueContains($locator, $text, $message = '')
766
    {
767
        $this->assertContains($text, $this->getValue($locator), $message);
768
    }
769
 
770
    /**
771
     * Asserts that an element's value does not contain a given string.
772
     *
773
     * @param  string $locator
774
     * @param  string $text
775
     * @param  string $message
776
     */
777
    public function assertElementValueNotContains($locator, $text, $message = '')
778
    {
779
        $this->assertNotContains($text, $this->getValue($locator), $message);
780
    }
781
 
782
    /**
783
     * Asserts that an element contains a given string.
784
     *
785
     * @param  string $locator
786
     * @param  string $text
787
     * @param  string $message
788
     */
789
    public function assertElementContainsText($locator, $text, $message = '')
790
    {
791
        $this->assertContains($text, $this->getText($locator), $message);
792
    }
793
 
794
    /**
795
     * Asserts that an element does not contain a given string.
796
     *
797
     * @param  string $locator
798
     * @param  string $text
799
     * @param  string $message
800
     */
801
    public function assertElementNotContainsText($locator, $text, $message = '')
802
    {
803
        $this->assertNotContains($text, $this->getText($locator), $message);
804
    }
805
 
806
    /**
807
     * Asserts that a select element has a specific option.
808
     *
809
     * @param  string $selectLocator
810
     * @param  string $option
811
     * @param  string $message
812
     * @since  Method available since Release 3.2.0
813
     */
814
    public function assertSelectHasOption($selectLocator, $option, $message = '')
815
    {
816
        $this->assertContains($option, $this->getSelectOptions($selectLocator), $message);
817
    }
818
 
819
    /**
820
     * Asserts that a select element does not have a specific option.
821
     *
822
     * @param  string $selectLocator
823
     * @param  string $option
824
     * @param  string $message
825
     * @since  Method available since Release 3.2.0
826
     */
827
    public function assertSelectNotHasOption($selectLocator, $option, $message = '')
828
    {
829
        $this->assertNotContains($option, $this->getSelectOptions($selectLocator), $message);
830
    }
831
 
832
    /**
833
     * Asserts that a specific label is selected.
834
     *
835
     * @param  string $selectLocator
836
     * @param  string $value
837
     * @param  string $message
838
     * @since  Method available since Release 3.2.0
839
     */
840
    public function assertSelected($selectLocator, $option, $message = '')
841
    {
842
        if ($message == '') {
843
            $message = sprintf(
844
              'Label "%s" not selected in "%s".',
845
              $option,
846
              $selectLocator
847
            );
848
        }
849
 
850
        $this->assertEquals(
851
          $option,
852
          $this->getSelectedLabel($selectLocator),
853
          $message
854
        );
855
    }
856
 
857
    /**
858
     * Asserts that a specific label is not selected.
859
     *
860
     * @param  string $selectLocator
861
     * @param  string $value
862
     * @param  string $message
863
     * @since  Method available since Release 3.2.0
864
     */
865
    public function assertNotSelected($selectLocator, $option, $message = '')
866
    {
867
        if ($message == '') {
868
            $message = sprintf(
869
              'Label "%s" selected in "%s".',
870
              $option,
871
              $selectLocator
872
            );
873
        }
874
 
875
        $this->assertNotEquals(
876
          $option,
877
          $this->getSelectedLabel($selectLocator),
878
          $message
879
        );
880
    }
881
 
882
    /**
883
     * Asserts that a specific value is selected.
884
     *
885
     * @param  string $selectLocator
886
     * @param  string $value
887
     * @param  string $message
888
     */
889
    public function assertIsSelected($selectLocator, $value, $message = '')
890
    {
891
        if ($message == '') {
892
            $message = sprintf(
893
              'Value "%s" not selected in "%s".',
894
              $value,
895
              $selectLocator
896
            );
897
        }
898
 
899
        $this->assertEquals(
900
          $value, $this->getSelectedValue($selectLocator),
901
          $message
902
        );
903
    }
904
 
905
    /**
906
     * Asserts that a specific value is not selected.
907
     *
908
     * @param  string $selectLocator
909
     * @param  string $value
910
     * @param  string $message
911
     */
912
    public function assertIsNotSelected($selectLocator, $value, $message = '')
913
    {
914
        if ($message == '') {
915
            $message = sprintf(
916
              'Value "%s" selected in "%s".',
917
              $value,
918
              $selectLocator
919
            );
920
        }
921
 
922
        $this->assertNotEquals(
923
          $value,
924
          $this->getSelectedValue($selectLocator),
925
          $message
926
        );
927
    }
928
 
929
    /**
930
     * Template Method that is called after Selenium actions.
931
     *
932
     * @param  string $action
933
     * @since  Method available since Release 3.1.0
934
     */
935
    protected function defaultAssertions($action)
936
    {
937
    }
938
 
939
    /**
940
     * @return array
941
     * @since  Method available since Release 3.2.0
942
     */
943
    protected function getCodeCoverage()
944
    {
945
        if (!empty($this->coverageScriptUrl)) {
946
            $url = sprintf(
947
              '%s?PHPUNIT_SELENIUM_TEST_ID=%s',
948
              $this->coverageScriptUrl,
949
              $this->testId
950
            );
951
 
952
            $buffer = @file_get_contents($url);
953
 
954
            if ($buffer !== FALSE) {
955
                return $this->matchLocalAndRemotePaths(unserialize($buffer));
956
            }
957
        }
958
 
959
        return array();
960
    }
961
 
962
    /**
963
     * @param  array $coverage
964
     * @return array
965
     * @author Mattis Stordalen Flister <mattis@xait.no>
966
     * @since  Method available since Release 3.2.9
967
     */
968
    protected function matchLocalAndRemotePaths(array $coverage)
969
    {
970
        $coverageWithLocalPaths = array();
971
 
972
        foreach ($coverage as $originalRemotePath => $data) {
973
            $remotePath = $originalRemotePath;
974
            $separator  = $this->findDirectorySeparator($remotePath);
975
 
976
            while (!($localpath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) &&
977
                   strpos($remotePath, $separator) !== FALSE) {
978
                $remotePath = substr($remotePath, strpos($remotePath, $separator) + 1);
979
            }
980
 
981
            if ($localpath && md5_file($localpath) == $data['md5']) {
982
                $coverageWithLocalPaths[$localpath] = $data['coverage'];
983
            }
984
        }
985
 
986
        return $coverageWithLocalPaths;
987
    }
988
 
989
    /**
990
     * @param  string $path
991
     * @return string
992
     * @author Mattis Stordalen Flister <mattis@xait.no>
993
     * @since  Method available since Release 3.2.9
994
     */
995
    protected function findDirectorySeparator($path)
996
    {
997
        if (strpos($path, '/') !== FALSE) {
998
            return '/';
999
        }
1000
 
1001
        return '\\';
1002
    }
1003
 
1004
    /**
1005
     * @param  string $path
1006
     * @return array
1007
     * @author Mattis Stordalen Flister <mattis@xait.no>
1008
     * @since  Method available since Release 3.2.9
1009
     */
1010
    protected function explodeDirectories($path)
1011
    {
1012
        return explode($this->findDirectorySeparator($path), dirname($path));
1013
    }
1014
 
1015
    /**
1016
     * @param  string $directory
1017
     * @param  string $suffix
1018
     * @return array
1019
     * @since  Method available since Release 3.3.0
1020
     */
1021
    protected static function getSeleneseFiles($directory, $suffix)
1022
    {
1023
        $files = array();
1024
 
1025
        $iterator = new PHPUnit_Util_FilterIterator(
1026
          new RecursiveIteratorIterator(
1027
            new RecursiveDirectoryIterator($directory)
1028
          ),
1029
          $suffix
1030
        );
1031
 
1032
        foreach ($iterator as $file) {
1033
            $files[] = (string)$file;
1034
        }
1035
 
1036
        return $files;
1037
    }
1038
 
1039
    /**
1040
     * @param  string $action
1041
     * @since  Method available since Release 3.2.0
1042
     */
1043
    public function runDefaultAssertions($action)
1044
    {
1045
        if (!$this->inDefaultAssertions) {
1046
            $this->inDefaultAssertions = TRUE;
1047
            $this->defaultAssertions($action);
1048
            $this->inDefaultAssertions = FALSE;
1049
        }
1050
    }
1051
 
1052
    /**
1053
     * This method is called when a test method did not execute successfully.
1054
     *
1055
     * @param Exception $e
1056
     * @since Method available since Release 3.4.0
1057
     */
1058
    protected function onNotSuccessfulTest(Exception $e)
1059
    {
1060
        if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
1061
            $buffer  = 'Current URL: ' . $this->drivers[0]->getLocation() .
1062
                       "\n";
1063
            $message = $e->getCustomMessage();
1064
 
1065
            if ($this->captureScreenshotOnFailure &&
1066
                !empty($this->screenshotPath) &&
1067
                !empty($this->screenshotUrl)) {
1068
                $this->drivers[0]->captureEntirePageScreenshot(
1069
                  $this->screenshotPath . DIRECTORY_SEPARATOR . $this->testId .
1070
                  '.png'
1071
                );
1072
 
1073
                $buffer .= 'Screenshot: ' . $this->screenshotUrl . '/' .
1074
                           $this->testId . ".png\n";
1075
            }
1076
        }
1077
 
1078
        if ($this->autoStop) {
1079
            try {
1080
                $this->stop();
1081
            }
1082
 
1083
            catch (RuntimeException $e) {
1084
            }
1085
        }
1086
 
1087
        if ($e instanceof PHPUnit_Framework_ExpectationFailedException) {
1088
            if (!empty($message)) {
1089
                $buffer .= "\n" . $message;
1090
            }
1091
 
1092
            $e->setCustomMessage($buffer);
1093
        }
1094
 
1095
        throw $e;
1096
    }
1097
}
1098
?>