From 6916b0bf61ab19b9d06f50f3c79b209e17f4c9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 4 Aug 2020 13:53:57 +0200 Subject: [PATCH 001/223] Minor improvements and typos fixes --- lib/Remote/RemoteWebElement.php | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/Remote/RemoteWebElement.php b/lib/Remote/RemoteWebElement.php index f8ee1d1fd..0ca59aba7 100644 --- a/lib/Remote/RemoteWebElement.php +++ b/lib/Remote/RemoteWebElement.php @@ -81,8 +81,7 @@ public function click() * Find the first WebDriverElement within this element using the given mechanism. * * @param WebDriverBy $by - * @return RemoteWebElement NoSuchElementException is thrown in - * HttpCommandExecutor if no element is found. + * @return RemoteWebElement NoSuchElementException is thrown in HttpCommandExecutor if no element is found. * @see WebDriverBy */ public function findElement(WebDriverBy $by) @@ -213,10 +212,10 @@ public function getCoordinates() $element = $this; $on_screen = null; // planned but not yet implemented - $in_view_port = function () use ($element) { + $in_view_port = static function () use ($element) { return $element->getLocationOnScreenOnceScrolledIntoView(); }; - $on_page = function () use ($element) { + $on_page = static function () use ($element) { return $element->getLocation(); }; $auxiliary = $this->getID(); @@ -304,7 +303,7 @@ public function isEnabled() } /** - * Determine whether or not this element is selected or not. + * Determine whether this element is selected or not. * * @return bool */ @@ -367,8 +366,7 @@ public function sendKeys($value) } /** - * Set the fileDetector in order to let the RemoteWebElement to know that - * you are going to upload a file. + * Set the fileDetector in order to let the RemoteWebElement to know that you are going to upload a file. * * Basically, if you want WebDriver trying to send a file, set the fileDetector * to be LocalFileDetector. Otherwise, keep it UselessFileDetector. @@ -427,7 +425,7 @@ public function getID() } /** - * Take screenshot of a specific element. + * Take a screenshot of a specific element. * * @param string $save_as The path of the screenshot to be saved. * @return string The screenshot in PNG format. @@ -454,7 +452,7 @@ public function takeElementScreenshot($save_as = null) } /** - * Test if two element IDs refer to the same DOM element. + * Test if two elements IDs refer to the same DOM element. * * @param WebDriverElement $other * @return bool From e2ae45a78370e2000711ba60de16d7f13317a53a Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Fri, 26 Jun 2020 11:02:41 +0800 Subject: [PATCH 002/223] Work around NULL key issue in sendKeys A long-standing geckodriver bug (https://bugzilla.mozilla.org/show_bug.cgi?id=1494661) means that it is not possible to send a key combination such as SHIFT + 'h' + NULL + 'ello'. In this case the NULL key does not clear the SHIFT modifier as per the specification, and it additionally prints a character for the NULL key. It is possible to work around this bug by splitting on the encoded key and sending the input in multiple commands instead. Geckodriver already sends an implicity NULL at the end of the sendKeys command which does work, does release the modifier and does not print any character. --- lib/Remote/RemoteWebElement.php | 24 +++++++++++++++-------- tests/functional/RemoteWebElementTest.php | 8 ++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/Remote/RemoteWebElement.php b/lib/Remote/RemoteWebElement.php index 0ca59aba7..b4b640374 100644 --- a/lib/Remote/RemoteWebElement.php +++ b/lib/Remote/RemoteWebElement.php @@ -325,14 +325,20 @@ public function sendKeys($value) { $local_file = $this->fileDetector->getLocalFile($value); + $params = []; if ($local_file === null) { if ($this->isW3cCompliant) { - $params = [ - 'text' => WebDriverKeys::encode($value, true), - ':id' => $this->id, - ]; + // Work around the Geckodriver NULL issue by splitting on NULL and calling sendKeys multiple times. + // See https://bugzilla.mozilla.org/show_bug.cgi?id=1494661. + $encodedValues = explode(WebDriverKeys::NULL, WebDriverKeys::encode($value, true)); + foreach ($encodedValues as $encodedValue) { + $params[] = [ + 'text' => $encodedValue, + ':id' => $this->id, + ]; + } } else { - $params = [ + $params[] = [ 'value' => WebDriverKeys::encode($value), ':id' => $this->id, ]; @@ -348,19 +354,21 @@ public function sendKeys($value) $fileName = $local_file; } - $params = [ + $params[] = [ 'text' => $fileName, ':id' => $this->id, ]; } else { - $params = [ + $params[] = [ 'value' => WebDriverKeys::encode($this->upload($local_file)), ':id' => $this->id, ]; } } - $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $params); + foreach ($params as $param) { + $this->executor->execute(DriverCommand::SEND_KEYS_TO_ELEMENT, $param); + } return $this; } diff --git a/tests/functional/RemoteWebElementTest.php b/tests/functional/RemoteWebElementTest.php index cacf16390..021e6ed1a 100644 --- a/tests/functional/RemoteWebElementTest.php +++ b/tests/functional/RemoteWebElementTest.php @@ -152,12 +152,20 @@ public function testShouldSendKeysToFormElement() $input->sendKeys(' baz'); $this->assertSame('foo bar baz', $input->getAttribute('value')); + $input->clear(); + $input->sendKeys([WebDriverKeys::SHIFT, 'H', WebDriverKeys::NULL, 'ello']); + $this->assertSame('Hello', $input->getAttribute('value')); + $textarea->clear(); $textarea->sendKeys('foo bar'); $this->assertSame('foo bar', $textarea->getAttribute('value')); $textarea->sendKeys(' baz'); $this->assertSame('foo bar baz', $textarea->getAttribute('value')); + $textarea->clear(); + $textarea->sendKeys([WebDriverKeys::SHIFT, 'H', WebDriverKeys::NULL, 'ello']); + $this->assertSame('Hello', $textarea->getAttribute('value')); + // Send keys as array $textarea->clear(); $textarea->sendKeys(['bat', 1, '3', ' ', 3, '7']); From 99ec34e9ee006a80042dd860f17010f13ddabed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Wed, 9 Sep 2020 17:44:26 +0200 Subject: [PATCH 003/223] Update travis build to latest geckodriver --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a773b2c6f..134f39466 100644 --- a/.travis.yml +++ b/.travis.yml @@ -132,7 +132,7 @@ before_script: unzip chromedriver_linux64.zip -d chromedriver; fi - if [ "$BROWSER_NAME" = "chrome" ]; then export CHROMEDRIVER_PATH=$PWD/chromedriver/chromedriver; fi - - if [ "$GECKODRIVER" = "1" ]; then mkdir -p geckodriver; wget -q -t 3 https://github.com/mozilla/geckodriver/releases/download/v0.26.0/geckodriver-v0.26.0-linux64.tar.gz; tar xzf geckodriver-v0.26.0-linux64.tar.gz -C geckodriver; fi + - if [ "$GECKODRIVER" = "1" ]; then mkdir -p geckodriver; wget -q -t 3 https://github.com/mozilla/geckodriver/releases/download/v0.27.0/geckodriver-v0.27.0-linux64.tar.gz; tar xzf geckodriver-v0.27.0-linux64.tar.gz -C geckodriver; fi - if [ ! -f jar/selenium-server-standalone.jar ] && [ -n "$SELENIUM_SERVER" ]; then mkdir -p jar; if [ "$SELENIUM_SERVER" = "legacy" ]; then From d01e823a2605118f41638e7d8ebcce870ff70e1d Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Mon, 22 Jun 2020 23:55:53 +0300 Subject: [PATCH 004/223] Make sure that chromeOptions is an object when empty --- lib/Chrome/ChromeOptions.php | 14 ++++++---- lib/Remote/DesiredCapabilities.php | 8 ++++-- tests/unit/Remote/DesiredCapabilitiesTest.php | 28 +++++++++++++------ 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/lib/Chrome/ChromeOptions.php b/lib/Chrome/ChromeOptions.php index af99d3cfe..1b3c4cbdc 100644 --- a/lib/Chrome/ChromeOptions.php +++ b/lib/Chrome/ChromeOptions.php @@ -117,17 +117,19 @@ public function toCapabilities() } /** - * @return array + * @return \ArrayObject|array */ public function toArray() { - $options = $this->experimentalOptions; - // The selenium server expects a 'dictionary' instead of a 'list' when // reading the chrome option. However, an empty array in PHP will be - // converted to a 'list' instead of a 'dictionary'. To fix it, we always - // set the 'binary' to avoid returning an empty array. - $options['binary'] = $this->binary; + // converted to a 'list' instead of a 'dictionary'. To fix it, we work + // with `ArrayObject` + $options = new \ArrayObject($this->experimentalOptions); + + if (!empty($this->binary)) { + $options['binary'] = $this->binary; + } if (!empty($this->arguments)) { $options['args'] = $this->arguments; diff --git a/lib/Remote/DesiredCapabilities.php b/lib/Remote/DesiredCapabilities.php index e022ccecd..5fcf651d9 100644 --- a/lib/Remote/DesiredCapabilities.php +++ b/lib/Remote/DesiredCapabilities.php @@ -235,9 +235,11 @@ public function toW3cCompatibleArray() // Convert ChromeOptions if (array_key_exists(ChromeOptions::CAPABILITY, $ossCapabilities)) { if (array_key_exists(ChromeOptions::CAPABILITY_W3C, $ossCapabilities)) { - $w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = array_merge_recursive( - $ossCapabilities[ChromeOptions::CAPABILITY], - $ossCapabilities[ChromeOptions::CAPABILITY_W3C] + $w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = new \ArrayObject( + array_merge_recursive( + (array) $ossCapabilities[ChromeOptions::CAPABILITY], + (array) $ossCapabilities[ChromeOptions::CAPABILITY_W3C] + ) ); } else { $w3cCapabilities[ChromeOptions::CAPABILITY_W3C] = $ossCapabilities[ChromeOptions::CAPABILITY]; diff --git a/tests/unit/Remote/DesiredCapabilitiesTest.php b/tests/unit/Remote/DesiredCapabilitiesTest.php index f74eb754d..f24d8eb40 100644 --- a/tests/unit/Remote/DesiredCapabilitiesTest.php +++ b/tests/unit/Remote/DesiredCapabilitiesTest.php @@ -213,15 +213,24 @@ public function provideW3cCapabilities() 'vendor:prefix' => 'vendor extension should be kept', ], ], + 'chromeOptions should be an object if empty' => [ + new DesiredCapabilities([ + ChromeOptions::CAPABILITY => new ChromeOptions(), + ]), + [ + 'goog:chromeOptions' => new \ArrayObject(), + ], + ], 'chromeOptions should be converted' => [ new DesiredCapabilities([ ChromeOptions::CAPABILITY => $chromeOptions, ]), [ - 'goog:chromeOptions' => [ - 'args' => ['--headless'], - 'binary' => '', - ], + 'goog:chromeOptions' => new \ArrayObject( + [ + 'args' => ['--headless'], + ] + ), ], ], 'chromeOptions should be merged if already defined' => [ @@ -233,11 +242,12 @@ public function provideW3cCapabilities() ], ]), [ - 'goog:chromeOptions' => [ - 'args' => ['--headless', 'window-size=1024,768'], - 'binary' => '', - 'debuggerAddress' => '127.0.0.1:38947', - ], + 'goog:chromeOptions' => new \ArrayObject( + [ + 'args' => ['--headless', 'window-size=1024,768'], + 'debuggerAddress' => '127.0.0.1:38947', + ] + ), ], ], 'firefox_profile should be converted' => [ From 33284ca385542df62a15ee53cc82eef33ca0c407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Thu, 10 Sep 2020 13:45:09 +0200 Subject: [PATCH 005/223] Run SauceLabs tests via GitHub Actions --- .github/workflows/sauce-labs.yaml | 66 ++++++++++++++++++++++++++ .travis.yml | 46 +----------------- composer.json | 1 + tests/functional/WebDriverTestCase.php | 26 +++++++--- 4 files changed, 88 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/sauce-labs.yaml diff --git a/.github/workflows/sauce-labs.yaml b/.github/workflows/sauce-labs.yaml new file mode 100644 index 000000000..9398909ae --- /dev/null +++ b/.github/workflows/sauce-labs.yaml @@ -0,0 +1,66 @@ +name: Sauce Labs + +on: + push: + schedule: + - cron: '0 3 * * *' + +jobs: + tests: + runs-on: ubuntu-latest + env: + SAUCELABS: 1 + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + strategy: + fail-fast: false + matrix: + include: + - { name: "Firefox 47, OSS protocol", BROWSER_NAME: "firefox", VERSION: "47.0", PLATFORM: "Windows 10", DISABLE_W3C_PROTOCOL: "1", tunnel-id: "gh-1" } + - { name: "Chrome 74, OSS protocol", BROWSER_NAME: "chrome", VERSION: "74.0", PLATFORM: "Windows 10", DISABLE_W3C_PROTOCOL: "1", tunnel-id: "gh-2" } # 74 is the last version which don't use W3C WebDriver by default + - { name: "Chrome latest, W3C protocol", BROWSER_NAME: "chrome", VERSION: "latest", PLATFORM: "Windows 10", tunnel-id: "gh-3" } + - { name: "Edge latest, W3C protocol", BROWSER_NAME: "MicrosoftEdge", VERSION: "latest", PLATFORM: "Windows 10", tunnel-id: "gh-4" } + + name: ${{ matrix.name }} (${{ matrix.tunnel-id }}) + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + extensions: mbstring, intl, zip + + - name: Install dependencies + run: composer update --no-interaction + + - name: Start local PHP server + run: | + php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log & + + - name: Start Sauce Connect + uses: saucelabs/sauce-connect-action@master + with: + username: ${{ secrets.SAUCE_USERNAME }} + accessKey: ${{ secrets.SAUCE_ACCESS_KEY }} + tunnelIdentifier: ${{ matrix.tunnel-id }} + + - name: Run tests + env: + BROWSER_NAME: ${{ matrix.BROWSER_NAME }} + VERSION: ${{ matrix.VERSION }} + PLATFORM: ${{ matrix.PLATFORM }} + DISABLE_W3C_PROTOCOL: ${{ matrix.DISABLE_W3C_PROTOCOL }} + SAUCE_TUNNEL_IDENTIFIER: ${{ matrix.tunnel-id }} + run: | + if [ -n "$SAUCELABS" ]; then EXCLUDE_GROUP+="exclude-saucelabs,"; fi + if [ "$BROWSER_NAME" = "MicrosoftEdge" ]; then EXCLUDE_GROUP+="exclude-edge,"; fi + if [ "$BROWSER_NAME" = "firefox" ]; then EXCLUDE_GROUP+="exclude-firefox,"; fi + if [ "$BROWSER_NAME" = "chrome" ]; then EXCLUDE_GROUP+="exclude-chrome,"; fi + if [ -n "$EXCLUDE_GROUP" ]; then EXTRA_PARAMS+=" --exclude-group $EXCLUDE_GROUP"; fi + ./vendor/bin/phpunit --coverage-clover ./logs/coverage-clover.xml $EXTRA_PARAMS + + - name: Print logs + if: ${{ always() }} + run: | + if [ -f ./logs/php-server.log ]; then cat ./logs/php-server.log; fi diff --git a/.travis.yml b/.travis.yml index 134f39466..a627edc09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -70,51 +70,6 @@ matrix: addons: chrome: stable - # Saucelabs builds - - name: 'Sauce Labs, Firefox 47, OSS protocol' - php: '7.3' - env: SAUCELABS=1 BROWSER_NAME="firefox" VERSION="47.0" PLATFORM="Windows 10" DISABLE_W3C_PROTOCOL="1" - before_script: - - php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log & - - until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started" - addons: - sauce_connect: true - jwt: - secure: 5s8iQfH1dHgEm0DeP9VZ/MCzCeiE/HnMWqPFzRmg6VD2qJ53oYdseo8j+QCbE25MIwoSnIbKzlnbCN6fVzZc/0S7Mo45xJiq8xVLPSdMjDoOeqYE4of+t5Srq4iSzGLPCLiMTtB4xDEl6blUVGhYxN5rA/tVN+cVtLNQvo3ovRon3Mw3MqR4pgCE6PofcLXtyJc3KuOBlUJLWdPGRdlZrpKWE5ogyj4a1h4bVwidckZqkOF+gm58Gf0zVfFazDQFIw2Xuq7SZmiNgdOD5yUEePkrMhy2tbOlPNAIgHCpzHldv5Y+GYyxIYHZ0mGlGxHrfjrcAoSA6r2iXB9q2ijLVwqOARpcvGcBzZBil9aMAHRIXHAOV9Ihv4velrzmiLKADtD60Bfj2zzntGYZA3EGucitMMkkP7vfAa769i5QWK1Lniq3+VUuGNVjRzl4GuQPpc0wMWeJvQGc5Uf9Kk/sOCkPp0SPWcZ6nNAUebRy3V5OoADA9IntyXxfTlZdOHSbJTsG+eOGve0uLGRAOS+oeCstO7Gk4e/Ylozju+ixkINEY7HHDGt6AyHGtjPdy08Y0XrIqs0JMxsHKrtTVNxDjIFKbMees+vtxU3DEr/tNo1sTo34ieGKZP2Cp5mG/IrcjD1saebUaCngQO3QfeuKcU8pBTR7l7PtFNHm3HrmdkY= - - - name: 'Sauce Labs, Chrome 74, OSS protocol' - php: '7.3' - env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="74.0" PLATFORM="Windows 10" DISABLE_W3C_PROTOCOL="1" # 74 is the last version which don't use W3C WebDriver by default - before_script: - - php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log & - - until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started" - addons: - sauce_connect: true - jwt: - secure: 5s8iQfH1dHgEm0DeP9VZ/MCzCeiE/HnMWqPFzRmg6VD2qJ53oYdseo8j+QCbE25MIwoSnIbKzlnbCN6fVzZc/0S7Mo45xJiq8xVLPSdMjDoOeqYE4of+t5Srq4iSzGLPCLiMTtB4xDEl6blUVGhYxN5rA/tVN+cVtLNQvo3ovRon3Mw3MqR4pgCE6PofcLXtyJc3KuOBlUJLWdPGRdlZrpKWE5ogyj4a1h4bVwidckZqkOF+gm58Gf0zVfFazDQFIw2Xuq7SZmiNgdOD5yUEePkrMhy2tbOlPNAIgHCpzHldv5Y+GYyxIYHZ0mGlGxHrfjrcAoSA6r2iXB9q2ijLVwqOARpcvGcBzZBil9aMAHRIXHAOV9Ihv4velrzmiLKADtD60Bfj2zzntGYZA3EGucitMMkkP7vfAa769i5QWK1Lniq3+VUuGNVjRzl4GuQPpc0wMWeJvQGc5Uf9Kk/sOCkPp0SPWcZ6nNAUebRy3V5OoADA9IntyXxfTlZdOHSbJTsG+eOGve0uLGRAOS+oeCstO7Gk4e/Ylozju+ixkINEY7HHDGt6AyHGtjPdy08Y0XrIqs0JMxsHKrtTVNxDjIFKbMees+vtxU3DEr/tNo1sTo34ieGKZP2Cp5mG/IrcjD1saebUaCngQO3QfeuKcU8pBTR7l7PtFNHm3HrmdkY= - - - name: 'Sauce Labs, Chrome latest, W3C protocol' - php: '7.3' - env: SAUCELABS=1 BROWSER_NAME="chrome" VERSION="latest" PLATFORM="Windows 10" - before_script: - - php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log & - - until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started" - addons: - sauce_connect: true - jwt: - secure: 5s8iQfH1dHgEm0DeP9VZ/MCzCeiE/HnMWqPFzRmg6VD2qJ53oYdseo8j+QCbE25MIwoSnIbKzlnbCN6fVzZc/0S7Mo45xJiq8xVLPSdMjDoOeqYE4of+t5Srq4iSzGLPCLiMTtB4xDEl6blUVGhYxN5rA/tVN+cVtLNQvo3ovRon3Mw3MqR4pgCE6PofcLXtyJc3KuOBlUJLWdPGRdlZrpKWE5ogyj4a1h4bVwidckZqkOF+gm58Gf0zVfFazDQFIw2Xuq7SZmiNgdOD5yUEePkrMhy2tbOlPNAIgHCpzHldv5Y+GYyxIYHZ0mGlGxHrfjrcAoSA6r2iXB9q2ijLVwqOARpcvGcBzZBil9aMAHRIXHAOV9Ihv4velrzmiLKADtD60Bfj2zzntGYZA3EGucitMMkkP7vfAa769i5QWK1Lniq3+VUuGNVjRzl4GuQPpc0wMWeJvQGc5Uf9Kk/sOCkPp0SPWcZ6nNAUebRy3V5OoADA9IntyXxfTlZdOHSbJTsG+eOGve0uLGRAOS+oeCstO7Gk4e/Ylozju+ixkINEY7HHDGt6AyHGtjPdy08Y0XrIqs0JMxsHKrtTVNxDjIFKbMees+vtxU3DEr/tNo1sTo34ieGKZP2Cp5mG/IrcjD1saebUaCngQO3QfeuKcU8pBTR7l7PtFNHm3HrmdkY= - - - name: 'Sauce Labs, Edge latest, W3C protocol' - php: '7.3' - env: SAUCELABS=1 BROWSER_NAME="MicrosoftEdge" VERSION="latest" PLATFORM="Windows 10" - before_script: - - php -S 127.0.0.1:8000 -t tests/functional/web/ &>>./logs/php-server.log & - - until $(echo | nc localhost 8000); do sleep 1; echo waiting for PHP server on port 8000...; done; echo "PHP server started" - addons: - sauce_connect: true - jwt: - secure: 5s8iQfH1dHgEm0DeP9VZ/MCzCeiE/HnMWqPFzRmg6VD2qJ53oYdseo8j+QCbE25MIwoSnIbKzlnbCN6fVzZc/0S7Mo45xJiq8xVLPSdMjDoOeqYE4of+t5Srq4iSzGLPCLiMTtB4xDEl6blUVGhYxN5rA/tVN+cVtLNQvo3ovRon3Mw3MqR4pgCE6PofcLXtyJc3KuOBlUJLWdPGRdlZrpKWE5ogyj4a1h4bVwidckZqkOF+gm58Gf0zVfFazDQFIw2Xuq7SZmiNgdOD5yUEePkrMhy2tbOlPNAIgHCpzHldv5Y+GYyxIYHZ0mGlGxHrfjrcAoSA6r2iXB9q2ijLVwqOARpcvGcBzZBil9aMAHRIXHAOV9Ihv4velrzmiLKADtD60Bfj2zzntGYZA3EGucitMMkkP7vfAa769i5QWK1Lniq3+VUuGNVjRzl4GuQPpc0wMWeJvQGc5Uf9Kk/sOCkPp0SPWcZ6nNAUebRy3V5OoADA9IntyXxfTlZdOHSbJTsG+eOGve0uLGRAOS+oeCstO7Gk4e/Ylozju+ixkINEY7HHDGt6AyHGtjPdy08Y0XrIqs0JMxsHKrtTVNxDjIFKbMees+vtxU3DEr/tNo1sTo34ieGKZP2Cp5mG/IrcjD1saebUaCngQO3QfeuKcU8pBTR7l7PtFNHm3HrmdkY= - cache: directories: - $HOME/.composer/cache @@ -156,6 +111,7 @@ before_script: script: - if [ -n "$SAUCELABS" ]; then EXCLUDE_GROUP+="exclude-saucelabs,"; fi + - if [ -n "$SAUCELABS" ]; then export SAUCE_TUNNEL_IDENTIFIER="$TRAVIS_JOB_NUMBER"; fi - if [ "$BROWSER_NAME" = "MicrosoftEdge" ]; then EXCLUDE_GROUP+="exclude-edge,"; fi - if [ "$BROWSER_NAME" = "firefox" ]; then EXCLUDE_GROUP+="exclude-firefox,"; fi - if [ "$BROWSER_NAME" = "chrome" ]; then EXCLUDE_GROUP+="exclude-chrome,"; fi diff --git a/composer.json b/composer.json index 7c0f1fdc3..b94e7ac94 100644 --- a/composer.json +++ b/composer.json @@ -24,6 +24,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", + "ondram/ci-detector": "^2.1 || ^3.5", "php-coveralls/php-coveralls": "^2.0", "php-mock/php-mock-phpunit": "^1.1", "php-parallel-lint/php-parallel-lint": "^1.2", diff --git a/tests/functional/WebDriverTestCase.php b/tests/functional/WebDriverTestCase.php index 9718cd671..76c79bb7d 100644 --- a/tests/functional/WebDriverTestCase.php +++ b/tests/functional/WebDriverTestCase.php @@ -8,6 +8,7 @@ use Facebook\WebDriver\Remote\DesiredCapabilities; use Facebook\WebDriver\Remote\RemoteWebDriver; use Facebook\WebDriver\Remote\WebDriverBrowserType; +use OndraM\CiDetector\CiDetector; use PHPUnit\Framework\TestCase; /** @@ -174,9 +175,18 @@ protected function setUpSauceLabs() $name = get_class($this) . '::' . $this->getName(); $tags = [get_class($this)]; - if (getenv('TRAVIS_JOB_NUMBER')) { - $tunnelIdentifier = getenv('TRAVIS_JOB_NUMBER'); - $build = getenv('TRAVIS_JOB_NUMBER'); + $ciDetector = new CiDetector(); + if ($ciDetector->isCiDetected()) { + $ci = $ciDetector->detect(); + if (!empty($ci->getBuildNumber())) { + // SAUCE_TUNNEL_IDENTIFIER appended as a workaround for GH actions not having environment value + // to distinguish runs of the matrix + $build = $ci->getBuildNumber() . '.' . getenv('SAUCE_TUNNEL_IDENTIFIER'); + } + } + + if (getenv('SAUCE_TUNNEL_IDENTIFIER')) { + $tunnelIdentifier = getenv('SAUCE_TUNNEL_IDENTIFIER'); } if (!getenv('DISABLE_W3C_PROTOCOL')) { @@ -184,17 +194,21 @@ protected function setUpSauceLabs() 'name' => $name, 'tags' => $tags, ]; - if (isset($tunnelIdentifier, $build)) { - $sauceOptions['tunnelIdentifier'] = $tunnelIdentifier; + if (isset($build)) { $sauceOptions['build'] = $build; } + if (isset($tunnelIdentifier)) { + $sauceOptions['tunnelIdentifier'] = $tunnelIdentifier; + } $this->desiredCapabilities->setCapability('sauce:options', (object) $sauceOptions); } else { $this->desiredCapabilities->setCapability('name', $name); $this->desiredCapabilities->setCapability('tags', $tags); - if (isset($tunnelIdentifier, $build)) { + if (isset($tunnelIdentifier)) { $this->desiredCapabilities->setCapability('tunnel-identifier', $tunnelIdentifier); + } + if (isset($build)) { $this->desiredCapabilities->setCapability('build', $build); } } From 0ac00d8deca08b2c5a94dd9f25533588da94c8ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 6 Oct 2020 20:22:34 +0200 Subject: [PATCH 006/223] Disable composer memory limit in travis builds --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a627edc09..31c92bd5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,7 @@ env: - DISPLAY=:99.0 - BROWSER_NAME="htmlunit" - SELENIUM_SERVER="https://selenium-release.storage.googleapis.com/3.14/selenium-server-standalone-3.14.0.jar" # Latest version including HtmlUnit + - COMPOSER_MEMORY_LIMIT=-1 services: - xvfb From d5790a8daea2172dc3923b1565aed8df12922177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 6 Oct 2020 21:09:25 +0200 Subject: [PATCH 007/223] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c219c31..b4ceccbda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/). ### Fixed - Make `alertIsPresent()` condition working in W3C mode. - `RemoteWebDriver::create()` cannot be used without providing the second parameter (which is in fact optional). +- `ChromeDriver::start()` starts in inconsistent state mixing W3C/OSS mode. +- Modifier keys are not released when sending NULL key in GeckoDriver (workaround for GeckoDriver bug [1494661](https://bugzilla.mozilla.org/show_bug.cgi?id=1494661)). +- Do not set unnecessary `binary` value of `goog:chromeOptions` while keep the object in proper data type required by ChromeDriver. ## 1.8.2 - 2020-03-04 ### Changed From fb0fc4cb01c70a7790a5fcc91d461b88c83174a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 6 Oct 2020 21:10:04 +0200 Subject: [PATCH 008/223] Release version 1.8.3 --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4ceccbda..c4f091d8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/). ## Unreleased + +## 1.8.3 - 2020-10-06 ### Fixed - Make `alertIsPresent()` condition working in W3C mode. - `RemoteWebDriver::create()` cannot be used without providing the second parameter (which is in fact optional). From 841b5b7e099aed453b67b617014f79b822688f90 Mon Sep 17 00:00:00 2001 From: Michael Steininger <11192306+codegain@users.noreply.github.com> Date: Fri, 18 Sep 2020 22:38:24 +0200 Subject: [PATCH 009/223] Add same-site support for cookies (fixes #705) --- lib/Cookie.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/Cookie.php b/lib/Cookie.php index 0e1436089..1005bd0dc 100644 --- a/lib/Cookie.php +++ b/lib/Cookie.php @@ -58,6 +58,9 @@ public static function createFromArray(array $cookieArray) if (isset($cookieArray['httpOnly'])) { $cookie->setHttpOnly($cookieArray['httpOnly']); } + if (isset($cookieArray['sameSite'])) { + $cookie->setSameSite($cookieArray['sameSite']); + } return $cookie; } @@ -172,6 +175,24 @@ public function isHttpOnly() return $this->offsetGet('httpOnly'); } + /** + * The cookie's same-site value. + * + * @param string $sameSite + */ + public function setSameSite($sameSite) + { + $this->offsetSet('sameSite', $sameSite); + } + + /** + * @return string|null + */ + public function getSameSite() + { + return $this->offsetGet('sameSite'); + } + /** * @return array */ From 7efbcb88a34b1df5aeaa1c40bf20d96388633d09 Mon Sep 17 00:00:00 2001 From: Michael Steininger <11192306+codegain@users.noreply.github.com> Date: Tue, 6 Oct 2020 22:07:06 +0200 Subject: [PATCH 010/223] added unit tests for same-site cookie attribute --- tests/unit/CookieTest.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/unit/CookieTest.php b/tests/unit/CookieTest.php index 621fb65c0..cced57524 100644 --- a/tests/unit/CookieTest.php +++ b/tests/unit/CookieTest.php @@ -17,6 +17,7 @@ public function testShouldSetAllProperties() $cookie->setExpiry(1485388387); $cookie->setSecure(true); $cookie->setHttpOnly(true); + $cookie->setSameSite('Lax'); $this->assertSame('cookieName', $cookie->getName()); $this->assertSame('someValue', $cookie->getValue()); @@ -25,6 +26,7 @@ public function testShouldSetAllProperties() $this->assertSame(1485388387, $cookie->getExpiry()); $this->assertTrue($cookie->isSecure()); $this->assertTrue($cookie->isHttpOnly()); + $this->assertSame('Lax', $cookie->getSameSite()); return $cookie; } @@ -44,6 +46,7 @@ public function testShouldBeConvertibleToArray(Cookie $cookie) 'expiry' => 1485388387, 'secure' => true, 'httpOnly' => true, + 'sameSite' => 'Lax', ], $cookie->toArray() ); @@ -84,6 +87,7 @@ public function testShouldProvideArrayAccessToProperties(Cookie $cookie) $this->assertSame(1485388387, $cookie['expiry']); $this->assertTrue($cookie['secure']); $this->assertTrue($cookie['httpOnly']); + $this->assertSame('Lax', $cookie['sameSite']); $cookie->offsetSet('domain', 'bar.com'); $this->assertSame('bar.com', $cookie['domain']); @@ -122,6 +126,10 @@ public function testShouldBeCreatableFromAnArrayWithBasicValues() $this->assertArrayNotHasKey('httpOnly', $cookie); $this->assertNull($cookie['httpOnly']); $this->assertNull($cookie->isHttpOnly()); + + $this->assertArrayNotHasKey('sameSite', $cookie); + $this->assertNull($cookie['sameSite']); + $this->assertNull($cookie->getSameSite()); } public function testShouldBeCreatableFromAnArrayWithAllValues() @@ -134,6 +142,7 @@ public function testShouldBeCreatableFromAnArrayWithAllValues() 'expiry' => 1485388333, 'secure' => false, 'httpOnly' => false, + 'sameSite' => 'Lax', ]; $cookie = Cookie::createFromArray($sourceArray); @@ -145,6 +154,7 @@ public function testShouldBeCreatableFromAnArrayWithAllValues() $this->assertSame(1485388333, $cookie['expiry']); $this->assertFalse($cookie['secure']); $this->assertFalse($cookie['httpOnly']); + $this->assertSame('Lax', $cookie['sameSite']); } /** From 4fbb161f0a480b48cce0116af581c61c3fd8c347 Mon Sep 17 00:00:00 2001 From: Michael Steininger <11192306+codegain@users.noreply.github.com> Date: Tue, 6 Oct 2020 22:38:12 +0200 Subject: [PATCH 011/223] Updated testShouldNotContainNullValues --- tests/unit/CookieTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/CookieTest.php b/tests/unit/CookieTest.php index cced57524..d58419a9a 100644 --- a/tests/unit/CookieTest.php +++ b/tests/unit/CookieTest.php @@ -67,6 +67,7 @@ public function testShouldNotContainNullValues() $cookie->setHttpOnly(null); $cookie->setPath(null); + $cookie->setSameSite(null); $cookieArray = $cookie->toArray(); foreach ($cookieArray as $key => $value) { From c106a41a1a75e3e3e163f6a3f58aeec80e434b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Tue, 6 Oct 2020 23:12:46 +0200 Subject: [PATCH 012/223] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4f091d8a..5009ff1dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ This project versioning adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Added +- Support of SameSite cookie property. ## 1.8.3 - 2020-10-06 ### Fixed From 9e8aeac43ec9e3e2f530c7662ecb67cbb4150495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Mon, 16 Nov 2020 15:26:32 +0100 Subject: [PATCH 013/223] Move phpstan path and level config to file --- phpstan.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/phpstan.neon b/phpstan.neon index b0777e2c2..846484976 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,4 +1,9 @@ parameters: + level: 2 + paths: + - lib/ + - tests/ + ignoreErrors: # To be fixed: - '#Call to an undefined method Facebook\\WebDriver\\WebDriver::getTouch\(\)#' From 5898a74ce2bb87b2b755d322069200c7460fe907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Mon, 16 Nov 2020 15:30:31 +0100 Subject: [PATCH 014/223] Workaround for broken PHPStan parallel processing --- composer.json | 3 ++- phpstan-webdriverkeys.neon | 6 ++++++ phpstan.neon | 3 +++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 phpstan-webdriverkeys.neon diff --git a/composer.json b/composer.json index b94e7ac94..0a3e81ae3 100644 --- a/composer.json +++ b/composer.json @@ -68,7 +68,8 @@ "scripts": { "analyze": [ "vendor/bin/parallel-lint -j 10 ./lib ./tests example.php", - "vendor/bin/phpstan.phar analyze ./lib ./tests --level 2 -c phpstan.neon --ansi" + "vendor/bin/phpstan.phar analyze -c phpstan.neon --ansi", + "vendor/bin/phpstan.phar analyze -c phpstan-webdriverkeys.neon --ansi" ], "codestyle:check": [ "vendor/bin/php-cs-fixer fix --diff --diff-format=udiff --dry-run -vvv --ansi", diff --git a/phpstan-webdriverkeys.neon b/phpstan-webdriverkeys.neon new file mode 100644 index 000000000..799558876 --- /dev/null +++ b/phpstan-webdriverkeys.neon @@ -0,0 +1,6 @@ +# WebDriverKeys.php breaks PHPStan parallel processing, so we must analyze the file separately. +# See https://github.com/phpstan/phpstan/issues/3956 and https://github.com/clue/reactphp-ndjson/issues/21 +parameters: + level: 2 + paths: + - lib/WebDriverKeys.php diff --git a/phpstan.neon b/phpstan.neon index 846484976..4b12710a5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,3 +16,6 @@ parameters: path: 'lib/Remote/RemoteWebDriver.php' inferPrivatePropertyTypeFromConstructor: true + + excludes_analyse: + - lib/WebDriverKeys.php From 4d2eb507e6308b8794ddf0b2e75be245bbff967c Mon Sep 17 00:00:00 2001 From: William Desportes Date: Mon, 16 Nov 2020 16:22:05 +0100 Subject: [PATCH 015/223] Scripts and configuration changes for PHP 8 Co-Authored-By: Dries Vints --- .gitattributes | 1 + .github/workflows/php.yaml | 2 +- .gitignore | 1 + .php_cs.dist | 2 +- .travis.yml | 22 ++++++++++++++++++---- composer.json | 10 ++++------ scripts/apply-phpunit-patches.sh | 20 ++++++++++++++++++++ 7 files changed, 46 insertions(+), 12 deletions(-) create mode 100755 scripts/apply-phpunit-patches.sh diff --git a/.gitattributes b/.gitattributes index 3123b82f2..8a5e272b2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,5 +1,6 @@ * text=auto +/scripts export-ignore /tests export-ignore /.gitattributes export-ignore /.gitignore export-ignore diff --git a/.github/workflows/php.yaml b/.github/workflows/php.yaml index c96bec74e..3065ff732 100644 --- a/.github/workflows/php.yaml +++ b/.github/workflows/php.yaml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v2 - name: Setup PHP - uses: shivammathur/setup-php@v1 + uses: shivammathur/setup-php@v2 with: php-version: '7.4' extensions: mbstring, intl, zip diff --git a/.gitignore b/.gitignore index deb25f3ae..d5605367c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ composer.phar composer.lock vendor .php_cs.cache +.phpunit.result.cache phpunit.xml logs/ diff --git a/.php_cs.dist b/.php_cs.dist index b771f8b04..a438f2095 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -52,7 +52,7 @@ return PhpCsFixer\Config::create() 'ordered_class_elements' => true, 'ordered_imports' => true, 'php_unit_construct' => true, - 'php_unit_dedicate_assert' => true, + 'php_unit_dedicate_assert' => false, 'php_unit_expectation' => ['target' => '5.6'], 'php_unit_method_casing' => ['case' => 'camel_case'], 'php_unit_mock' => true, diff --git a/.travis.yml b/.travis.yml index 31c92bd5d..b8f993e44 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,8 +2,6 @@ language: php dist: xenial php: - - '5.6' - - '7.0' - '7.1' - '7.2' - '7.3' @@ -21,10 +19,25 @@ services: matrix: include: + - name: 'PHP nightly build' + php: 'nightly' + env: DEPENDENCIES="--ignore-platform-req=php" + + - name: 'PHP 7.0' + php: '7.0' + env: RUN_PHPUNIT_PATCHES="true" + + - name: 'PHP 5.6' + php: '5.6' + env: RUN_PHPUNIT_PATCHES="true" + # Build with lowest possible dependencies on lowest possible PHP - name: 'Lowest dependencies build' php: '5.6' - env: DEPENDENCIES="--prefer-lowest" + env: + - DEPENDENCIES="--prefer-lowest" + - RUN_PHPUNIT_PATCHES="true" + # Firefox inside Travis environment - name: 'Firefox 45 on Travis (OSS protocol); via legacy Selenium server' @@ -80,6 +93,7 @@ install: - travis_retry composer update --no-interaction $DEPENDENCIES before_script: + - if [ "$RUN_PHPUNIT_PATCHES" = "true" ]; then ./scripts/apply-phpunit-patches.sh; fi - if [ "$BROWSER_NAME" = "chrome" ]; then mkdir chromedriver; CHROME_VERSION=$(google-chrome --product-version); @@ -126,4 +140,4 @@ after_script: - if [ -f ./logs/chromedriver.log ]; then cat ./logs/chromedriver.log; fi after_success: - - travis_retry php vendor/bin/php-coveralls -v + - if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then travis_retry php vendor/bin/php-coveralls -v; fi diff --git a/composer.json b/composer.json index 0a3e81ae3..88f215101 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "homepage": "https://github.com/php-webdriver/php-webdriver", "license": "MIT", "require": { - "php": "^5.6 || ~7.0", + "php": "^5.6 || ~7.0 || ^8.0", "ext-curl": "*", "ext-json": "*", "ext-zip": "*", @@ -25,12 +25,10 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", "ondram/ci-detector": "^2.1 || ^3.5", - "php-coveralls/php-coveralls": "^2.0", - "php-mock/php-mock-phpunit": "^1.1", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^1.1 || ^2.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpunit/phpunit": "^5.7", - "sebastian/environment": "^1.3.4 || ^2.0 || ^3.0", - "sminnee/phpunit-mock-objects": "^3.4", + "phpunit/phpunit": "^5.7 || ^7 || ^8 || ^9", "squizlabs/php_codesniffer": "^3.5", "symfony/var-dumper": "^3.3 || ^4.0 || ^5.0" }, diff --git a/scripts/apply-phpunit-patches.sh b/scripts/apply-phpunit-patches.sh new file mode 100755 index 000000000..ee1dd00f3 --- /dev/null +++ b/scripts/apply-phpunit-patches.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# All commands below must no fail +set -e + +# Be in the root dir +cd "$(dirname $0)/../" + +find tests/ -type f -print0 | xargs -0 sed -i 's/function setUpBeforeClass(): void/function setUpBeforeClass()/g'; +find tests/ -type f -print0 | xargs -0 sed -i 's/function setUp(): void/function setUp()/g'; +find tests/ -type f -print0 | xargs -0 sed -i 's/function tearDown(): void/function tearDown()/g'; + +sed -i 's/endTest(\\PHPUnit\\Framework\\Test \$test, float \$time): void/endTest(\\PHPUnit_Framework_Test \$test, \$time)/g' tests/functional/ReportSauceLabsStatusListener.php; +sed -i 's/: void/ /g' tests/functional/ReportSauceLabsStatusListener.php; +# Drop the listener from the config file +sed -i '//,+2d' phpunit.xml.dist; +sed -i 's/function runBare(): void/function runBare()/g' tests/functional/WebDriverTestCase.php; + +# Return back to original dir +cd - > /dev/null \ No newline at end of file From 6583dd2fddac651d75ead9189cacc9fec0ef504f Mon Sep 17 00:00:00 2001 From: William Desportes Date: Mon, 16 Nov 2020 12:17:56 +0100 Subject: [PATCH 016/223] PHP 8 and phpunit compatibility changes on source files tests/* --- .../Chrome/ChromeDriverServiceTest.php | 2 +- tests/functional/Chrome/ChromeDriverTest.php | 4 +- tests/functional/RemoteTargetLocatorTest.php | 28 +++++----- .../functional/RemoteWebDriverCreateTest.php | 6 +-- .../RemoteWebDriverFindElementTest.php | 4 +- tests/functional/RemoteWebDriverTest.php | 18 +++---- tests/functional/RemoteWebElementTest.php | 6 +-- .../ReportSauceLabsStatusListener.php | 52 ++++++++++++++++--- tests/functional/WebDriverActionsTest.php | 3 +- tests/functional/WebDriverAlertTest.php | 2 +- tests/functional/WebDriverCheckboxesTest.php | 2 +- .../WebDriverOptionsCookiesTest.php | 2 +- tests/functional/WebDriverRadiosTest.php | 2 +- tests/functional/WebDriverSelectTest.php | 2 +- tests/functional/WebDriverTestCase.php | 22 ++++++-- .../WebDriverButtonReleaseActionTest.php | 6 +-- .../Internal/WebDriverClickActionTest.php | 6 +-- .../WebDriverClickAndHoldActionTest.php | 6 +-- .../WebDriverContextClickActionTest.php | 6 +-- .../Internal/WebDriverCoordinatesTest.php | 22 +++----- .../WebDriverDoubleClickActionTest.php | 6 +-- .../Internal/WebDriverKeyDownActionTest.php | 8 +-- .../Internal/WebDriverKeyUpActionTest.php | 8 +-- .../Internal/WebDriverMouseMoveActionTest.php | 6 +-- .../WebDriverMouseToOffsetActionTest.php | 6 +-- .../Internal/WebDriverSendKeysActionTest.php | 8 +-- tests/unit/Remote/HttpCommandExecutorTest.php | 2 +- tests/unit/Remote/RemoteWebDriverTest.php | 2 +- tests/unit/WebDriverExpectedConditionTest.php | 4 +- tests/unit/WebDriverOptionsTest.php | 4 +- 30 files changed, 151 insertions(+), 104 deletions(-) diff --git a/tests/functional/Chrome/ChromeDriverServiceTest.php b/tests/functional/Chrome/ChromeDriverServiceTest.php index a21727781..1f5baa4f9 100644 --- a/tests/functional/Chrome/ChromeDriverServiceTest.php +++ b/tests/functional/Chrome/ChromeDriverServiceTest.php @@ -11,7 +11,7 @@ */ class ChromeDriverServiceTest extends TestCase { - protected function setUp() + protected function setUp(): void { if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) { $this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome'); diff --git a/tests/functional/Chrome/ChromeDriverTest.php b/tests/functional/Chrome/ChromeDriverTest.php index 26c9de81d..fd7581008 100644 --- a/tests/functional/Chrome/ChromeDriverTest.php +++ b/tests/functional/Chrome/ChromeDriverTest.php @@ -16,14 +16,14 @@ class ChromeDriverTest extends TestCase /** @var ChromeDriver */ protected $driver; - protected function setUp() + protected function setUp(): void { if (!getenv('BROWSER_NAME') === 'chrome' || getenv('SAUCELABS') || !getenv('CHROMEDRIVER_PATH')) { $this->markTestSkipped('ChromeDriverServiceTest is run only when running against local chrome'); } } - protected function tearDown() + protected function tearDown(): void { if ($this->driver instanceof RemoteWebDriver && $this->driver->getCommandExecutor() !== null) { $this->driver->quit(); diff --git a/tests/functional/RemoteTargetLocatorTest.php b/tests/functional/RemoteTargetLocatorTest.php index 8ee5c96bc..9128502b2 100644 --- a/tests/functional/RemoteTargetLocatorTest.php +++ b/tests/functional/RemoteTargetLocatorTest.php @@ -23,7 +23,7 @@ public function testShouldSwitchToWindow() ); // At first the window should not be switched - $this->assertContains('open_new_window.html', $this->driver->getCurrentURL()); + $this->compatAssertStringContainsString('open_new_window.html', $this->driver->getCurrentURL()); $this->assertSame($originalWindowHandle, $this->driver->getWindowHandle()); /** @@ -38,7 +38,7 @@ public function testShouldSwitchToWindow() $this->driver->switchTo()->window($newWindowHandle); // After switchTo() is called, the active window should be changed - $this->assertContains('index.html', $this->driver->getCurrentURL()); + $this->compatAssertStringContainsString('index.html', $this->driver->getCurrentURL()); $this->assertNotSame($originalWindowHandle, $this->driver->getWindowHandle()); } @@ -64,25 +64,25 @@ public function testShouldSwitchToFrameByItsId() $this->driver->get($this->getTestPageUrl('page_with_frame.html')); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); $this->driver->switchTo()->frame(0); - $this->assertContains($firstChildFrame, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource()); $this->driver->switchTo()->frame(null); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); $this->driver->switchTo()->frame(1); - $this->assertContains($secondChildFrame, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($secondChildFrame, $this->driver->getPageSource()); $this->driver->switchTo()->frame(null); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); $this->driver->switchTo()->frame(0); - $this->assertContains($firstChildFrame, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource()); $this->driver->switchTo()->defaultContent(); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); } public function testShouldSwitchToParentFrame() @@ -92,13 +92,13 @@ public function testShouldSwitchToParentFrame() $this->driver->get($this->getTestPageUrl('page_with_frame.html')); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); $this->driver->switchTo()->frame(0); - $this->assertContains($firstChildFrame, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($firstChildFrame, $this->driver->getPageSource()); $this->driver->switchTo()->parent(); - $this->assertContains($parentPage, $this->driver->getPageSource()); + $this->compatAssertStringContainsString($parentPage, $this->driver->getPageSource()); } public function testShouldSwitchToFrameByElement() @@ -108,7 +108,7 @@ public function testShouldSwitchToFrameByElement() $element = $this->driver->findElement(WebDriverBy::id('iframe_content')); $this->driver->switchTo()->frame($element); - $this->assertContains('This is the content of the iFrame', $this->driver->getPageSource()); + $this->compatAssertStringContainsString('This is the content of the iFrame', $this->driver->getPageSource()); } /** @@ -139,6 +139,6 @@ public function testShouldAcceptStringAsFrameIdInJsonWireMode() $this->driver->switchTo()->frame('iframe_content'); - $this->assertContains('This is the content of the iFrame', $this->driver->getPageSource()); + $this->compatAssertStringContainsString('This is the content of the iFrame', $this->driver->getPageSource()); } } diff --git a/tests/functional/RemoteWebDriverCreateTest.php b/tests/functional/RemoteWebDriverCreateTest.php index db379964d..29302e16a 100644 --- a/tests/functional/RemoteWebDriverCreateTest.php +++ b/tests/functional/RemoteWebDriverCreateTest.php @@ -32,7 +32,7 @@ public function testShouldStartBrowserAndCreateInstanceOfRemoteWebDriver() $this->assertInstanceOf(HttpCommandExecutor::class, $this->driver->getCommandExecutor()); $this->assertNotEmpty($this->driver->getCommandExecutor()->getAddressOfRemoteServer()); - $this->assertInternalType('string', $this->driver->getSessionID()); + $this->assertTrue(is_string($this->driver->getSessionID())); $this->assertNotEmpty($this->driver->getSessionID()); $returnedCapabilities = $this->driver->getCapabilities(); @@ -104,7 +104,7 @@ public function testShouldCreateInstanceFromExistingSessionId() $this->requestTimeout ); $originalDriver->get($this->getTestPageUrl('index.html')); - $this->assertContains('/index.html', $originalDriver->getCurrentURL()); + $this->compatAssertStringContainsString('/index.html', $originalDriver->getCurrentURL()); // Store session ID $sessionId = $originalDriver->getSessionID(); @@ -114,7 +114,7 @@ public function testShouldCreateInstanceFromExistingSessionId() $this->driver = RemoteWebDriver::createBySessionID($sessionId, $this->serverUrl, null, null, $isW3cCompliant); // Check we reused the previous instance (window) and it has the same URL - $this->assertContains('/index.html', $this->driver->getCurrentURL()); + $this->compatAssertStringContainsString('/index.html', $this->driver->getCurrentURL()); // Do some interaction with the new driver $this->assertNotEmpty($this->driver->findElement(WebDriverBy::id('id_test'))->getText()); diff --git a/tests/functional/RemoteWebDriverFindElementTest.php b/tests/functional/RemoteWebDriverFindElementTest.php index 4ac265381..5a7d18e70 100644 --- a/tests/functional/RemoteWebDriverFindElementTest.php +++ b/tests/functional/RemoteWebDriverFindElementTest.php @@ -34,7 +34,7 @@ public function testShouldReturnEmptyArrayIfElementsCannotBeFound() $elements = $this->driver->findElements(WebDriverBy::cssSelector('not_existing')); - $this->assertInternalType('array', $elements); + $this->assertTrue(is_array($elements)); $this->assertCount(0, $elements); } @@ -44,7 +44,7 @@ public function testShouldFindMultipleElements() $elements = $this->driver->findElements(WebDriverBy::cssSelector('ul > li')); - $this->assertInternalType('array', $elements); + $this->assertTrue(is_array($elements)); $this->assertCount(5, $elements); $this->assertContainsOnlyInstancesOf(RemoteWebElement::class, $elements); } diff --git a/tests/functional/RemoteWebDriverTest.php b/tests/functional/RemoteWebDriverTest.php index 28b4e52ab..ae289de5d 100644 --- a/tests/functional/RemoteWebDriverTest.php +++ b/tests/functional/RemoteWebDriverTest.php @@ -43,8 +43,8 @@ public function testShouldGetPageSource() $this->driver->get($this->getTestPageUrl('index.html')); $source = $this->driver->getPageSource(); - $this->assertContains('

