From 58b043756b0d994ba4d32d88b11e38aab030292f Mon Sep 17 00:00:00 2001 From: Kamil Kokot Date: Tue, 26 May 2020 17:49:09 +0200 Subject: [PATCH] Travis Bionic + Chrome Headless + PHP 7.4 support --- .travis.yml | 40 ++++++++++++---- behat.yml.dist | 12 ++++- composer.json | 2 + config/packages/test_cached/doctrine.yaml | 43 +++++++++++------ .../suites/application/before_install.sh | 10 ++-- .../suites/application/before_script.sh | 2 - .../script/test-behat-with-javascript | 32 ++++--------- .../Behat/Page/Admin/Crud/IndexPage.php | 3 +- .../Product/CreateConfigurableProductPage.php | 3 +- .../Admin/Product/CreateSimpleProductPage.php | 16 +++---- .../Product/UpdateConfigurableProductPage.php | 2 - .../Admin/Product/UpdateSimpleProductPage.php | 7 ++- .../Page/Admin/ShippingMethod/CreatePage.php | 3 +- .../Behat/Page/Admin/Taxon/CreatePage.php | 5 +- .../Behat/Page/Admin/Taxon/UpdatePage.php | 5 +- .../Behat/Page/Shop/Checkout/AddressPage.php | 3 +- .../Behat/Page/Shop/Checkout/CompletePage.php | 3 +- .../Page/Shop/Checkout/SelectPaymentPage.php | 3 +- .../Page/Shop/Checkout/SelectShippingPage.php | 3 +- .../Behat/Page/Shop/Product/ShowPage.php | 11 +++-- .../Resources/config/services/contexts/ui.xml | 1 + .../Behat/Service/AutocompleteHelper.php | 6 +-- src/Sylius/Behat/Service/JQueryHelper.php | 2 +- .../Behat/Service/Setter/CookieSetter.php | 15 +++++- .../Behat/Service/SlugGenerationHelper.php | 46 +++++++++---------- 25 files changed, 156 insertions(+), 122 deletions(-) diff --git a/.travis.yml b/.travis.yml index 228a536a40..0580f4cfe9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: php -dist: trusty +dist: bionic sudo: false @@ -10,11 +10,6 @@ env: - SYLIUS_CACHE_DIR=$HOME/.sylius-cache - SYLIUS_BUILD_DIR=etc/build -addons: - apt: - sources: - - mysql-5.7-trusty - matrix: include: - @@ -22,8 +17,14 @@ matrix: env: - SYLIUS_SUITE="application" - SYMFONY_VERSION="4.4.*" + addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable + chrome: stable services: - - memcached - mysql - php: 7.3 @@ -36,7 +37,30 @@ matrix: apt: packages: - parallel - + - + php: 7.4 + env: + - SYLIUS_SUITE="application" + - SYMFONY_VERSION="4.4.*" + addons: + apt: + sources: + - google-chrome + packages: + - google-chrome-stable + chrome: stable + services: + - mysql + - + php: 7.4 + env: + - SYLIUS_SUITE="packages" + - SYMFONY_VERSION="4.4.*" + addons: + apt: + packages: + - parallel + cache: yarn: true directories: diff --git a/behat.yml.dist b/behat.yml.dist index 0ddfe84452..fc46c60eaa 100644 --- a/behat.yml.dist +++ b/behat.yml.dist @@ -14,6 +14,8 @@ default: snippets: false extensions: + DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~ + Lakion\Behat\MinkDebugExtension: directory: etc/build clean_start: false @@ -21,12 +23,16 @@ default: Behat\MinkExtension: files_path: "%paths.base%/src/Sylius/Behat/Resources/fixtures/" - base_url: "https://localhost:8080/" + base_url: "https://127.0.0.1:8080/" default_session: symfony - javascript_session: chrome + javascript_session: chrome_headless sessions: symfony: symfony: ~ + chrome_headless: + chrome: + api_url: http://127.0.0.1:9222 + validate_certificate: false chrome: selenium2: browser: chrome @@ -41,6 +47,8 @@ default: - "start-maximized" - "no-sandbox" extra_capabilities: + acceptSslCerts: true + acceptInsecureCerts: true unexpectedAlertBehaviour: accept goog:chromeOptions: w3c: false # https://github.com/Sylius/Sylius/issues/10561 diff --git a/composer.json b/composer.json index 07468660ec..27cd247ac1 100644 --- a/composer.json +++ b/composer.json @@ -105,6 +105,8 @@ "require-dev": { "behat/behat": "^3.6.1", "behat/mink-selenium2-driver": "^1.3", + "dmore/behat-chrome-extension": "^1.3", + "dmore/chrome-mink-driver": "^2.7", "doctrine/data-fixtures": "^1.4", "friends-of-behat/mink": "^1.8", "friends-of-behat/mink-browserkit-driver": "^1.3", diff --git a/config/packages/test_cached/doctrine.yaml b/config/packages/test_cached/doctrine.yaml index 49528606d9..2f16f0fdea 100644 --- a/config/packages/test_cached/doctrine.yaml +++ b/config/packages/test_cached/doctrine.yaml @@ -1,16 +1,31 @@ doctrine: orm: - entity_managers: - default: - result_cache_driver: - type: memcached - host: localhost - port: 11211 - query_cache_driver: - type: memcached - host: localhost - port: 11211 - metadata_cache_driver: - type: memcached - host: localhost - port: 11211 + metadata_cache_driver: + type: service + id: doctrine.system_cache_provider + query_cache_driver: + type: service + id: doctrine.system_cache_provider + result_cache_driver: + type: service + id: doctrine.result_cache_provider + +services: + doctrine.result_cache_provider: + class: Symfony\Component\Cache\DoctrineProvider + public: false + arguments: + - '@doctrine.result_cache_pool' + doctrine.system_cache_provider: + class: Symfony\Component\Cache\DoctrineProvider + public: false + arguments: + - '@doctrine.system_cache_pool' + +framework: + cache: + pools: + doctrine.result_cache_pool: + adapter: cache.app + doctrine.system_cache_pool: + adapter: cache.system diff --git a/etc/travis/suites/application/before_install.sh b/etc/travis/suites/application/before_install.sh index ff5fa147d1..2cc4fdb079 100755 --- a/etc/travis/suites/application/before_install.sh +++ b/etc/travis/suites/application/before_install.sh @@ -3,17 +3,13 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/common.lib.sh" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/application.sh" -print_header "Activating memcached extension" "Sylius" -run_command "echo \"extension = memcached.so\" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini" || exit $? -run_command "echo \"memory_limit=4096M\" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini" || exit $? - -print_header "Updating Composer" "Sylius" -run_command "composer self-update --preview" - # Download and configure Symfony webserver print_header "Downloading Symfony CLI" "Sylius" if [ ! -f $SYLIUS_CACHE_DIR/symfony ]; then run_command "wget https://get.symfony.com/cli/installer -O - | bash" run_command "mv ~/.symfony/bin/symfony $SYLIUS_CACHE_DIR" fi +run_command "php -v | head -n 1 | awk '{ print \$2 }' > .php-version" run_command "$SYLIUS_CACHE_DIR/symfony version" +run_command "$SYLIUS_CACHE_DIR/symfony local:php:list" +run_command "$SYLIUS_CACHE_DIR/symfony php -v" diff --git a/etc/travis/suites/application/before_script.sh b/etc/travis/suites/application/before_script.sh index 8c0255ddfd..11d55b91d7 100755 --- a/etc/travis/suites/application/before_script.sh +++ b/etc/travis/suites/application/before_script.sh @@ -3,8 +3,6 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/common.lib.sh" source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../bash/application.sh" -run_command "sudo mysql_upgrade" - print_header "Setting the application up" "Sylius" run_command "APP_DEBUG=1 bin/console doctrine:database:create -vvv" || exit $? # Have to be run with debug = true, to omit generating proxies before setting up the database run_command "APP_DEBUG=1 APP_ENV=dev bin/console cache:warmup -vvv" || exit $? # For PHPStan diff --git a/etc/travis/suites/application/script/test-behat-with-javascript b/etc/travis/suites/application/script/test-behat-with-javascript index 810252d16a..3a13eafcba 100755 --- a/etc/travis/suites/application/script/test-behat-with-javascript +++ b/etc/travis/suites/application/script/test-behat-with-javascript @@ -3,33 +3,14 @@ source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../../../bash/common.lib.sh" prepare_for_behat_with_js() { - # Configure display - run_command "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen 0 2880x1800x16" - run_command "export DISPLAY=:99" + # Install certificates + run_command "$SYLIUS_CACHE_DIR/symfony server:ca:install" - # Download and configure ChromeDriver - if [ ! -f $SYLIUS_CACHE_DIR/chromedriver ] || [ "$($SYLIUS_CACHE_DIR/chromedriver --version | grep -c 2.34)" = "0" ]; then - run_command "curl http://chromedriver.storage.googleapis.com/2.34/chromedriver_linux64.zip > chromedriver.zip" - run_command "unzip chromedriver.zip" - run_command "chmod +x chromedriver" - run_command "mv chromedriver $SYLIUS_CACHE_DIR" - fi - - # Run ChromeDriver - run_command "$SYLIUS_CACHE_DIR/chromedriver > /dev/null 2>&1 &" - - # Download and configure Selenium - if [ ! -f $SYLIUS_CACHE_DIR/selenium.jar ] || [ "$(java -jar $SYLIUS_CACHE_DIR/selenium.jar --version | grep -c 3.4.0)" = "0" ]; then - run_command "curl http://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar > selenium.jar" - run_command "mv selenium.jar $SYLIUS_CACHE_DIR" - fi - - # Run Selenium - run_command "java -Dwebdriver.chrome.driver=$SYLIUS_CACHE_DIR/chromedriver -jar $SYLIUS_CACHE_DIR/selenium.jar > /dev/null 2>&1 &" + # Run headless Chrome + run_command "google-chrome-stable --enable-automation --disable-background-networking --no-default-browser-check --no-first-run --disable-popup-blocking --disable-default-apps --allow-insecure-localhost --disable-translate --disable-extensions --no-sandbox --enable-features=Metal --headless --remote-debugging-port=9222 --window-size=2880,1800 --proxy-server='direct://' --proxy-bypass-list='*' http://127.0.0.1 > /dev/null 2>&1 &" # Run webserver - run_command "$SYLIUS_CACHE_DIR/symfony server:ca:install" - run_command "$SYLIUS_CACHE_DIR/symfony server:start --port=8080 --dir=public --force-php-discovery --daemon" + run_command "$SYLIUS_CACHE_DIR/symfony server:start --port=8080 --dir=public --daemon" } run_behat() { @@ -40,6 +21,9 @@ run_behat() { if [[ ${code} = 1 ]]; then run_command "vendor/bin/behat --strict --no-interaction -vvv -f progress --tags=\"@javascript && ~@todo && ~@cli\" --rerun" ; code=$? fi + if [[ ${code} = 1 ]]; then + run_command "vendor/bin/behat --strict --no-interaction -vvv -f progress --tags=\"@javascript && ~@todo && ~@cli\" --rerun" ; code=$? + fi return ${code} } diff --git a/src/Sylius/Behat/Page/Admin/Crud/IndexPage.php b/src/Sylius/Behat/Page/Admin/Crud/IndexPage.php index 7de2fc4d41..82dda3e45f 100644 --- a/src/Sylius/Behat/Page/Admin/Crud/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Crud/IndexPage.php @@ -17,6 +17,7 @@ use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Session; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use Sylius\Behat\Service\Accessor\TableAccessorInterface; use Symfony\Component\Routing\RouterInterface; @@ -137,7 +138,7 @@ class IndexPage extends SymfonyPage implements IndexPageInterface public function bulkDelete(): void { $this->getElement('bulk_actions')->pressButton('Delete'); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { $this->getElement('confirmation_button')->click(); } } diff --git a/src/Sylius/Behat/Page/Admin/Product/CreateConfigurableProductPage.php b/src/Sylius/Behat/Page/Admin/Product/CreateConfigurableProductPage.php index 2ba2aacf7c..924cb1d8ee 100644 --- a/src/Sylius/Behat/Page/Admin/Product/CreateConfigurableProductPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/CreateConfigurableProductPage.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Page\Admin\Product; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\SpecifiesItsCode; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\AutocompleteHelper; @@ -34,7 +35,7 @@ class CreateConfigurableProductPage extends BaseCreatePage implements CreateConf sprintf('sylius_product_translations_%s_name', $localeCode), $name ); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { SlugGenerationHelper::waitForSlugGeneration($this->getSession(), $this->getElement('slug')); } } diff --git a/src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php b/src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php index 65d47e57e4..0abedcd2a4 100644 --- a/src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php @@ -15,12 +15,14 @@ namespace Sylius\Behat\Page\Admin\Product; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\SpecifiesItsCode; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\AutocompleteHelper; use Sylius\Behat\Service\SlugGenerationHelper; use Sylius\Component\Core\Model\TaxonInterface; use Sylius\Component\Product\Model\ProductAssociationTypeInterface; +use WebDriver\Exception; use Webmozart\Assert\Assert; class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProductPageInterface @@ -38,7 +40,7 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd $this->activateLanguageTab($localeCode); $this->getElement('name', ['%locale%' => $localeCode])->setValue($name); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { SlugGenerationHelper::waitForSlugGeneration( $this->getSession(), $this->getElement('slug', ['%locale%' => $localeCode]) @@ -136,8 +138,6 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd { $this->clickTab('associations'); - Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); - $dropdown = $this->getElement('association_dropdown', [ '%association%' => $productAssociationType->getName(), ]); @@ -182,7 +182,7 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd public function activateLanguageTab(string $locale): void { - if (!$this->getDriver() instanceof Selenium2Driver) { + if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) { return; } @@ -255,12 +255,8 @@ class CreateSimpleProductPage extends BaseCreatePage implements CreateSimpleProd private function selectElementFromAttributesDropdown(string $id): void { - /** @var Selenium2Driver $driver */ - $driver = $this->getDriver(); - Assert::isInstanceOf($driver, Selenium2Driver::class); - - $driver->executeScript('$(\'#sylius_product_attribute_choice\').dropdown(\'show\');'); - $driver->executeScript(sprintf('$(\'#sylius_product_attribute_choice\').dropdown(\'set selected\', \'%s\');', $id)); + $this->getDriver()->executeScript('$(\'#sylius_product_attribute_choice\').dropdown(\'show\');'); + $this->getDriver()->executeScript(sprintf('$(\'#sylius_product_attribute_choice\').dropdown(\'set selected\', \'%s\');', $id)); } private function waitForFormElement(int $timeout = 5): void diff --git a/src/Sylius/Behat/Page/Admin/Product/UpdateConfigurableProductPage.php b/src/Sylius/Behat/Page/Admin/Product/UpdateConfigurableProductPage.php index 1b22126a9e..8bd4a6d669 100644 --- a/src/Sylius/Behat/Page/Admin/Product/UpdateConfigurableProductPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/UpdateConfigurableProductPage.php @@ -56,8 +56,6 @@ class UpdateConfigurableProductPage extends BaseUpdatePage implements UpdateConf { $this->openTaxonBookmarks(); - Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); - $this->getDriver()->executeScript(sprintf('$(\'input.search\').val(\'%s\')', $taxon->getName())); $this->getElement('search')->click(); $this->getElement('search')->waitFor(10, function () { diff --git a/src/Sylius/Behat/Page/Admin/Product/UpdateSimpleProductPage.php b/src/Sylius/Behat/Page/Admin/Product/UpdateSimpleProductPage.php index 6cf9035e0b..24829bca92 100644 --- a/src/Sylius/Behat/Page/Admin/Product/UpdateSimpleProductPage.php +++ b/src/Sylius/Behat/Page/Admin/Product/UpdateSimpleProductPage.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Page\Admin\Product; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\ChecksCodeImmutability; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Sylius\Behat\Service\AutocompleteHelper; @@ -37,7 +38,7 @@ class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProd $this->activateLanguageTab($localeCode); $this->getElement('name', ['%locale%' => $localeCode])->setValue($name); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { SlugGenerationHelper::waitForSlugGeneration( $this->getSession(), $this->getElement('slug', ['%locale%' => $localeCode]) @@ -237,8 +238,6 @@ class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProd { $this->clickTab('associations'); - Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class); - $dropdown = $this->getElement('association_dropdown', [ '%association%' => $productAssociationType->getName(), ]); @@ -309,7 +308,7 @@ class UpdateSimpleProductPage extends BaseUpdatePage implements UpdateSimpleProd public function activateLanguageTab(string $locale): void { - if (!$this->getDriver() instanceof Selenium2Driver) { + if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) { return; } diff --git a/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php b/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php index 5ef5bce6f3..9b9272cd35 100644 --- a/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Page\Admin\ShippingMethod; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\SpecifiesItsCode; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Component\Core\Formatter\StringInflector; @@ -57,7 +58,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface public function checkChannel($channelName): void { - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { $this->getElement('channel', ['%channel%' => $channelName])->click(); return; diff --git a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php index 88321b745f..d769f84763 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php @@ -16,6 +16,7 @@ namespace Sylius\Behat\Page\Admin\Taxon; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\SpecifiesItsCode; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\JQueryHelper; @@ -78,7 +79,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface $this->activateLanguageTab($languageCode); $this->getElement('name', ['%language%' => $languageCode])->setValue($name); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { SlugGenerationHelper::waitForSlugGeneration( $this->getSession(), $this->getElement('slug', ['%language%' => $languageCode]) @@ -109,7 +110,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface public function activateLanguageTab(string $locale): void { - if (!$this->getDriver() instanceof Selenium2Driver) { + if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) { return; } diff --git a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php index 9958572b51..58c77f3ae8 100644 --- a/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php +++ b/src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php @@ -16,6 +16,7 @@ namespace Sylius\Behat\Page\Admin\Taxon; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Behaviour\ChecksCodeImmutability; use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; use Sylius\Behat\Service\AutocompleteHelper; @@ -45,7 +46,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface $this->activateLanguageTab($languageCode); $this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { SlugGenerationHelper::waitForSlugGeneration( $this->getSession(), $this->getElement('slug', ['%language%' => $languageCode]) @@ -190,7 +191,7 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface public function activateLanguageTab(string $locale): void { - if (!$this->getDriver() instanceof Selenium2Driver) { + if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) { return; } diff --git a/src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php b/src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php index b16fdefd01..ba88316674 100644 --- a/src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php +++ b/src/Sylius/Behat/Page/Shop/Checkout/AddressPage.php @@ -17,6 +17,7 @@ use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\ElementNotFoundException; use Behat\Mink\Session; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use Sylius\Behat\Service\JQueryHelper; use Sylius\Component\Core\Factory\AddressFactoryInterface; @@ -52,7 +53,7 @@ class AddressPage extends SymfonyPage implements AddressPageInterface public function chooseDifferentShippingAddress(): void { $driver = $this->getDriver(); - if ($driver instanceof Selenium2Driver) { + if ($driver instanceof Selenium2Driver || $driver instanceof ChromeDriver) { $this->getElement('different_shipping_address_label')->click(); return; diff --git a/src/Sylius/Behat/Page/Shop/Checkout/CompletePage.php b/src/Sylius/Behat/Page/Shop/Checkout/CompletePage.php index 99458c0b56..6a2e7c6f7b 100644 --- a/src/Sylius/Behat/Page/Shop/Checkout/CompletePage.php +++ b/src/Sylius/Behat/Page/Shop/Checkout/CompletePage.php @@ -16,6 +16,7 @@ namespace Sylius\Behat\Page\Shop\Checkout; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Session; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use Sylius\Behat\Service\Accessor\TableAccessorInterface; use Sylius\Component\Core\Model\AddressInterface; @@ -233,7 +234,7 @@ class CompletePage extends SymfonyPage implements CompletePageInterface public function tryToOpen(array $urlParameters = []): void { - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { $start = microtime(true); $end = $start + 15; do { diff --git a/src/Sylius/Behat/Page/Shop/Checkout/SelectPaymentPage.php b/src/Sylius/Behat/Page/Shop/Checkout/SelectPaymentPage.php index e69cd8507c..f441dcb8ea 100644 --- a/src/Sylius/Behat/Page/Shop/Checkout/SelectPaymentPage.php +++ b/src/Sylius/Behat/Page/Shop/Checkout/SelectPaymentPage.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Page\Shop\Checkout; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; class SelectPaymentPage extends SymfonyPage implements SelectPaymentPageInterface @@ -26,7 +27,7 @@ class SelectPaymentPage extends SymfonyPage implements SelectPaymentPageInterfac public function selectPaymentMethod(string $paymentMethod): void { - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { $this->getElement('payment_method_select', ['%payment_method%' => $paymentMethod])->click(); return; diff --git a/src/Sylius/Behat/Page/Shop/Checkout/SelectShippingPage.php b/src/Sylius/Behat/Page/Shop/Checkout/SelectShippingPage.php index 38ddf05cfe..dae27fcec8 100644 --- a/src/Sylius/Behat/Page/Shop/Checkout/SelectShippingPage.php +++ b/src/Sylius/Behat/Page/Shop/Checkout/SelectShippingPage.php @@ -16,6 +16,7 @@ namespace Sylius\Behat\Page\Shop\Checkout; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; class SelectShippingPage extends SymfonyPage implements SelectShippingPageInterface @@ -27,7 +28,7 @@ class SelectShippingPage extends SymfonyPage implements SelectShippingPageInterf public function selectShippingMethod(string $shippingMethod): void { - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { $this->getElement('shipping_method_select', ['%shipping_method%' => $shippingMethod])->click(); return; diff --git a/src/Sylius/Behat/Page/Shop/Product/ShowPage.php b/src/Sylius/Behat/Page/Shop/Product/ShowPage.php index 77f87b3c2e..ccb000c05d 100644 --- a/src/Sylius/Behat/Page/Shop/Product/ShowPage.php +++ b/src/Sylius/Behat/Page/Shop/Product/ShowPage.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Page\Shop\Product; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Exception\ElementNotFoundException; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage; use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException; use Sylius\Behat\Service\JQueryHelper; @@ -33,7 +34,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface { $this->getElement('add_to_cart_button')->click(); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession()); } } @@ -43,7 +44,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface $this->getElement('quantity')->setValue($quantity); $this->getElement('add_to_cart_button')->click(); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession()); } } @@ -54,7 +55,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface $this->getElement('add_to_cart_button')->click(); - if ($this->getDriver() instanceof Selenium2Driver) { + if ($this->getDriver() instanceof Selenium2Driver || $this->getDriver() instanceof ChromeDriver) { JQueryHelper::waitForAsynchronousActionsToFinish($this->getSession()); } } @@ -72,7 +73,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface $attributesTable = $this->getElement('attributes'); $driver = $this->getDriver(); - if ($driver instanceof Selenium2Driver) { + if ($driver instanceof Selenium2Driver || $driver instanceof ChromeDriver) { try { $attributesTab = $this->getElement('tab', ['%name%' => 'attributes']); if (!$attributesTab->hasAttribute('[data-test-active]')) { @@ -214,7 +215,7 @@ class ShowPage extends SymfonyPage implements ShowPageInterface $variantRadio = $this->getElement('variant_radio', ['%variantName%' => $variantName]); $driver = $this->getDriver(); - if ($driver instanceof Selenium2Driver) { + if ($driver instanceof Selenium2Driver || $driver instanceof ChromeDriver) { $variantRadio->click(); return; diff --git a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml index e3de4ddcd3..16e86383ac 100644 --- a/src/Sylius/Behat/Resources/config/services/contexts/ui.xml +++ b/src/Sylius/Behat/Resources/config/services/contexts/ui.xml @@ -254,6 +254,7 @@ + diff --git a/src/Sylius/Behat/Service/AutocompleteHelper.php b/src/Sylius/Behat/Service/AutocompleteHelper.php index dda7892327..163b839a84 100644 --- a/src/Sylius/Behat/Service/AutocompleteHelper.php +++ b/src/Sylius/Behat/Service/AutocompleteHelper.php @@ -25,8 +25,6 @@ abstract class AutocompleteHelper */ public static function chooseValue(Session $session, NodeElement $element, $value) { - Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); - static::activateAutocompleteDropdown($session, $element); $element->find('css', sprintf('div.item:contains("%s")', $value))->click(); @@ -39,8 +37,6 @@ abstract class AutocompleteHelper */ public static function chooseValues(Session $session, NodeElement $element, array $values) { - Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); - static::activateAutocompleteDropdown($session, $element); foreach ($values as $value) { @@ -66,7 +62,7 @@ abstract class AutocompleteHelper { $session->wait(5000, sprintf( '$(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).dropdown("is visible")', - $element->getXpath() + str_replace('"', '\"', $element->getXpath()) )); } } diff --git a/src/Sylius/Behat/Service/JQueryHelper.php b/src/Sylius/Behat/Service/JQueryHelper.php index 5c24152378..4efb6f91d1 100644 --- a/src/Sylius/Behat/Service/JQueryHelper.php +++ b/src/Sylius/Behat/Service/JQueryHelper.php @@ -20,7 +20,7 @@ abstract class JQueryHelper { public static function waitForAsynchronousActionsToFinish(Session $session): void { - $session->wait(1000, '0 === jQuery.active'); + $session->wait(1000, 'typeof jQuery !== "undefined" && 0 === jQuery.active'); } public static function waitForFormToStopLoading(DocumentElement $document, int $timeout = 10): void diff --git a/src/Sylius/Behat/Service/Setter/CookieSetter.php b/src/Sylius/Behat/Service/Setter/CookieSetter.php index 7eef8215ac..1b200a2c0a 100644 --- a/src/Sylius/Behat/Service/Setter/CookieSetter.php +++ b/src/Sylius/Behat/Service/Setter/CookieSetter.php @@ -15,6 +15,7 @@ namespace Sylius\Behat\Service\Setter; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Session; +use DMore\ChromeDriver\ChromeDriver; use FriendsOfBehat\SymfonyExtension\Driver\SymfonyDriver; use Symfony\Component\BrowserKit\Cookie; @@ -45,10 +46,16 @@ final class CookieSetter implements CookieSetterInterface */ public function setCookie($name, $value) { - $this->prepareMinkSessionIfNeeded($this->minkSession); - $driver = $this->minkSession->getDriver(); + if ($driver instanceof ChromeDriver) { + if (!$driver->isStarted()) { + $driver->start(); + } + } + + $this->prepareMinkSessionIfNeeded($this->minkSession); + if ($driver instanceof SymfonyDriver) { $driver->getClient()->getCookieJar()->set( new Cookie($name, $value, null, null, parse_url($this->minkParameters['base_url'], \PHP_URL_HOST)) @@ -79,6 +86,10 @@ final class CookieSetter implements CookieSetterInterface return true; } + if ($driver instanceof ChromeDriver && $driver->isStarted() === false) { + return true; + } + if (false !== strpos($session->getCurrentUrl(), $this->minkParameters['base_url'])) { return false; } diff --git a/src/Sylius/Behat/Service/SlugGenerationHelper.php b/src/Sylius/Behat/Service/SlugGenerationHelper.php index ade6ac207f..0ace5d148f 100644 --- a/src/Sylius/Behat/Service/SlugGenerationHelper.php +++ b/src/Sylius/Behat/Service/SlugGenerationHelper.php @@ -16,37 +16,36 @@ namespace Sylius\Behat\Service; use Behat\Mink\Driver\Selenium2Driver; use Behat\Mink\Element\NodeElement; use Behat\Mink\Session; +use DMore\ChromeDriver\ChromeDriver; use Webmozart\Assert\Assert; abstract class SlugGenerationHelper { - public static function waitForSlugGeneration(Session $session, NodeElement $element) + public static function waitForSlugGeneration(Session $session, NodeElement $element): void { - Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); - JQueryHelper::waitForAsynchronousActionsToFinish($session); + static::isElementReadonly($session, $element); + JQueryHelper::waitForAsynchronousActionsToFinish($session); } - public static function enableSlugModification(Session $session, NodeElement $element) + public static function enableSlugModification(Session $session, NodeElement $element): void { - Assert::isInstanceOf($session->getDriver(), Selenium2Driver::class); - JQueryHelper::waitForAsynchronousActionsToFinish($session); - static::waitForElementToBeClickable($session, $element); + + static::isElementReadonly($session, $element); $element->click(); + static::isElementNotReadonly($session, $element); + JQueryHelper::waitForAsynchronousActionsToFinish($session); } - /** - * @return bool - */ - public static function isSlugReadonly(Session $session, NodeElement $element) + public static function isSlugReadonly(Session $session, NodeElement $element): bool { - if (!$session->getDriver() instanceof Selenium2Driver) { + if (!$session->getDriver() instanceof Selenium2Driver && !$session->getDriver() instanceof ChromeDriver) { return $element->hasAttribute('readonly'); } @@ -55,22 +54,19 @@ abstract class SlugGenerationHelper return static::isElementReadonly($session, $element); } - private static function waitForElementToBeClickable(Session $session, NodeElement $element) - { - $session->wait(1000, sprintf( - 'false === $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).hasClass("loading")', - $element->getParent()->getParent()->getXpath() - )); - } - - /** - * @return bool - */ - private static function isElementReadonly(Session $session, NodeElement $element) + private static function isElementReadonly(Session $session, NodeElement $element): bool { return $session->wait(1000, sprintf( 'undefined != $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")', - $element->getXpath() + str_replace('"', '\"', $element->getXpath()) + )); + } + + private static function isElementNotReadonly(Session $session, NodeElement $element): bool + { + return $session->wait(1000, sprintf( + 'undefined == $(document.evaluate("%s", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).attr("readonly")', + str_replace('"', '\"', $element->getXpath()) )); } }