Skip to content

Commit 881cbfb

Browse files
committed
Install Dependencies to Run Dusk Tests
**Why we need this change?** Currently we are unable to run Dusk (Browser) tests in workspace container. This change, is to allow us to install all dependencies needed to run Dust test which consists of 1. Linux packages such as xvfb (x-virtual frame buffer to run browser in headless container) and etc. 2. Chrome browser. 3. Chrome driver. To install the Dusk dependencies. 1. Update `WORKSPACE_INSTALL_DUSK_DEPS` to true. 2. Run `docker-compose build workspace`. I've also added couple of aliases to facilitate the preparation of test environment. 1. xvfb = `Xvfb -ac :0 -screen 0 1024x768x16 &` (run x-virtual frame buffer in the background) 2. serve = `php artisan serve --quiet &` (run laravel app in the background) Once those are installed, we will need to update the default chrome driver argument in Laravel 5.5 from `--headless` to `sandbox`. Below are the steps to run Dusk in workspace. 1. `docker-compose run workspace bash` (get into workspace). 2. `laravel new dusk-test` (generate new lavarel app for testing purpose). 3. `cd dusk-test` (change directory to newly generate app folder). 4. `composer install --dev laravel/dusk` (install dusk via composer). 5. `php artisan dusk:install` (generate dusk files). 6. `sed -i '/APP_URL/d' .env` (remove APP_URL entry in .env) 7. `echo 'APP_URL=localhost:8000' >> .env` (add new APP_URL entry in .env) 8. `sed -i--'s/headless/no-sandbox/g' tests/DuskTestCase.php` (replace the default chrome driver argument). 9. `xvfb` (alias to run Xvfb instance in the background). 10. `serve` (alias to run laravel app in the background). 11. `dusk` (alias to run Dusk test).
1 parent 6cff904 commit 881cbfb

6 files changed

Lines changed: 93 additions & 0 deletions

File tree

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ services:
4040
- INSTALL_IMAGE_OPTIMIZERS=${WORKSPACE_INSTALL_IMAGE_OPTIMIZERS}
4141
- INSTALL_IMAGEMAGICK=${WORKSPACE_INSTALL_IMAGEMAGICK}
4242
- INSTALL_TERRAFORM=${WORKSPACE_INSTALL_TERRAFORM}
43+
- INSTALL_DUSK_DEPS=${WORKSPACE_INSTALL_DUSK_DEPS}
4344
- PUID=${WORKSPACE_PUID}
4445
- PGID=${WORKSPACE_PGID}
4546
- NODE_VERSION=${WORKSPACE_NODE_VERSION}

env-example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ WORKSPACE_INSTALL_PYTHON=false
5353
WORKSPACE_INSTALL_IMAGE_OPTIMIZERS=false
5454
WORKSPACE_INSTALL_IMAGEMAGICK=false
5555
WORKSPACE_INSTALL_TERRAFORM=false
56+
WORKSPACE_INSTALL_DUSK_DEPS=false
5657
WORKSPACE_PUID=1000
5758
WORKSPACE_PGID=1000
5859
WORKSPACE_NODE_VERSION=stable

workspace/Dockerfile-56

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \
525525
&& rm terraform_0.10.6_linux_amd64.zip \
526526
;fi
527527

528+
#####################################
529+
# Dusk Dependencies:
530+
#####################################
531+
USER root
532+
ARG INSTALL_DUSK_DEPS=false
533+
ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS}
534+
RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \
535+
# Install required packages
536+
add-apt-repository ppa:ondrej/php \
537+
&& apt-get update \
538+
&& apt-get -y install zip wget unzip xdg-utils \
539+
libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \
540+
gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \
541+
xfonts-base xfonts-scalable x11-apps \
542+
543+
# Install Google Chrome
544+
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
545+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
546+
&& apt-get -y -f install \
547+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
548+
&& rm google-chrome-stable_current_amd64.deb \
549+
550+
# Install Chrome Driver
551+
&& wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \
552+
&& unzip chromedriver_linux64.zip \
553+
&& mv chromedriver /usr/local/bin/ \
554+
&& rm chromedriver_linux64.zip \
555+
;fi
556+
528557
#
529558
#--------------------------------------------------------------------------
530559
# Final Touch

