-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Playwright to the transition repo, and run a few simple tests on …
…github. Fix: #1065
- Loading branch information
1 parent
2eb1888
commit 8d557eb
Showing
22 changed files
with
790 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,3 +70,11 @@ MAIL_TRANSPORT_SMTP_AUTH_PWD=password | |
|
||
# From email | ||
MAIL_FROM_ADDRESS=[email protected] | ||
|
||
#Parameters used to login to a test account in the playwright tests | ||
PLAYWRIGHT_TEST_USER=testUser | ||
PLAYWRIGHT_TEST_EMAIL=[email protected] | ||
PLAYWRIGHT_TEST_PASSWORD=testPassword | ||
|
||
# Put as true when testing Playwright on the pipeline | ||
IS_TESTING_PLAYWRIGHT=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,15 +12,39 @@ on: | |
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
services: | ||
postgres: | ||
image: postgis/postgis | ||
ports: | ||
- 5432:5432 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
env: | ||
POSTGRES_USER: testuser | ||
POSTGRES_PASSWORD: testpassword | ||
POSTGRES_DB: testdb | ||
strategy: | ||
matrix: | ||
node-version: [18.x, 20.x] | ||
env: | ||
PROJECT_CONFIG: ${{ github.workspace }}/examples/config.js | ||
PG_CONNECTION_STRING_PREFIX: postgres://testuser:testpassword@localhost:5432/ | ||
PG_DATABASE_PRODUCTION: testdb | ||
PG_DATABASE_DEVELOPMENT: testdb | ||
CI: true ## This is to make sure that the tests run in CI mode | ||
PLAYWRIGHT_TEST_USER: testUser | ||
PLAYWRIGHT_TEST_EMAIL: [email protected] | ||
PLAYWRIGHT_TEST_PASSWORD: testPassword | ||
IS_TESTING_PLAYWRIGHT: true | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: copy env file | ||
run: cp .env.example .env | ||
- name: copy config file | ||
run: cp examples/config-example-no-osrm.js examples/config.js | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v4 | ||
with: | ||
|
@@ -31,10 +55,39 @@ jobs: | |
run: yarn compile | ||
- name: Build Client bundle | ||
run: yarn build:prod | ||
- name: Unit Test | ||
run: yarn test | ||
- name: UI Test | ||
# - name: Unit Test | ||
# run: yarn test | ||
# Following configure the automated UI tests | ||
- name: Create DB | ||
run: yarn setup && yarn migrate | ||
env: | ||
NODE_ENV: production | ||
- name: Get Playwright config | ||
run: cp packages/chaire-lib-frontend/playwright-example.config.ts packages/chaire-lib-frontend/playwright.config.ts | ||
- name: Create test user | ||
run: yarn create-user --username $PLAYWRIGHT_TEST_USER --email $PLAYWRIGHT_TEST_EMAIL --password $PLAYWRIGHT_TEST_PASSWORD --admin | ||
- name: Create test resources directory | ||
run: mkdir -p packages/chaire-lib-frontend/ui-tests-resources | ||
- name: Download gtfs feed | ||
run: curl -L -o packages/chaire-lib-frontend/ui-tests-resources/gtfs.zip https://github.com/chairemobilite/transition/releases/download/playwright/gtfs.zip | ||
- name: Download invalid gtfs feed | ||
run: curl -L -o packages/chaire-lib-frontend/ui-tests-resources/invalid-gtfs.zip https://github.com/chairemobilite/transition/releases/download/playwright/invalid-gtfs.zip | ||
- name: Start application | ||
run: yarn start & | ||
env: | ||
NODE_ENV: production | ||
- name: Start cache | ||
rum: yarn start:json2capnp -- 2000 $PWD/examples/runtime/cache/demo_transition | ||
- name: Run UI tests | ||
run: yarn test:ui | ||
- name: Archive UI Test results | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: playwright-results-${{matrix.node-version}} # This is to make sure that the results are stored in a unique name | ||
path: packages/chaire-lib-frontend/test-results | ||
retention-days: 2 | ||
# End of automated UI tests | ||
|
||
code-lint: | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,6 +163,41 @@ For example, to run yarn test in the chaire-lib backend: | |
You can also run the app this way with: | ||
`docker run -a STDOUT -it -v "${PWD}:/home/project" -w=/home/project/ testtransition yarn start` | ||
|
||
### UI testing with Playwright | ||
|
||
To execute UI tests with Playwright, you first have to create an account that will be used for logging in to Transition during the tests. This only needs to be done once: | ||
``` | ||
yarn create-user --username testUser --email [email protected] --password testPassword --admin | ||
``` | ||
|
||
You will also need some files used by the "Import GTFS" test. First, create a 'ui-tests-resources' directory in 'packages/chaire-lib-frontend'. Then, download the files 'gtfs.zip' and 'invalid-gtfs.zip' found here: https://github.com/chairemobilite/transition/releases/tag/playwright, and add these files to the newly created 'ui-tests-resources' folder. | ||
|
||
Next, configure Playwright by copying the example config file and select the browser to test in: | ||
``` | ||
cp packages/chaire-lib-frontend/playwright-example.config.ts packages/chaire-lib-frontend/playwright.config.ts | ||
``` | ||
|
||
Next, install browser dependencies to correctly execute the tests. If it is not done, an arror message should tell you the command when attempting to run the test. It is possible to install each browser separaly with the following command, for example `firefox`: | ||
``` | ||
npx playwright install --with-deps firefox | ||
``` | ||
|
||
Now that Playwright is configured, you need to start the application as you would to run it normally: | ||
``` | ||
yarn build:dev or yarn build:prod | ||
yarn start | ||
``` | ||
|
||
Then, to run the tests: | ||
``` | ||
yarn test:ui | ||
``` | ||
|
||
You can also use this command to open a graphic interface that allows you to run tests individually and gives more info: | ||
``` | ||
yarn test:ui --ui | ||
``` | ||
|
||
## Contributing | ||
|
||
See [CONTRIBUTING.md](CONTRIBUTING.md) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
module.exports = { | ||
|
||
projectShortname: 'demo_transition', | ||
projectDirectory: `${__dirname}/runtime/`, | ||
auth: { | ||
localLogin: { | ||
allowRegistration: true, | ||
// This will send an email to confirm the user's email address. Email send needs to be configured. By default, users can register and directly login. | ||
// confirmEmail: true | ||
} | ||
}, | ||
maxParallelCalculators: 2, | ||
|
||
// Maximum number of parallel calculation. Used in tasks to start the calculator with this number of threads. | ||
// maxParallelCalculators: 2, | ||
|
||
// @deprecated: Use the cacheAllScenarios in the 'routing.transit.engines.trRouting' configuration instead | ||
// trRoutingCacheAllScenarios: false, | ||
// Configuration for the trRouting services. Single is for the single calculation instance (from the UI and public API), while batch is for the batch calculation instance, for tasks | ||
// routing: { | ||
// transit: { | ||
// defaultEngine: 'trRouting', | ||
// engines: { | ||
// trRouting: { | ||
// single: { | ||
// port: 4000, | ||
// // Enable caching of connections for all scenarios in trRouting. Will use more memory | ||
// cacheAllScenarios: false | ||
// }, | ||
// batch: { | ||
// port: 14000, | ||
// // Enable caching of connections for all scenarios in trRouting. Will use more memory and may not be necessary for batch calculations as currently there's only one scenario per task | ||
// cacheAllScenarios: false | ||
// } | ||
// } | ||
// } | ||
// } | ||
// }, | ||
|
||
mapDefaultCenter: { | ||
lat: 45.5092960, | ||
lon: -73.4769080 | ||
}, | ||
|
||
languages: ['fr', 'en'], | ||
|
||
locales: { | ||
fr: 'fr-CA', | ||
en: 'en-CA' | ||
}, | ||
|
||
languageNames: { | ||
fr: "Français", | ||
en: "English" | ||
}, | ||
|
||
title: { | ||
fr: "Démo", | ||
en: "Demo" | ||
}, | ||
|
||
defaultLocale: "fr", | ||
timezone: "America/Montreal", | ||
gtfs: { | ||
socketFileUploaderOptions: { | ||
uploadDirectory : 'gtfs', | ||
fileExtension : 'zip', | ||
renamedFileNameWithoutExtension: 'import', | ||
acceptTypes : ['application/zip'], | ||
maxFileSizeMB : 256, | ||
chunckSizeMB : 10240000, | ||
overwriteExistingFile : true | ||
} | ||
}, | ||
|
||
defaultPreferences: { | ||
osrmRouting: { | ||
modes: { | ||
driving: { | ||
// !!! Be careful: use your own server, since you may be blocked on the osrm demo server after too many queries | ||
port : 7000, // Port used to access OSRM, either locally or remotely | ||
host : null, // If set to null, localhost will be used. Ignored if autoStart set to true | ||
autoStart: true, // If true, a local instance of OSRM will be started | ||
enabled : true // If true, this mode will be configured, otherwise will be left out | ||
}, | ||
cycling: { | ||
port : 8000, | ||
host : null, | ||
autoStart: true, | ||
enabled : true | ||
}, | ||
walking: { | ||
port : 5001, | ||
host : null, | ||
autoStart: true, | ||
enabled : false | ||
}, | ||
bus_suburb: { | ||
port : 7110, | ||
host : null, | ||
autoStart: true, | ||
enabled : true | ||
}, | ||
bus_urban: { | ||
port : 7120, | ||
host : null, | ||
autoStart: true, | ||
enabled : true | ||
}, | ||
rail: { | ||
port : 9000, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
}, | ||
tram: { | ||
port : 9100, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
}, | ||
tram_train: { | ||
port : 9200, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
}, | ||
metro: { | ||
port : 9300, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
}, | ||
monorail: { | ||
port : 9400, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
}, | ||
cable_car: { | ||
port : 9500, | ||
host : null, | ||
autoStart: false, | ||
enabled : false | ||
} | ||
} | ||
}, | ||
transit: { | ||
routing: { | ||
batch: { | ||
allowSavingOdTripsToDb: true | ||
} | ||
} | ||
} | ||
}, | ||
tokenLifespanDays: 14 | ||
}; | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.