Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-124]: Integrating Playwright for E2E tests #228

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c24bd0f
setup playwright using docs
rahulsuresh-git Nov 1, 2023
a3871d2
fixed setup commands in setup-environment script
rahulsuresh-git Nov 1, 2023
389c10f
added readme
rahulsuresh-git Nov 1, 2023
e52d248
added config for playwright
rahulsuresh-git Nov 1, 2023
c0d4dc3
Merge branch 'master' of https://github.com/rahulsuresh-git/mattermos…
rahulsuresh-git Nov 9, 2023
ef99bdd
integrated playwright utils and added test to check available commands
rahulsuresh-git Nov 9, 2023
cce3e55
removed changes from user.ts
rahulsuresh-git Nov 9, 2023
ab195be
fixed TodoBot URL
rahulsuresh-git Nov 9, 2023
15ea6cb
removed a comment
rahulsuresh-git Nov 9, 2023
54c3133
improvements to message input function
rahulsuresh-git Nov 10, 2023
007367f
fixed issue with cleanUpBotDMs
rahulsuresh-git Nov 10, 2023
23c6e32
added github workflow for playwright
rahulsuresh-git Nov 11, 2023
6646dd0
updated workflow with workflow_dispatch
rahulsuresh-git Nov 15, 2023
8d22541
updated node version in .nvmrc
rahulsuresh-git Nov 15, 2023
8bc4127
updated package-lock.json
rahulsuresh-git Nov 16, 2023
98e0dc2
updated package-lock.json for node 16.13.1
rahulsuresh-git Nov 16, 2023
3a94bd3
updated package-lock.json for node 16.13.1
rahulsuresh-git Nov 16, 2023
63284a8
Merge branch 'feat/adding-playwright-e2e' of https://github.com/rahul…
rahulsuresh-git Nov 16, 2023
721a285
added python to workflow
rahulsuresh-git Nov 16, 2023
4be1742
removed python from workflow and removed package-lock.json cache
rahulsuresh-git Nov 16, 2023
0e9c707
attempts to fix workflow failure
rahulsuresh-git Nov 16, 2023
858d67e
attempts to fix workflow failure
rahulsuresh-git Nov 16, 2023
67351b4
attempts to fix workflow failure
rahulsuresh-git Nov 16, 2023
f48fdb2
reverted workflow changes
rahulsuresh-git Nov 16, 2023
745a291
reverted workflow changes
rahulsuresh-git Nov 16, 2023
3ac3aec
disabled caching in workflow
rahulsuresh-git Nov 16, 2023
a798f8d
Merge branch 'master' of https://github.com/rahulsuresh-git/mattermos…
rahulsuresh-git Nov 16, 2023
ab0fcd9
updated playwright workflow and node version to 16.20.2
rahulsuresh-git Nov 16, 2023
ae3e6d2
updated to node 18.17 and updated setup-environment
rahulsuresh-git Nov 16, 2023
f848c87
updated workflow with new steps
rahulsuresh-git Nov 16, 2023
cf843ad
changed checkout method for mattermost-monorepo
rahulsuresh-git Nov 16, 2023
1a37d61
fixed tsc errors
rahulsuresh-git Nov 16, 2023
8a698e3
commented out playwright ci/lint in workflow
rahulsuresh-git Nov 16, 2023
dd496af
updated workflow to run on pull_request
rahulsuresh-git Nov 17, 2023
e6af7c0
updated workflow triggers
rahulsuresh-git Nov 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 182 additions & 5 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,196 @@
name: Playwright Tests
on:
workflow_run:
workflows: ["ci"]
types:
- completed
Comment on lines -3 to -6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to other reviewers that one of the main reasons this was written this way before was so PRs coming from forks could use the OAuth token secrets for e2e testing. We're going to try to avoid the need to use real tokens going forward, by having a test harness around external services, that the e2e test can act as and make assertions.

push:
branches:
- master
tags:
- "v*"
pull_request:
workflow_dispatch:

env:
TERM: xterm
GO_VERSION: 1.19.6
NODE_VERSION: 16.20.2

