77use Behat \Mink \Tests \Driver \Basic \BasicAuthTest ;
88use Behat \Mink \Tests \Driver \Basic \HeaderTest ;
99use Behat \Mink \Tests \Driver \Basic \StatusCodeTest ;
10+ use Behat \Mink \Tests \Driver \Css \HoverTest ;
11+ use Behat \Mink \Tests \Driver \Custom \SeleniumSupportTest ;
12+ use Behat \Mink \Tests \Driver \Form \Html5Test ;
13+ use Behat \Mink \Tests \Driver \Js \EventsTest ;
1014use Behat \Mink \Tests \Driver \Js \JavascriptTest ;
1115
1216class Selenium2Config extends AbstractConfig
1317{
18+
19+ /**
20+ * @var integer
21+ */
22+ protected $ seleniumMajorVersion ;
23+
24+ public function __construct ()
25+ {
26+ $ this ->seleniumMajorVersion = (int ) explode ('. ' , $ _SERVER ['SELENIUM_VERSION ' ] ?? '' )[0 ];
27+ }
28+
1429 public static function getInstance (): self
1530 {
1631 return new self ();
@@ -36,15 +51,17 @@ public function mapRemoteFilePath($file): string
3651
3752 public function skipMessage ($ testCase , $ test ): ?string
3853 {
39- if (
40- 'Behat\Mink\Tests\Driver\Form\Html5Test ' === $ testCase
41- && 'testHtml5Types ' === $ test
42- ) {
43- return 'WebDriver does not support setting value in color inputs. See https://code.google.com/p/selenium/issues/detail?id=7650 ' ;
54+ $ testCallback = [$ testCase , $ test ];
55+
56+ if ([Html5Test::class, 'testHtml5Types ' ] === $ testCallback ) {
57+ return <<<TEXT
58+ WebDriver does not support setting value in color inputs.
59+
60+ See https://code.google.com/p/selenium/issues/detail?id=7650.
61+ TEXT ;
4462 }
4563
46- if (
47- 'Behat\Mink\Tests\Driver\Js\WindowTest ' === $ testCase
64+ if ('Behat\Mink\Tests\Driver\Js\WindowTest ' === $ testCase
4865 && (0 === strpos ($ test , 'testWindowMaximize ' ))
4966 && 'true ' === getenv ('GITHUB_ACTIONS ' )
5067 ) {
@@ -63,20 +80,52 @@ public function skipMessage($testCase, $test): ?string
6380 return 'Checking status code is not supported. ' ;
6481 }
6582
66- if (array (JavascriptTest::class, 'testDragDropOntoHiddenItself ' ) === array ($ testCase , $ test )) {
67- $ seleniumVersion = $ _SERVER ['SELENIUM_VERSION ' ] ?? null ;
83+ if ([JavascriptTest::class, 'testDragDropOntoHiddenItself ' ] === $ testCallback ) {
6884 $ browser = $ _SERVER ['WEB_FIXTURES_BROWSER ' ] ?? null ;
6985
70- if ($ seleniumVersion && version_compare ( $ seleniumVersion , ' 3.0.0 ' , ' < ' ) && $ browser === ' firefox ' ) {
71- return 'The Firefox browser compatible with Selenium Server 2.x doesn \' t fully implement drag-n-drop support. ' ;
86+ if ($ browser === ' firefox ' && $ this -> getSeleniumMajorVersion () === 2 ) {
87+ return 'The Firefox browser compatible with Selenium 2.x does not fully implement drag-n-drop support. ' ;
7288 }
7389 }
7490
91+ // Skip right-clicking tests, when an unsupported Selenium version detected.
92+ if (([HoverTest::class, 'testRightClickHover ' ] === $ testCallback || [EventsTest::class, 'testRightClick ' ] === $ testCallback )
93+ && !$ this ->isRightClickingInSeleniumSupported ()
94+ ) {
95+ return <<<TEXT
96+ Selenium 3.x does not support right-clicking via JsonWireProtocol.
97+
98+ See https://github.com/SeleniumHQ/selenium/commit/085ceed1f55fbaaa1d419b19c73264415c394905.
99+ TEXT ;
100+ }
101+
102+ // Skips all tests, except mentioned below, for an unsupported Selenium version.
103+ if ([SeleniumSupportTest::class, 'testDriverCannotBeUsedInUnsupportedSelenium ' ] !== $ testCallback
104+ && !$ this ->isSeleniumVersionSupported ()
105+ ) {
106+ return 'Does not apply to unsupported Selenium versions. ' ;
107+ }
108+
75109 return parent ::skipMessage ($ testCase , $ test );
76110 }
77111
78112 protected function supportsCss (): bool
79113 {
80114 return true ;
81115 }
116+
117+ public function isRightClickingInSeleniumSupported (): bool
118+ {
119+ return $ this ->getSeleniumMajorVersion () < 3 ;
120+ }
121+
122+ public function isSeleniumVersionSupported (): bool
123+ {
124+ return $ this ->getSeleniumMajorVersion () < 4 ;
125+ }
126+
127+ protected function getSeleniumMajorVersion (): int
128+ {
129+ return $ this ->seleniumMajorVersion ;
130+ }
82131}
0 commit comments