Skip to content

Commit

Permalink
Run dusk in docker on travis ci (#49)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
troccoli authored May 17, 2019
1 parent f650fd2 commit 993a5f7
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 55 deletions.
109 changes: 77 additions & 32 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion env.travis → .env.ci
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ QUEUE_DRIVER=sync

MAIL_DRIVER=log

FAKER_LOCALE=en_GB
FAKER_LOCALE=en_GB
49 changes: 28 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
19 changes: 19 additions & 0 deletions tests/Browser/PingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use LVA\User;
use Tests\Browser\Pages\HomePage;
use Tests\DuskTestCase;

class PingTest extends DuskTestCase
{
public function testPing()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('London Volleyball Association');
});
}
}
4 changes: 4 additions & 0 deletions tests/DuskTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 993a5f7

Please sign in to comment.