Travis Bionic + Chrome Headless + PHP 7.4 support

This commit is contained in:
Kamil Kokot 2020-05-26 17:49:09 +02:00
parent a01e2ba9ee
commit 58b043756b
No known key found for this signature in database
GPG key ID: 7BD76F7054D93C89
25 changed files with 156 additions and 122 deletions

View file

@ -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:

View file

@ -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

View file

@ -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",

View file

@ -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

View file

@ -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"

View file

@ -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

View file

@ -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}
}

View file

@ -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();
}
}

View file

@ -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'));
}
}

View file

@ -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

View file

@ -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 () {

View file

@ -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;
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;

View file

@ -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 {

View file

@ -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;

View file

@ -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;

View file

@ -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;

View file

@ -254,6 +254,7 @@
<argument type="service" id="sylius.behat.page.admin.taxon.update" />
<argument type="service" id="sylius.behat.current_page_resolver" />
<argument type="service" id="sylius.behat.notification_checker" />
<argument type="service" id="behat.mink.default_session" />
</service>
<service id="sylius.behat.context.ui.admin.managing_tax_rate" class="Sylius\Behat\Context\Ui\Admin\ManagingTaxRateContext">

View file

@ -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())
));
}
}

View file

@ -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

View file

@ -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;
}

View file

@ -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())
));
}
}