Skip to content

Commit

Permalink
Travis Bionic + Chrome Headless + PHP 7.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
pamil committed May 26, 2020
1 parent a01e2ba commit 58b0437
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 119 deletions.
40 changes: 32 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: php

dist: trusty
dist: bionic

sudo: false

Expand All @@ -10,20 +10,21 @@ env:
- SYLIUS_CACHE_DIR=$HOME/.sylius-cache
- SYLIUS_BUILD_DIR=etc/build

addons:
apt:
sources:
- mysql-5.7-trusty

matrix:
include:
-
php: 7.3
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
Expand All @@ -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:
Expand Down
12 changes: 10 additions & 2 deletions behat.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ default:
snippets: false

extensions:
DMore\ChromeExtension\Behat\ServiceContainer\ChromeExtension: ~

Lakion\Behat\MinkDebugExtension:
directory: etc/build
clean_start: false
screenshot: true

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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
43 changes: 29 additions & 14 deletions config/packages/test_cached/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions etc/travis/suites/application/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 0 additions & 2 deletions etc/travis/suites/application/before_script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 8 additions & 24 deletions etc/travis/suites/application/script/test-behat-with-javascript
Original file line number Diff line number Diff line change
Expand Up @@ -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"

# 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
# Install certificates
run_command "$SYLIUS_CACHE_DIR/symfony server:ca:install"

# 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() {
Expand All @@ -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}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Sylius/Behat/Page/Admin/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -137,7 +138,7 @@ public function filter(): void
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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;
Expand All @@ -34,7 +35,7 @@ public function nameItIn(string $name, string $localeCode): void
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'));
}
}
Expand Down
16 changes: 6 additions & 10 deletions src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@

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
Expand All @@ -38,7 +40,7 @@ public function nameItIn(string $name, string $localeCode): void
$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])
Expand Down Expand Up @@ -136,8 +138,6 @@ public function associateProducts(ProductAssociationTypeInterface $productAssoci
{
$this->clickTab('associations');

Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class);

$dropdown = $this->getElement('association_dropdown', [
'%association%' => $productAssociationType->getName(),
]);
Expand Down Expand Up @@ -182,7 +182,7 @@ public function checkChannel(string $channelName): void

public function activateLanguageTab(string $locale): void
{
if (!$this->getDriver() instanceof Selenium2Driver) {
if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) {
return;
}

Expand Down Expand Up @@ -255,12 +255,8 @@ private function openTaxonBookmarks(): void

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ public function selectMainTaxon(TaxonInterface $taxon): void
{
$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 () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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;
Expand All @@ -37,7 +38,7 @@ public function nameItIn(string $name, string $localeCode): void
$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])
Expand Down Expand Up @@ -237,8 +238,6 @@ public function associateProducts(ProductAssociationTypeInterface $productAssoci
{
$this->clickTab('associations');

Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class);

$dropdown = $this->getElement('association_dropdown', [
'%association%' => $productAssociationType->getName(),
]);
Expand Down Expand Up @@ -309,7 +308,7 @@ public function specifySlugIn(string $slug, string $locale): void

public function activateLanguageTab(string $locale): void
{
if (!$this->getDriver() instanceof Selenium2Driver) {
if (!$this->getDriver() instanceof Selenium2Driver && !$this->getDriver() instanceof ChromeDriver) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Sylius/Behat/Page/Admin/ShippingMethod/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

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;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function chooseCalculator(string $name): void

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;
Expand Down
Loading

0 comments on commit 58b0437

Please sign in to comment.