|
| 1 | +<?php |
| 2 | +// Copyright 2004-present Facebook. All Rights Reserved. |
| 3 | +// |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// |
| 8 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +// |
| 10 | +// Unless required by applicable law or agreed to in writing, software |
| 11 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +// See the License for the specific language governing permissions and |
| 14 | +// limitations under the License. |
| 15 | + |
| 16 | +namespace Facebook\WebDriver\Chrome; |
| 17 | + |
| 18 | +/** |
| 19 | + * @group exclude-saucelabs |
| 20 | + * @covers Facebook\WebDriver\Chrome\ChromeDriverService |
| 21 | + * @covers Facebook\WebDriver\Remote\Service\DriverService |
| 22 | + */ |
| 23 | +class ChromeDriverServiceTest extends \PHPUnit_Framework_TestCase |
| 24 | +{ |
| 25 | + protected function setUp() |
| 26 | + { |
| 27 | + if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) { |
| 28 | + $this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome'); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + public function testShouldStartAndStopServiceCreatedUsingShortcutConstructor() |
| 33 | + { |
| 34 | + // The createDefaultService() method expect path to the executable to be present in the environment variable |
| 35 | + putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . getenv('CHROMEDRIVER_PATH')); |
| 36 | + |
| 37 | + $driverService = ChromeDriverService::createDefaultService(); |
| 38 | + |
| 39 | + $this->assertSame('http://localhost:9515', $driverService->getURL()); |
| 40 | + |
| 41 | + $this->assertInstanceOf(ChromeDriverService::class, $driverService->start()); |
| 42 | + $this->assertTrue($driverService->isRunning()); |
| 43 | + |
| 44 | + $this->assertInstanceOf(ChromeDriverService::class, $driverService->start()); |
| 45 | + |
| 46 | + $this->assertInstanceOf(ChromeDriverService::class, $driverService->stop()); |
| 47 | + $this->assertFalse($driverService->isRunning()); |
| 48 | + |
| 49 | + $this->assertInstanceOf(ChromeDriverService::class, $driverService->stop()); |
| 50 | + } |
| 51 | + |
| 52 | + public function testShouldStartAndStopServiceCreatedUsingDefaultConstructor() |
| 53 | + { |
| 54 | + $driverService = new ChromeDriverService(getenv('CHROMEDRIVER_PATH'), 9515, ['--port=9515']); |
| 55 | + |
| 56 | + $this->assertSame('http://localhost:9515', $driverService->getURL()); |
| 57 | + |
| 58 | + $driverService->start(); |
| 59 | + $this->assertTrue($driverService->isRunning()); |
| 60 | + |
| 61 | + $driverService->stop(); |
| 62 | + $this->assertFalse($driverService->isRunning()); |
| 63 | + } |
| 64 | + |
| 65 | + public function testShouldThrowExceptionIfExecutableCannotBeFound() |
| 66 | + { |
| 67 | + putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=/not/existing'); |
| 68 | + |
| 69 | + $this->expectException(\Exception::class); |
| 70 | + $this->expectExceptionMessage('\'/not/existing\' is not a file.'); |
| 71 | + ChromeDriverService::createDefaultService(); |
| 72 | + } |
| 73 | + |
| 74 | + public function testShouldThrowExceptionIfExecutableIsNotExecutable() |
| 75 | + { |
| 76 | + putenv(ChromeDriverService::CHROME_DRIVER_EXE_PROPERTY . '=' . __FILE__); |
| 77 | + |
| 78 | + $this->expectException(\Exception::class); |
| 79 | + $this->expectExceptionMessage('is not executable'); |
| 80 | + ChromeDriverService::createDefaultService(); |
| 81 | + } |
| 82 | +} |
0 commit comments