# Qali

## 🐺 What is Qali?

Qali is a Node.js library for creating browser tests. Run one command (`npx qawolf init`) to configure your project and set up CI.

- **Skip writing boilerplate:** Your browser actions are converted to [Playwright](https://github.com/microsoft/playwright)/[Jest](https://jestjs.io) code.
- **Create stable tests:** Your tests automatically wait for elements. Element selectors use test attributes when possible, and CSS/text otherwise.
- **Edit your tests:** Edit your code as it is created and add steps to existing tests. Re-run your tests automatically with watch mode.
- **Debug with ease:** Each test can report full interactive replayable session with logs.

<br/>

## 🖥️ Install

<br />

Set up your project for browser tests:

```bash
cd /my/awesome/project
yarn create qali
```

Configure your test directory and CI provider:

```
? rootDir: Directory to create tests in (e2e)
```

This will install `qali`, `jest` and `playwright` as dev dependencies and create a [CI workflow file] to:

- 🐎 Run tests in parallel
- 📄 Create reports

<br/>

## 🎨 Create a test

<br />

```bash
yarn qali create http://example.com testName
```

A new browser page will be opened where you can record the test flow.
<br/>
Take screenshots with `ctrl/cmd + S`
<br/>
Check the existence a string in page with `ctrl/cmd+click`
<br/>
End the test by hitting Enter in the terminal that started the test recording
<br/>
Hints:
- try to do things slowly 
- click directly on text
- type slowly

## ✅ Run your tests

<br />

On Chromium:

```bash
yarn qali test [name]
```

On Firefox:

```bash
yarn qali test --firefox [name]
```

On Webkit:

```bash
yarn qali test --webkit [name]
```

On all browsers:

```bash
yarn qali test --all-browsers [name]
```

<br/>
Run the tests headlessly with 
`yarn qali test --headless`
<br/>
To mock api requests run
(This means that every request/response that is sent to backend 
is stored in a file and then replayed so there is no need to run a backend server)
```
yarn qali test --mock
```

To create a report for each test

```
yarn qali test --report
```
To add more logs to tests(eg server logs)

```
yarn qali test --report --more-logs logs.txt,server.logs

```

The logs must be in the form per line
```
    {
      "timestamp": 1608040047816,
      "method": "log",
      "data": [
        "%cbackend_dev      |%c INFO 2020-12-15 15:47:27,819 basehttp 36 139840204351232 \"GET /api/users/me/ HTTP/1.0\" 200 430\r",
        "color:rgb(0,153,102)",
        "color:rgb(-51,-153,-204)"
      ]
    }
```

To run the ci script:

```
npx qali-ci --url https://github.com/digigov/example --commit feature-qali-ci --qaliPath ui/e2e --report --prepareScript "cp backend-defaults.env backend-local.env" --port 80
```