jobs:
playwright-run:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:11.13
env:
POSTGRES_USER: mmuser
POSTGRES_PASSWORD: mostest
POSTGRES_DB: mattermost_test
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
minio:
image: minio/minio:RELEASE.2019-10-11T00-38-09Z
env:
MINIO_ACCESS_KEY: minioaccesskey
MINIO_SECRET_KEY: miniosecretkey
MINIO_SSE_MASTER_KEY: "my-minio-key:6368616e676520746869732070617373776f726420746f206120736563726574"
inbucket:
image: mattermost/inbucket:release-1.2.0
ports:
- 10080:10080
- 10110:10110
- 10025:10025
elasticsearch:
image: mattermost/mattermost-elasticsearch-docker:7.0.0
env:
http.host: "0.0.0.0"
http.port: 9200
http.cors.enabled: "true"
http.cors.allow-origin: "http://localhost:1358,http://127.0.0.1:1358"
http.cors.allow-headers: "X-Requested-With,X-Auth-Token,Content-Type,Content-Length,Authorization"
http.cors.allow-credentials: "true"
transport.host: "127.0.0.1"
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
ports:
- 9200:9200
mattermost-server:
image: mattermost/mattermost-enterprise-edition:master
env:
DB_HOST: postgres
DB_PORT_NUMBER: 5432
MM_DBNAME: mattermost_test
MM_USERNAME: mmuser
MM_PASSWORD: mostest
CI_INBUCKET_HOST: inbucket
CI_INBUCKET_PORT: 10080
CI_MINIO_HOST: minio
IS_CI: true
MM_CLUSTERSETTINGS_READONLYCONFIG: false
MM_EMAILSETTINGS_SMTPSERVER: inbucket
MM_EMAILSETTINGS_SMTPPORT: 10025
MM_ELASTICSEARCHSETTINGS_CONNECTIONURL: http://elasticsearch:9200
MM_EXPERIMENTALSETTINGS_USENEWSAMLLIBRARY: true
MM_SQLSETTINGS_DATASOURCE: "postgres://mmuser:mostest@postgres:5432/mattermost_test?sslmode=disable&connect_timeout=10"
MM_SQLSETTINGS_DRIVERNAME: postgres
MM_PLUGINSETTINGS_ENABLEUPLOADS: true
MM_SERVICESETTINGS_SITEURL: http://localhost:8065
MM_PLUGINSETTINGS_AUTOMATICPREPACKAGEDPLUGINS: false
MM_ANNOUNCEMENTSETTINGS_ADMINNOTICESENABLED: false
MM_FEATUREFLAGS_AppsEnabled: true

ports:
- 8065:8065
- 4000:4000
env:
TYPE: NONE
PULL_REQUEST: ""
HEADLESS: true
DASHBOARD_ENABLE: false
FULL_REPORT: false
MM_SERVICESETTINGS_SITEURL: http://localhost:8065
MM_ADMIN_EMAIL: [email protected]
MM_ADMIN_USERNAME: sysadmin
MM_ADMIN_PASSWORD: Sys@dmin-sample1
TEST_DATABASE_URL: postgres://mmuser:mostest@localhost:5432/mattermost_test
MM_SERVICESETTINGS_ENABLEDEVELOPER: true
steps:
- name: ci/checkout-repo
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0

- name: ci/setup-go
uses: actions/setup-go@6edd4406fa81c3da01a34fa6f6343087c207a568 # v3.5.0
with:
go-version: "${{ env.GO_VERSION }}"
cache: true

- name: ci/setup-node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: ".nvmrc"
# cache: "npm"
# cache-dependency-path: webapp/package-lock.json
Comment on lines +108 to +113
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an issue to address dependency caching #233


- name: ci/create-admin-user
run: |
STATUSCODE=$(curl -X POST -H "Content-Type: application/json" -d '{"email": "'${MM_ADMIN_EMAIL}'", "username": "'${MM_ADMIN_USERNAME}'", "password": "'${MM_ADMIN_PASSWORD}'"}' ${MM_SERVICESETTINGS_SITEURL}/api/v4/users -w "%{http_code}" -o /dev/stderr)
if test $STATUSCODE -ne 201; then exit 1; fi

