-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow accessing capabilities; add capabilities tests
- Loading branch information
Showing
2 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Mink\WebdriverClassicDriver\Tests\Custom; | ||
|
||
use Mink\WebdriverClassicDriver\WebdriverClassicDriver; | ||
|
||
class CapabilityTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @param array<string, mixed> $desiredCapabilities | ||
* @param array<string, mixed> $expectedCapabilities | ||
* | ||
* @dataProvider capabilitiesDataProvider | ||
*/ | ||
public function testThatCapabilitiesAreAsExpected(string $browserName, array $desiredCapabilities, array $expectedCapabilities): void | ||
{ | ||
$driver = $this->createDriverExposingCapabilities($browserName, $desiredCapabilities); | ||
|
||
$this->assertSame($expectedCapabilities, $driver->capabilities); | ||
} | ||
|
||
public static function capabilitiesDataProvider(): iterable | ||
{ | ||
yield 'unknown browser starts with default driver capabilities' => [ | ||
'browserName' => 'fake browser', | ||
'desiredCapabilities' => [], | ||
'expectedCapabilities' => [ | ||
'platform' => 'ANY', | ||
'name' => 'Behat Test', | ||
'deviceOrientation' => 'landscape', | ||
'deviceType' => 'desktop', | ||
], | ||
]; | ||
|
||
yield 'default capabilities can be customised' => [ | ||
'browserName' => 'fake browser', | ||
'desiredCapabilities' => [ | ||
'something' => 'custom', | ||
'name' => 'Custom Test', | ||
], | ||
'expectedCapabilities' => [ | ||
'platform' => 'ANY', | ||
'name' => 'Custom Test', | ||
'deviceOrientation' => 'landscape', | ||
'deviceType' => 'desktop', | ||
'something' => 'custom', | ||
], | ||
]; | ||
|
||
yield 'browser-specific default capabilities are added' => [ | ||
'browserName' => 'chrome', | ||
'desiredCapabilities' => [], | ||
'expectedCapabilities' => [ | ||
'browserName' => 'chrome', | ||
'platform' => 'ANY', | ||
'name' => 'Behat Test', | ||
'deviceOrientation' => 'landscape', | ||
'deviceType' => 'desktop', | ||
'goog:chromeOptions' => [ | ||
'excludeSwitches' => ['enable-automation'], | ||
], | ||
], | ||
]; | ||
|
||
yield 'browser-specific default capabilities can be customised' => [ | ||
'browserName' => 'chrome', | ||
'desiredCapabilities' => [ | ||
'name' => 'Custom Test', | ||
'goog:chromeOptions' => ['args' => ['a', 'b', 'c']], | ||
], | ||
'expectedCapabilities' => [ | ||
'browserName' => 'chrome', | ||
'platform' => 'ANY', | ||
'name' => 'Custom Test', | ||
'deviceOrientation' => 'landscape', | ||
'deviceType' => 'desktop', | ||
'goog:chromeOptions' => ['args' => ['a', 'b', 'c']], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $browserName | ||
* @param array<string, mixed> $desiredCapabilities | ||
* @return WebdriverClassicDriver&object{capabilities: array<string, mixed>} | ||
*/ | ||
private function createDriverExposingCapabilities(string $browserName, array $desiredCapabilities = []): WebdriverClassicDriver | ||
{ | ||
return new class($browserName, $desiredCapabilities) extends WebdriverClassicDriver { | ||
Check failure on line 89 in tests/Custom/CapabilityTest.php GitHub Actions / Static analysis
Check failure on line 89 in tests/Custom/CapabilityTest.php GitHub Actions / Static analysis
|
||
public ?array $capabilities = null; | ||
|
||
public function __construct(string $browserName, array $desiredCapabilities) | ||
{ | ||
parent::__construct($browserName, $desiredCapabilities); | ||
|
||
$this->capabilities = $this->getDesiredCapabilities(); | ||
} | ||
}; | ||
} | ||
} |