workspace/Dockerfile-70

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \
618618
&& rm terraform_0.10.6_linux_amd64.zip \
619619
;fi
620620

621+
#####################################
622+
# Dusk Dependencies:
623+
#####################################
624+
USER root
625+
ARG INSTALL_DUSK_DEPS=false
626+
ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS}
627+
RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \
628+
# Install required packages
629+
add-apt-repository ppa:ondrej/php \
630+
&& apt-get update \
631+
&& apt-get -y install zip wget unzip xdg-utils \
632+
libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \
633+
gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \
634+
xfonts-base xfonts-scalable x11-apps \
635+
636+
# Install Google Chrome
637+
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
638+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
639+
&& apt-get -y -f install \
640+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
641+
&& rm google-chrome-stable_current_amd64.deb \
642+
643+
# Install Chrome Driver
644+
&& wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \
645+
&& unzip chromedriver_linux64.zip \
646+
&& mv chromedriver /usr/local/bin/ \
647+
&& rm chromedriver_linux64.zip \
648+
;fi
649+
621650
#
622651
#--------------------------------------------------------------------------
623652
# Final Touch

workspace/Dockerfile-71

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,35 @@ RUN if [ ${INSTALL_TERRAFORM} = true ]; then \
624624
&& rm terraform_0.10.6_linux_amd64.zip \
625625
;fi
626626

627+
#####################################
628+
# Dusk Dependencies:
629+
#####################################
630+
USER root
631+
ARG INSTALL_DUSK_DEPS=false
632+
ENV INSTALL_DUSK_DEPS ${INSTALL_DUSK_DEPS}
633+
RUN if [ ${INSTALL_DUSK_DEPS} = true ]; then \
634+
# Install required packages
635+
add-apt-repository ppa:ondrej/php \
636+
&& apt-get update \
637+
&& apt-get -y install zip wget unzip xdg-utils \
638+
libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4 xvfb \
639+
gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi \
640+
xfonts-base xfonts-scalable x11-apps \
641+
642+
# Install Google Chrome
643+
&& wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
644+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
645+
&& apt-get -y -f install \
646+
&& dpkg -i --force-depends google-chrome-stable_current_amd64.deb \
647+
&& rm google-chrome-stable_current_amd64.deb \
648+
649+
# Install Chrome Driver
650+
&& wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip \
651+
&& unzip chromedriver_linux64.zip \
652+
&& mv chromedriver /usr/local/bin/ \
653+
&& rm chromedriver_linux64.zip \
654+
;fi
655+
627656
#
628657
#--------------------------------------------------------------------------
629658
# Final Touch

workspace/aliases.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ alias migrate="php artisan migrate"
6969
alias refresh="php artisan migrate:refresh"
7070
alias rollback="php artisan migrate:rollback"
7171
alias seed="php artisan:seed"
72+
alias serve="php artisan serve --quiet &"
7273

7374
alias phpunit="./vendor/bin/phpunit"
7475
alias pu="phpunit"
@@ -88,6 +89,9 @@ alias reload="source ~/.aliases && echo \"$COL_GREEN ==> Aliases Reloaded... $CO
8889
alias run="npm run"
8990
alias tree="xtree"
9091

92+
# Xvfb
93+
alias xvfb="Xvfb -ac :0 -screen 0 1024x768x16 &"
94+
9195
# requires installation of 'https://www.npmjs.com/package/npms-cli'
9296
alias npms="npms search"
9397
# requires installation of 'https://www.npmjs.com/package/package-menu-cli'

0 commit comments

Comments
 (0)