|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2014 Anthon Pang. All Rights Reserved. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + * |
| 17 | + * @package WebDriver |
| 18 | + * |
| 19 | + * @author Anthon Pang <[email protected]> |
| 20 | + */ |
| 21 | + |
| 22 | +namespace Test\WebDriver; |
| 23 | + |
| 24 | +use WebDriver\WebDriver; |
| 25 | + |
| 26 | +/** |
| 27 | + * Test WebDriver\WebDriver class |
| 28 | + * |
| 29 | + * @package WebDriver |
| 30 | + */ |
| 31 | +class WebDriverTest extends \PHPUnit_Framework_TestCase |
| 32 | +{ |
| 33 | + private $driver; |
| 34 | + private $session; |
| 35 | + |
| 36 | + /** |
| 37 | + * {@inheritdoc} |
| 38 | + */ |
| 39 | + protected function setUp() |
| 40 | + { |
| 41 | + $this->driver = new WebDriver(); |
| 42 | + $this->session = null; |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * {@inheritdoc} |
| 47 | + */ |
| 48 | + protected function tearDown() |
| 49 | + { |
| 50 | + if ($this->session) { |
| 51 | + $this->session->close(); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + /** |
| 56 | + * @group Functional |
| 57 | + */ |
| 58 | + public function testSessions() |
| 59 | + { |
| 60 | + try { |
| 61 | + $this->assertCount(0, $this->driver->sessions()); |
| 62 | + |
| 63 | + $this->session = $this->driver->session(); |
| 64 | + } catch (\Exception $e) { |
| 65 | + if (strpos($e->getMessage(),'Failed connect to localhost:4444; Connection refused') !== false) { |
| 66 | + $this->markTestSkipped('selenium server not running'); |
| 67 | + } else { |
| 68 | + throw $e; |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + $this->assertCount(1, $this->driver->sessions()); |
| 73 | + $this->assertEquals('http://localhost:4444/wd/hub', $this->driver->getUrl()); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @group Functional |
| 78 | + */ |
| 79 | + public function testStatus() |
| 80 | + { |
| 81 | + try { |
| 82 | + $status = $this->driver->status(); |
| 83 | + } catch (\Exception $e) { |
| 84 | + if (strpos($e->getMessage(),'Failed connect to localhost:4444; Connection refused') !== false) { |
| 85 | + $this->markTestSkipped('selenium server not running'); |
| 86 | + } else { |
| 87 | + throw $e; |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + $this->assertCount(3, $status); |
| 92 | + $this->assertTrue(isset($status['java'])); |
| 93 | + $this->assertTrue(isset($status['os'])); |
| 94 | + $this->assertTrue(isset($status['build'])); |
| 95 | + } |
| 96 | +} |
0 commit comments