From a0779134200996f0d30557d14dc11840af7633a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20=C5=A0trba?= Date: Mon, 6 Apr 2020 21:46:10 +0200 Subject: [PATCH 1/3] Add PHPUnit 9 compatibility --- .ci/vagrant_pre_setup.sh | 2 +- .travis.yml | 1 - composer.json | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.ci/vagrant_pre_setup.sh b/.ci/vagrant_pre_setup.sh index 359f710a..ba28e76e 100644 --- a/.ci/vagrant_pre_setup.sh +++ b/.ci/vagrant_pre_setup.sh @@ -8,5 +8,5 @@ apt-get install software-properties-common -y apt-get install python-software-properties -y # installing xvfb, java and php -apt-get install xvfb php7.2-cli php7.2-curl php7.2-xml php7.2-mbstring php-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends +apt-get install xvfb php7.3-cli php7.3-curl php7.3-xml php7.3-mbstring php-xdebug ncurses-term unzip xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic vim -y --no-install-recommends diff --git a/.travis.yml b/.travis.yml index 54424340..497273f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php dist: xenial php: - - 7.2 - 7.3 - 7.4 diff --git a/composer.json b/composer.json index 41f1af45..dc2c6d0b 100644 --- a/composer.json +++ b/composer.json @@ -43,9 +43,9 @@ "issues": "https://github.com/giorgiosironi/phpunit-selenium/issues" }, "require": { - "php": ">=7.2", + "php": ">=7.3", "ext-curl": "*", - "phpunit/phpunit": ">=8.0,<9.0" + "phpunit/phpunit": ">=9.0,<10.0" }, "require-dev": { "phing/phing": "2.*" From 97676a2855319cddd2bed9c92d8dd328cabad8bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20=C5=A0trba?= Date: Mon, 6 Apr 2020 21:47:21 +0200 Subject: [PATCH 2/3] Fix ScreenshotListener and generating output filename based on class name (convert PSR-4 to PSR-0) --- PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php b/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php index 28a6b963..5f3cd27a 100644 --- a/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php +++ b/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php @@ -87,11 +87,13 @@ private function storeAScreenshot(Test $test) { if ($test instanceof Selenium2TestCase) { + $className = str_replace('\\', '_', get_class($test)); + try { - $file = $this->directory . '/' . get_class($test) . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.png'; + $file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.png'; file_put_contents($file, $test->currentScreenshot()); } catch (\Exception $e) { - $file = $this->directory . '/' . get_class($test) . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.txt'; + $file = $this->directory . '/' . $className . '__' . $test->getName() . '__' . date('Y-m-d\TH-i-s') . '.txt'; file_put_contents($file, "Screenshot generation doesn't work." . "\n" . $e->getMessage() . "\n" . $e->getTraceAsString()); From fdb7cb5a18f2c5a617d7dffb62e187d94d0a6f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20=C5=A0trba?= Date: Mon, 6 Apr 2020 21:47:43 +0200 Subject: [PATCH 3/3] Fix tests + Add PSR-4 to tests --- Tests/CodeCoverageTest.php | 2 ++ Tests/Selenium2TestCase/BaseTestCase.php | 4 ++- .../Selenium2TestCase/Coverage/CookieTest.php | 6 ++++- .../Coverage/RemoteCoverageTest.php | 4 ++- .../Coverage/SingleFileTest.php | 5 +++- .../CustomDesiredCapabilitiesTest.php | 5 +++- Tests/Selenium2TestCase/FailuresTest.php | 12 +++++++-- Tests/Selenium2TestCase/LogTest.php | 5 +++- .../Selenium2TestCase/MobileFeaturesTest.php | 5 +++- .../MultipleBrowsersMethodTest.php | 6 ++++- .../MultipleBrowsersPropertyTest.php | 5 +++- Tests/Selenium2TestCase/PageObjectTest.php | 15 ++++++----- Tests/Selenium2TestCase/RegressionsTest.php | 5 +++- .../ScreenshotListenerTest.php | 6 ++++- .../SessionCommand/FileTest.php | 6 ++++- .../Selenium2TestCase/SessionInSetupTest.php | 4 ++- Tests/Selenium2TestCase/SetUpPageTest.php | 7 +++-- Tests/Selenium2TestCase/SuiteBuildingTest.php | 11 +++++--- Tests/Selenium2TestCase/TimeoutTest.php | 5 +++- Tests/Selenium2TestCase/URLTest.php | 5 +++- Tests/Selenium2TestCase/WaitUntilTest.php | 5 +++- .../fixtures/SuiteBuildingSuites.php | 6 +++-- Tests/Selenium2TestCaseTest.php | 27 +++++++++++++++---- 23 files changed, 125 insertions(+), 36 deletions(-) diff --git a/Tests/CodeCoverageTest.php b/Tests/CodeCoverageTest.php index 04ce6e1c..e1d6966f 100644 --- a/Tests/CodeCoverageTest.php +++ b/Tests/CodeCoverageTest.php @@ -1,5 +1,7 @@ text(); $this->fail('The element shouldn\'t be accessible.'); } catch (RuntimeException $e) { - $this->assertContains('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage()); + $this->assertStringContainsString('http://seleniumhq.org/exceptions/stale_element_reference.html', $e->getMessage()); } } diff --git a/Tests/Selenium2TestCase/LogTest.php b/Tests/Selenium2TestCase/LogTest.php index b6a487c8..6494cf91 100644 --- a/Tests/Selenium2TestCase/LogTest.php +++ b/Tests/Selenium2TestCase/LogTest.php @@ -1,4 +1,7 @@ array( diff --git a/Tests/Selenium2TestCase/MobileFeaturesTest.php b/Tests/Selenium2TestCase/MobileFeaturesTest.php index 0e94d094..122ead7a 100644 --- a/Tests/Selenium2TestCase/MobileFeaturesTest.php +++ b/Tests/Selenium2TestCase/MobileFeaturesTest.php @@ -1,4 +1,7 @@ url('html/test_type_page1.html'); - $page = new Tests_AuthenticationPage($this); + $page = new AuthenticationPage($this); $welcomePage = $page->username('TestUser') ->password('TestPassword') ->submit(); @@ -12,7 +15,7 @@ public function testAPageInteractsWithElementsExposingAnHigherLevelApi() } } -class Tests_AuthenticationPage +class AuthenticationPage { public function __construct($test) { @@ -36,11 +39,11 @@ public function password($value) public function submit() { $this->test->clickOnElement('submitButton'); - return new Tests_WelcomePage($this->test); + return new WelcomePage($this->test); } } -class Tests_WelcomePage +class WelcomePage { public function __construct($test) { @@ -50,6 +53,6 @@ public function __construct($test) public function assertWelcomeIs($text) { - $this->test->assertRegExp("/$text/", $this->header->text()); + $this->test->assertMatchesRegularExpression("/$text/", $this->header->text()); } } diff --git a/Tests/Selenium2TestCase/RegressionsTest.php b/Tests/Selenium2TestCase/RegressionsTest.php index e460f757..9a66e653 100644 --- a/Tests/Selenium2TestCase/RegressionsTest.php +++ b/Tests/Selenium2TestCase/RegressionsTest.php @@ -1,4 +1,7 @@ url('html/test_type_page1.html'); @@ -56,6 +59,6 @@ public function setUpPage() public function testSetUpPageIsExecuted() { - $this->assertRegExp('/html\/test_type_page1\.html$/', $this->url()); + $this->assertMatchesRegularExpression('/html\/test_type_page1\.html$/', $this->url()); } } diff --git a/Tests/Selenium2TestCase/SuiteBuildingTest.php b/Tests/Selenium2TestCase/SuiteBuildingTest.php index ce46b0c9..fde44cee 100644 --- a/Tests/Selenium2TestCase/SuiteBuildingTest.php +++ b/Tests/Selenium2TestCase/SuiteBuildingTest.php @@ -1,4 +1,7 @@ assertInstanceOf(TestSuite::class, $suite); $this->assertEquals(2, count($suite->tests())); } @@ -68,7 +73,7 @@ public function testSampleTestCaseBuildsAFullSuiteContainingAllItsTests() public function testAMultipleBrowsersTestCaseBuildsACopyOfEachTestForEachBrowser() { require_once __DIR__ . '/fixtures/SuiteBuildingSuites.php'; - $suite = Extensions_Selenium2MultipleBrowsersTestCaseSample::suite('Extensions_Selenium2MultipleBrowsersTestCaseSample'); + $suite = MultipleBrowsersTestCaseSample::suite(MultipleBrowsersTestCaseSample::class); $this->assertInstanceOf(TestSuite::class, $suite); $this->assertEquals(2, count($suite->tests())); } diff --git a/Tests/Selenium2TestCase/TimeoutTest.php b/Tests/Selenium2TestCase/TimeoutTest.php index fb3d0599..52d07e97 100644 --- a/Tests/Selenium2TestCase/TimeoutTest.php +++ b/Tests/Selenium2TestCase/TimeoutTest.php @@ -1,5 +1,8 @@ url('html/test_geometry.html'); $element = $this->byId('colored'); - $this->assertRegExp('/rgb[a]?\(0,\s*0,\s*255[,\s*1]?\)/', $element->css('background-color')); + $this->assertMatchesRegularExpression('/rgb[a]?\(0,\s*0,\s*255[,\s*1]?\)/', $element->css('background-color')); } public function testClick() @@ -362,7 +367,7 @@ public function testTypingViaTheKeyboard() $this->clickOnElement('submitButton'); $h2 = $this->byCssSelector('h2'); - $this->assertRegExp('/Welcome, TestUser!/', $h2->text()); + $this->assertMatchesRegularExpression('/Welcome, TestUser!/', $h2->text()); } /** @@ -394,9 +399,21 @@ public function testFormsCanBeSubmitted() $usernameInput = $this->byName('username'); $usernameInput->value('TestUser'); - $this->byCssSelector('form')->submit(); + $this->byId('submitButton')->submit(); + + // fix slow submiting + $this->waitUntil(function() { + try { + $this->byCssSelector('h2'); + + return true; + } catch (WebDriverException $e) { + return null; + } + }, 10000); + $h2 = $this->byCssSelector('h2'); - $this->assertRegExp('/Welcome, TestUser!/', $h2->text()); + $this->assertMatchesRegularExpression('/Welcome, TestUser!/', $h2->text()); } /**