- name: ci/install-go-dependencies
run: go mod tidy

- name: ci/install-plugin-webapp-deps
run: cd webapp && npm ci

- name: ci/build-and-install-plugin
run: make deploy
env:
PLUGIN_E2E_MOCK_OAUTH_SERVER_URL: http://172.17.0.1:8080
E2E_TESTING: true

# - name: ci/checkout-mattermost-monorepo
# uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
# with:
# path: ../mattermost
# repository: mattermost/mattermost
Comment on lines +132 to +136
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this block


- name: ci/checkout-mattermost-monorepo
run: |
git clone https://github.com/mattermost/mattermost.git ../mattermost

- name: ci/setup-node-for-mattermost-monorepo
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: "../mattermost/.nvmrc"

- name: ci/install-mattermost-monorepo-webapp-deps
run: |
cd ../mattermost/webapp
npm i

- name: ci/install-mattermost-monorepo-playwright-deps
run: |
cd ../mattermost/e2e-tests/playwright
npm i
npx playwright install --with-deps

- name: ci/setup-node-for-mattermost-plugin
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version-file: ".nvmrc"

- name: ci/install-plugin-playwright-deps
run: |
cd e2e/playwright
npm ci

- name: ci/tsc
run: |
cd e2e/playwright
npm run tsc

# - name: ci/lint
# run: |
# cd e2e/playwright
# npm run lint
Comment on lines +168 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all of the other steps are descriptive:

Suggested change
- name: ci/tsc
run: |
cd e2e/playwright
npm run tsc
# - name: ci/lint
# run: |
# cd e2e/playwright
# npm run lint
- name: ci/tsc-plugin-playwright
run: |
cd e2e/playwright
npm run tsc
# - name: ci/lint-plugin-playwright
# run: |
# cd e2e/playwright
# npm run lint

Comment on lines +173 to +176
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a ticket to address this in a separate PR #232

We were receiving linting errors in the e2e code:

The task here is to fix the linting errors here:
https://github.com/rahulsuresh-git/mattermost-plugin-todo/actions/runs/6897786793/job/18766591926

/home/runner/work/mattermost-plugin-todo/mattermost-plugin-todo/e2e/playwright/playwright.config.ts
  4:1  error  Parsing error: The keyword 'import' is reserved


- name: ci/run-playwright-tests
run: |
cd e2e/playwright
npm run test-ci
env:
PW_BASE_URL: ${{ env.MM_SERVICESETTINGS_SITEURL }}

- name: ci/move-artifacts
if: success() || failure()
run: |
cd e2e/playwright
mkdir results
mv playwright-report results

- uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: test-results
path: e2e/playwright/results
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.13.1
16.20.2
9 changes: 9 additions & 0 deletions e2e/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules/
/blob-report/
/playwright/.cache/
.env
screenshots
playwright-report
test-results
.auth-user.json
.eslintcache
37 changes: 37 additions & 0 deletions e2e/playwright/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
In order to get your environment set up to run [Playwright](https://playwright.dev) tests, you can run `./setup-environment`, or run equivalent commands for your current setup.

What this script does:

- Navigate to the folder above `mattermost-plugin-todo`
- Clone `mattermost` (if it is already cloned there, please have a clean git index to avoid issues with conflicts)
- `cd mattermost`
- Install webapp dependencies - `cd webapp && npm i`
- Install Playwright test dependencies - `cd ../e2e-tests/playwright && npm i`
- Install Playwright - `npx install playwright`
- Install Todo plugin e2e dependencies - `cd ../../../mattermost-plugin-todo/e2e/playwright && npm i`
- Build and deploy plugin with e2e support - `make deploy-e2e`

---

Then to run the tests:

Start Mattermost server:

- `cd <path>/mattermost/server`
- `make test-data`
- `make run-server`

Run test:

- `cd <path>/mattermost-plugin-todo/e2e/playwright`
- `npm test`

To see the test report:

- `cd <path>/mattermost-plugin-todo/e2e/playwright`
- `npm run show-report`
- Navigate to http://localhost:9323

To see test screenshots:

- `cd <path>/mattermost-plugin-todo/e2e/playwright/screenshots`
Loading