go-gitea:main
← AllSpiceIO:kd/ci-playwright
opened 12:25AM - 29 Jan 22 UTC
Closes #18346
Test adding [playwright](https://playwright.dev/) support for e…nd to end tests.
Current implementation:
- use `make test-e2e` to run default e2e setup using sqlite
- (re)builds gitea binary
- uses integration test templates to build app.ini
- runs `gitea web` and playwright tests
- (not yet implemented) initialize/test DB before each test fixture
- run series of assertion tests (eg. load page, assert load, click button...)
- (not yet implemented) reset/cleanup database
- can alternatively use `make test-e2e-mysql` or any of the other supported DBs in integration tests
- can use `test-e2e#test_name` or `test-e2e-mysql#test_name` to run subset of tests
For example, I run as:
```
TEST_PGSQL_HOST=localhost:5432 TEST_PGSQL_DBNAME=gitea_e2e TEST_PGSQL_USERNAME=gitea TEST_PGSQL_PASSWORD=gitea TEST_PGSQL_SCHEMA='' NO_DEPS_PLAYWRIGHT=1 make test-e2e-pgsql
```
If you remove `NO_DEPS_PLAYWRIGHT=1` it will run as root to install playwright + dependencies. Otherwise, you'll have to run `npx playwright install --with-deps`
You can uncomment the two lines in my test script to try the visual testing.
Some questions to answer:
### How to handle DBs?
This is the last major hickup I have. Running in CI is easy because we start with a fresh DB every time. Running locally is a bit more difficult, because I want to put the DB back in the state that it started in at the end of the test. Ideas:
- Is there a way to create a fresh DB using gitea? It looks like xorm supports creating tables, maybe I can write a wrapper for that?
- Maybe I can expose or copy some of the functions in `integration_test.go` to prep and teardown the environment.
- I can create a database "dump" at the beginning of the tests and restore at the end.
### Can any makefile experts take a look at the makefile commands?
### How to structure tests?
- Since end-to-end tests should emulate a production environment, I think they should be able to run in parallel. That is any data that is created should not interfere with other tests (maybe there is a simple way to enforce this by prepending the test name hash to any emulated user data).
- Currently I put the demo test in `./tools/e2e/tests/`. Haven't investigated syncing with jest.
### Browsers we want to test on?
Currently, I've enabled presets for `chromium`, `firefox`, `webkit`, `Mobile Chrome`, and `Mobile Safari`. Some explanation for Playwright browsers is [here](https://playwright.dev/docs/browsers). All options for presets are [here](https://github.com/microsoft/playwright/blob/5382a794fecdad0fce9178ad0b659e17bc7db9ad/packages/playwright-core/src/server/deviceDescriptorsSource.json#L576).