verua-e2e/README.md

91 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

# verua-e2e
This repository contains testing specifications (specs) for VeruA application. The tests are written with <a href="https://playwright.dev/">Playwright</a>. It is a tool that simulates various browsers (Chrome, Firefox, Safari) and executes tests that are written in test specs. It can create reports, can be triggered from git actions and run on a server as well.
## Requirements
- NodeJS and npm: https://nodejs.org/en/download (install for linux)
- yarn: https://yarnpkg.com/getting-started/install (only install corepack)
## Setup
Clone the repo:
```bash
git clone https://code.verua.online/VeruA/verua-e2e.git
cd verua-e2e
```
Install dependencies with yarn:
```bash
yarn
```
## Usage
### Usage with Visual Code / VS Codium
If you are using Visual Code (or as Open Source <a href="https://vscodium.com/">VS Codium</a>) as editor, then you can install Playwright Extension from the marketplace and use it from within. It is recommnded because a lot of helpful videos exist, see Code Generation.
### Usage from Command-Line
```bash
Inside that directory, you can run several commands:
yarn playwright test
Runs the end-to-end tests.
yarn playwright test --ui
Starts the interactive UI mode.
yarn playwright test --project=chromium
Runs the tests only on Desktop Chrome.
yarn playwright test example
Runs the tests in a specific file.
yarn playwright test --debug
Runs the tests in debug mode.
yarn playwright codegen
Auto generate tests with Codegen.
```
### Code Generation
Playwright comes with helpful features that allow code generation by browser recording. Watch this video to understand how tests can be (partially) generated by recording your browser interactions. However, important parts such as checking the expectations have to be written from scratch.
Playwright Documentation about Codegen: https://playwright.dev/docs/codegen
Video aobut Playwright Codegen: https://www.youtube.com/watch?v=LM4yqrOzmFE
**Hint: If the extension does not work, try reloading the windows through command palette or restart the editor.**
## Writing new tests
Tests are written based on Test Cases defined in https://nextcloud.verua.online/apps/files/files/1295007?dir=/Team_VeruA/Testing/Task-Ticket_45540.
The best procedure for writing new tests is:
1. Open `tests/verua.spec.ts`
2. Add a new test at the end of the spec
```TypeScript
test('## - name your test', async ({ page }) => {
// put your cursor here
})
```
3. Start "Record at cursor" (a browser will open up)
4. Disable recording and go to the page that you would like to test.
5. Start recording and re-enter the URL so that it will be recorded.
6. Interact with your browser and see how it will be recorded until you are finished.
7. Add the expected resulted manually to the code.
8. Run the test and see if it succeeds.
*A new test should always be submitted as a PR on a new branch*