', $source); - $this->assertContains('Welcome to the php-webdriver testing page.', $source); + $this->compatAssertStringContainsString('

', $source); + $this->compatAssertStringContainsString('Welcome to the php-webdriver testing page.', $source); } /** @@ -63,7 +63,7 @@ public function testShouldGetSessionId() $sessionId = $this->driver->getSessionID(); - $this->assertInternalType('string', $sessionId); + $this->assertTrue(is_string($sessionId)); $this->assertNotEmpty($sessionId); } @@ -79,7 +79,7 @@ public function testShouldGetAllSessions() $sessions = RemoteWebDriver::getAllSessions($this->serverUrl, 30000); - $this->assertInternalType('array', $sessions); + $this->assertTrue(is_array($sessions)); $this->assertCount(1, $sessions); $this->assertArrayHasKey('capabilities', $sessions[0]); @@ -124,7 +124,7 @@ public function testShouldGetWindowHandles() $windowHandle = $this->driver->getWindowHandle(); $windowHandles = $this->driver->getWindowHandles(); - $this->assertInternalType('string', $windowHandle); + $this->assertTrue(is_string($windowHandle)); $this->assertNotEmpty($windowHandle); $this->assertSame([$windowHandle], $windowHandles); @@ -266,7 +266,7 @@ public function testShouldTakeScreenshot() $outputPng = $this->driver->takeScreenshot(); $image = imagecreatefromstring($outputPng); - $this->assertInternalType('resource', $image); + $this->assertTrue(is_resource($image)); $this->assertGreaterThan(0, imagesx($image)); $this->assertGreaterThan(0, imagesy($image)); @@ -292,7 +292,7 @@ public function testShouldSaveScreenshotToFile() $this->driver->takeScreenshot($screenshotPath); $image = imagecreatefrompng($screenshotPath); - $this->assertInternalType('resource', $image); + $this->assertTrue(is_resource($image)); $this->assertGreaterThan(0, imagesx($image)); $this->assertGreaterThan(0, imagesy($image)); @@ -323,9 +323,9 @@ public function testShouldGetRemoteEndStatus() { $status = $this->driver->getStatus(); - $this->assertInternalType('boolean', $status->isReady()); + $this->assertTrue(is_bool($status->isReady())); $this->assertNotEmpty($status->getMessage()); - $this->assertInternalType('array', $status->getMeta()); + $this->assertTrue(is_array($status->getMeta())); } } diff --git a/tests/functional/RemoteWebElementTest.php b/tests/functional/RemoteWebElementTest.php index 021e6ed1a..21d890ccc 100644 --- a/tests/functional/RemoteWebElementTest.php +++ b/tests/functional/RemoteWebElementTest.php @@ -318,7 +318,7 @@ public function testShouldReturnEmptyArrayIfChildElementsCannotBeFound() $childElements = $element->findElements(WebDriverBy::cssSelector('not_existing')); - $this->assertInternalType('array', $childElements); + $this->assertTrue(is_array($childElements)); $this->assertCount(0, $childElements); } @@ -330,7 +330,7 @@ public function testShouldFindMultipleChildElements() $allElements = $this->driver->findElements(WebDriverBy::cssSelector('li')); $childElements = $element->findElements(WebDriverBy::cssSelector('li')); - $this->assertInternalType('array', $childElements); + $this->assertTrue(is_array($childElements)); $this->assertCount(5, $allElements); // there should be 5
  • elements on page $this->assertCount(3, $childElements); // but we should find only subelements of one