@dennisdigital/polaris-e2etesting v1.0.1
polaris-e2etesting
Tools for running user tests against our siteapps
Setup
yarn add -D dennisinteractive/polaris-e2etestingCreate
e2e_testsfolder with following structure:
mkdir e2e_tests e2e_tests/features e2e_tests/tests e2e_tests/output e2e_tests/screenshots && touch e2e_tests/output/.gitignore && echo '*\n!.gitignore' > e2e_tests/output/.gitignore
e2e_tests
│
└───features
│ │ bddtest1.feature
│ │ bddtest2.feature
│
└───tests
│ │ test1.test.js
│ │ test2.test.js
│
└───output
└───screenshots- Create
runTests.jsfile
const runTests = require('@dennisdigital/polaris-e2etesting');
runTests();Add
"test:e2e": "node ./runTests.js"to your package.json scripts sectionUpdate the site's Dockerfile (
docker/Dockerfile) to include the following afterARG BUILD_COMMAND
# Install dependencies for running Puppeteer
# https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-in-docker
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
&& apt-get update \
&& apt-get install -y google-chrome-unstable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf \
--no-install-recommends \
&& rm -rf /var/lib/apt/lists/*- Ensure the siteapp's webpack config does not include the
Dotenvplugin for the server bundle (it should still be used for the client bundle)
Usage
Extra config
Default codecept config can be overriden like so
const runTests = require('@dennisdigital/polaris-e2etesting');
runTests({
extraConfig: {
helpers: {
TestCafe: {
browser: 'safari',
},
},
gherkin: {
steps: [
'./e2e_tests/step_definitions/steps.js',
],
},
},
});extraConfig will be merged with default config and override any already defined options. This allows adding extra site specific step definitions to the gherkin.steps array
Override URL
By default a local server will be spun up running the local sitecode (this assumes the code has been compiled, using either yarn build or yarn watch).
If you wish to use a specific url instead this can be overridden by passing the baseUrl parameter. In this case the local server won't run, instead the tests will just run against the url specified
const runTests = require('@dennisdigital/polaris-e2etesting');
runTests({
baseUrl: 'https://evo.develop.coreapp.didev.co.uk',
});Arguments
Arguments can be passed to the package.json script like so: yarn test:e2e --dev
yarn test:e2e --dev- shows browser when running tests
Development
To develop against polaris-e2etesting from within a siteapp (e.g. https://github.com/dennisinteractive/polaris-siteapp) do the following:
- Clone both the
polaris-e2etestingrepo and the siteapp repo into their respective folders - In
polaris-e2etestingrunyarn link. This will allow it to be symlinked in other projects - In
polaris-siteapprunyarnto install dependencies, then runyarn link polaris-e2etesting. This means thatpolaris-siteappwill now use your local copy ofpolaris-e2etestinginstead of the copy in its node_modules folder, allowing you to develop against it - Run
yarn test:e2einpolaris-siteappto start your local version of the test runner