From 993a5f79c4ecd6c5e29ecf81904f7257101dd742 Mon Sep 17 00:00:00 2001 From: Giulio Troccoli-Allard Date: Fri, 17 May 2019 10:01:09 +0100 Subject: [PATCH] Run dusk in docker on travis ci (#49) Trying to make Dusk work on Travis and Circle CI This is still not working and I have decided to leave it for now, as the Dusk tests all pass in my local (with Selenium), to concentrate on upgrading Laravel. But since I have done some useful changes, I would like to keep them and therefore merging them into master. --- .circleci/config.yml | 109 +++++++++++++----- env.travis => .env.ci | 2 +- .travis.yml | 49 ++++---- .../AvailableAppointmentResourceTest.php | 5 +- tests/Browser/PingTest.php | 19 +++ tests/DuskTestCase.php | 4 + 6 files changed, 133 insertions(+), 55 deletions(-) rename env.travis => .env.ci (90%) create mode 100644 tests/Browser/PingTest.php diff --git a/.circleci/config.yml b/.circleci/config.yml index 6282cfb3..3c6df33b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,73 +6,118 @@ version: 2 jobs: build: docker: - # specify the version you desire here - - image: circleci/php:7.1-node-browsers + # Specify the version you desire here + - image: circleci/php:7.3-stretch-node-browsers # Specify service dependencies here if necessary # CircleCI maintains a library of pre-built images # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/mysql:9.4 - - working_directory: ~/laravel + # Using the RAM variation mitigates I/O contention + # for database intensive operations. + # - image: circleci/mysql:5.7-ram + # + # - image: redis:3 steps: - checkout - - run: sudo apt install -y libsqlite3-dev zlib1g-dev - - run: sudo docker-php-ext-install zip - - run: sudo composer self-update + - run: + name: Install System Dependencies + command: | + sudo apt-get update + sudo apt-get install -y zlib1g-dev libsqlite3-dev + - run: + name: Install PHP Extensions + command: sudo docker-php-ext-install zip + + - run: + name: Version checks + command: | + php --version + php --ini + php -m - # Download and cache composer dependencies - restore_cache: keys: - - v1-dependencies-{{ checksum "composer.json" }} - # fallback to using the latest cache if no exact match is found - - v1-dependencies- - - run: composer install -n --prefer-dist + - composer-v1-{{ checksum "composer.lock" }} + - composer-v1- + + - run: + name: Install Composer Dependencies + command: composer install --no-progress --no-suggest --no-interaction --optimize-autoloader + - save_cache: + key: composer-v1-{{ checksum "composer.lock" }} paths: - vendor - key: v1-dependencies-{{ checksum "composer.json" }} - # Download and cache npm dependencies - - restore_cache: # special step to restore the dependency cache if `package.json` does not change + - restore_cache: keys: - node-v1-{{ checksum "package.json" }} - # fallback to using the latest cache if no exact match is found (See https://circleci.com/docs/2.0/caching/) - node-v1- - - run: npm install - - save_cache: # special step to save the dependency cache with the `package.json` cache key template + + - run: + name: Install Node Dependencies + command: npm install + + - save_cache: key: node-v1-{{ checksum "package.json" }} paths: - node_modules - - run: cp env.travis .env - - run: cp .env .env.dusk.local + - run: + name: Setup Environment + command: | + cp .env.ci .env + php artisan key:generate + touch ./storage/logs/laravel.log + touch ./database/database.sqlite + + - run: + name: Run Webpack + command: npm run production - - run: php artisan key:generate - - run: touch database/database.sqlite - - run: php artisan migrate --env=testing --database=testing --force - - run: npm run production + - run: + name: Migrate Database + command: php artisan migrate - # run tests! - - run: ./vendor/bin/phpunit + - run: + name: Run Unit Tests + command: | + mkdir -p ./logs/phpunit + vendor/bin/phpunit - run: name: Start Chrome Driver - command: ./vendor/laravel/dusk/bin/chromedriver-linux +# command: | +# php artisan dusk:update +# vendor/laravel/dusk/bin/chromedriver-linux + command: vendor/laravel/dusk/bin/chromedriver-linux background: true - - run: sleep 1 + - run: name: Run Laravel Server - command: php artisan serve --quiet + command: php artisan serve background: true - - run: sleep 1 - run: name: Run Laravel Dusk Tests - command: php artisan dusk --filter AvailableAppointmentResourceTest + command: php artisan dusk --filter testListAvailableAppointments + environment: + USE_CHROME_DRIVER: true + + - store_artifacts: + path: ./logs/phpunit + destination: phpunit + + - store_artifacts: + path: ./tests/Browser/console + destination: console - store_artifacts: path: ./tests/Browser/screenshots + destination: screenshots + - store_artifacts: + path: ./storage/logs + destination: laravel diff --git a/env.travis b/.env.ci similarity index 90% rename from env.travis rename to .env.ci index 9d6ce2ec..22659d11 100644 --- a/env.travis +++ b/.env.ci @@ -11,4 +11,4 @@ QUEUE_DRIVER=sync MAIL_DRIVER=log -FAKER_LOCALE=en_GB \ No newline at end of file +FAKER_LOCALE=en_GB diff --git a/.travis.yml b/.travis.yml index 91ffc097..b30aa9f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,46 @@ sudo: required dist: trusty -branches: - only: - - master - - dev -notifications: - email: - on_success: always - on_failure: always - slack: - rooms: - - secure: c5WWnc0fqkQjUWd44/V0w2tBVP795zTYl6EuJlYcmzy4YhDOCXmxQmk51UjN4Eh/9GfFRdrMVH35pjY74AF4wG6agfw0Xy1lzT6WxsyU+STdKaC4p1p3qKnHH80jrokETcJ7QfVBU3sRW6f0auIWSakHd47v7+QcBpJKDDr1sCPgXQfXmbHHKfcPQqXnoUk5pD+EEcOQDGTM1OkskPJg8QYLwMEmSsCBNOE21AvV1mxw67HQTT4TteM8W4Wyffun1vk1rEq01NRr7cVC9ik79JX8YnxwWF29kRtfItoSFbc83MAoqO+fiOxKkvZRKXz0U+Offx/Ni7CP25oWcDVQ37tFafDXeAsi61TaNHt5rK5NXZkr6TidE4bBvEcsMQEz4FHYQrGliJWCe2fsuAgOhhzIhcSgQETbhc8g67TshqGS0agOhT9tTx8Yxmf3Y+g3hB6mkPKi8MpsoL7Dn++RXahimqUWuc37pylFrLU4Bi9lepNubWoh9mz0F1P98kfJp3Zk2DeK3vvWNp5UyA9M5uzpfQtS4VtY24w1rf4yaUTXBP0gbdIb1BJzKV6IutIZl2f2R7nM6WXHPfcVNlDcszSmAaeasfYUZ/XAoCprctSbGDqhMVyrfInvCLxtxEKBzl3teRJ3tC8mx51AE1BZf601EEX/yblgzq+xVUxzSoo= - on_success: always - on_failure: always + +services: + - docker + language: php + php: - - 7.1 + - 7.3 + +#branches: +# only: +# - master +# - dev + install: - travis_retry composer install --no-progress --no-suggest --no-interaction --optimize-autoloader - npm install - npm rebuild node-sass - npm run production + - docker-compose build + before_script: - phpenv config-rm xdebug.ini - - cp env.travis .env + - cp .env.ci .env - cp .env .env.dusk.local - php artisan key:generate - touch database/database.sqlite - php artisan migrate - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - - ./vendor/laravel/dusk/bin/chromedriver-linux & - - php artisan serve > /dev/null 2>&1 & - script: - vendor/bin/phpunit - - php artisan dusk -vvv \ No newline at end of file + - docker-compose up -d + - sleep 3 + - docker exec -it app-web php artisan dusk --filter PingTest + +notifications: + email: + on_success: always + on_failure: always + slack: + rooms: + - secure: c5WWnc0fqkQjUWd44/V0w2tBVP795zTYl6EuJlYcmzy4YhDOCXmxQmk51UjN4Eh/9GfFRdrMVH35pjY74AF4wG6agfw0Xy1lzT6WxsyU+STdKaC4p1p3qKnHH80jrokETcJ7QfVBU3sRW6f0auIWSakHd47v7+QcBpJKDDr1sCPgXQfXmbHHKfcPQqXnoUk5pD+EEcOQDGTM1OkskPJg8QYLwMEmSsCBNOE21AvV1mxw67HQTT4TteM8W4Wyffun1vk1rEq01NRr7cVC9ik79JX8YnxwWF29kRtfItoSFbc83MAoqO+fiOxKkvZRKXz0U+Offx/Ni7CP25oWcDVQ37tFafDXeAsi61TaNHt5rK5NXZkr6TidE4bBvEcsMQEz4FHYQrGliJWCe2fsuAgOhhzIhcSgQETbhc8g67TshqGS0agOhT9tTx8Yxmf3Y+g3hB6mkPKi8MpsoL7Dn++RXahimqUWuc37pylFrLU4Bi9lepNubWoh9mz0F1P98kfJp3Zk2DeK3vvWNp5UyA9M5uzpfQtS4VtY24w1rf4yaUTXBP0gbdIb1BJzKV6IutIZl2f2R7nM6WXHPfcVNlDcszSmAaeasfYUZ/XAoCprctSbGDqhMVyrfInvCLxtxEKBzl3teRJ3tC8mx51AE1BZf601EEX/yblgzq+xVUxzSoo= + on_success: always + on_failure: always diff --git a/tests/Browser/Admin/DataManagement/AvailableAppointmentResourceTest.php b/tests/Browser/Admin/DataManagement/AvailableAppointmentResourceTest.php index 08d55b02..440ea881 100644 --- a/tests/Browser/Admin/DataManagement/AvailableAppointmentResourceTest.php +++ b/tests/Browser/Admin/DataManagement/AvailableAppointmentResourceTest.php @@ -2,7 +2,10 @@ namespace Tests\Browser\Admin\DataManagement; +use Facebook\WebDriver\Remote\RemoteWebElement; +use Facebook\WebDriver\WebDriverBy; use Illuminate\Database\Eloquent\Collection; +use Illuminate\Support\Facades\Log; use Laravel\Dusk\Browser; use LVA\Models\AvailableAppointment; use LVA\Models\Fixture; @@ -63,7 +66,7 @@ public function testListAvailableAppointments() } }) // Check page 2 - ->with($page->pageNavigation, function ($nav) { + ->with($page->pageNavigation, function (Browser $nav) { $nav->clickLink(2); }) ->assertPathIs($page->indexUrl()) diff --git a/tests/Browser/PingTest.php b/tests/Browser/PingTest.php new file mode 100644 index 00000000..03423b5b --- /dev/null +++ b/tests/Browser/PingTest.php @@ -0,0 +1,19 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('London Volleyball Association'); + }); + } +} diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php index 7ce05d7f..e7feb323 100644 --- a/tests/DuskTestCase.php +++ b/tests/DuskTestCase.php @@ -60,6 +60,10 @@ protected function driver() ]); $capabilities->setCapability(ChromeOptions::CAPABILITY, $chromeOptions); + if (env('USE_CHROME_DRIVER', false)) { + return RemoteWebDriver::create('localhost:9515', $capabilities); + } + return RemoteWebDriver::create('http://selenium:4444/wd/hub', $capabilities); }