Skip to content

Commit

Permalink
Check if given browser is supported (fixes lmc-eu#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
OndraM committed May 25, 2015
1 parent 5d065dc commit 7468f53
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
### Added
- Check if browser given to `run-tests` command is supported (this helps avoiding typos, interchange of browser and environment etc.).

### Changed
- The `logs/results.xml` could now be also accessed locally (the XSLT is now embedded right into the file, so we don't encounter same-origin policy problems).
- Use tagged version 0.6.0 of [php-webdriver](https://github.com/facebook/php-webdriver)
- Use tagged version 0.6.0 of [php-webdriver](https://github.com/facebook/php-webdriver).

### Fixed
- Properly trigger PHPUnit colored (ANSI) mode when Steward itself is in ANSI mode.
Expand Down
41 changes: 41 additions & 0 deletions src-tests/Console/Command/RunTestsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,47 @@ public function directoryOptionsProvider()
];
}

/**
* @dataProvider browserNameProvider
* @param string $browserName
* @param bool $shouldThrowException
*/
public function testShouldThrowExceptionIfUnsupportedBrowserSelected($browserName, $shouldThrowException)
{
if ($shouldThrowException) {
$this->setExpectedException('\RuntimeException', 'Browser "' . $browserName . '" is not supported');
}

$seleniumAdapterMock = $this->getSeleniumAdapterMock();
$this->command->setSeleniumAdapter($seleniumAdapterMock);

$this->tester->execute(
['command' => $this->command->getName(), 'environment' => 'prod', 'browser' => $browserName]
);

if (!$shouldThrowException) {
$output = $this->tester->getDisplay();
$this->assertContains('Browser: ' . strtolower($browserName), $output);
$this->assertContains('No testcases found, exiting.', $output);
}
}

/**
* @return array
*/
public function browserNameProvider()
{
return [
// $browserName, $shouldThrowException
'firefox is supported' => ['firefox', false],
'chrome is supported' => ['chrome', false],
'phantomjs is supported' => ['phantomjs', false],
'browser name is case insensitive' => ['FIREFOX', false],
'not supported browser' => ['mosaic', true],
'unprintable character in browser name' => ['firefox​', true],
];
}

public function testShouldStopIfServerIsNotResponding()
{
$seleniumAdapterMock = $this->getMockBuilder(SeleniumServerAdapter::class)
Expand Down
34 changes: 32 additions & 2 deletions src/Console/Command/RunTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class RunTestsCommand extends Command
protected $seleniumAdapter;
/** @var ProcessSetCreator */
protected $processSetCreator;
/** @var array */
protected $supportedBrowsers = [
\WebDriverBrowserType::FIREFOX,
\WebDriverBrowserType::CHROME,
\WebDriverBrowserType::IE,
\WebDriverBrowserType::SAFARI,
\WebDriverBrowserType::PHANTOMJS,
];

const ARGUMENT_ENVIRONMENT = 'environment';
const ARGUMENT_BROWSER = 'browser';
Expand Down Expand Up @@ -147,10 +155,32 @@ protected function initialize(InputInterface $input, OutputInterface $output)
)
);

$output->writeln(sprintf('Browser: %s', $input->getArgument(self::ARGUMENT_BROWSER)));
// If browser name or env is empty, ends initialization and let the Console/Command fail on input validation
if (empty($input->getArgument(self::ARGUMENT_BROWSER))
|| empty($input->getArgument(self::ARGUMENT_ENVIRONMENT))
) {
return;
}

// Browser name is case insensitive, normalize it to lower case
$input->setArgument(self::ARGUMENT_BROWSER, strtolower($input->getArgument(self::ARGUMENT_BROWSER)));
$browser = $input->getArgument(self::ARGUMENT_BROWSER);

// Check if browser is supported
if (!in_array($browser, $this->supportedBrowsers)) {
throw new \RuntimeException(
sprintf(
'Browser "%s" is not supported (use one of: %s)',
$browser,
implode(', ', $this->supportedBrowsers)
)
);
}

$output->writeln(sprintf('Browser: %s', $browser));
$output->writeln(sprintf('Environment: %s', $input->getArgument(self::ARGUMENT_ENVIRONMENT)));

// Tests directories exists
// Check if directories exists
$this->testDirectories(
$input,
$output,
Expand Down

0 comments on commit 7468f53

Please sign in to comment.