<commit_before># Introduction

End to end tests are performed using [Protractor](http://www.protractortest.org/).

Each plugin (and OpenVeo core) defines a list of test suites in **tests/client/protractorSuites.json**.

# Install Protractor

First of all you need to install Protractor, all information are available on Protractor's web site.

# Configure tests

To be able to launch end to end tests, OpenVeo needs to find the selenium jar and the chrome driver file installed with Protractor.
You can specify the path of the selenium jar using **SELENIUM_JAR** environment variable and chrome driver using **CHROME_DRIVER** environment variable.

You also need to specify a new database which will be used during tests. To do so, you can add a new configuration file in user's directory under **~/.openveo/core** called **databaseTestConf.json**.

**~/.openveo/core/databaseTestConf.json**

```json
{
  "type": "mongodb",
  "host": "localhost",
  "port": 27017,
  "database": "openveo-test",
  "username": "openveo",
  "password": "<PASSWORD>"
}
```

**WARNING** : Each time you launch end to end tests, all information will be removed from this database ! DO NOT use the same database as the one described in **databaseConf.json**

# Launch server in test mode

    node server.js -t

# Launch end to end tests

    # Launch all end to end tests on chrome
    grunt test-e2e --capabilities="{\"browserName\": \"chrome\"}" --directConnect=true

    # Launch all end to end tests on firefox
    grunt test-e2e --capabilities="{\"browserName\": \"firefox\"}" --directConnect=true

    # Launch only homePage suite on chrome
    grunt test-e2e --capabilities="{\"browserName\": \"chrome\"}" --directConnect=true --suite="homePage"<commit_msg>Add more documentation about end to end tests<commit_after># Introduction

End to end tests are performed using [Protractor](http://www.protractortest.org/).

Each plugin (and OpenVeo core) defines a list of test suites in **tests/client/protractorSuites.json**.

# Install Protractor globally

First of all you need to install Protractor, all information are available on Protractor's web site.

# Remove grunt-protractor-runner local protractor

    rm -rf node_modules/grunt-protractor-runner/node_modules/protractor

# Configure tests

To be able to launch end to end tests, OpenVeo needs to find the selenium jar and the chrome driver file installed with Protractor.
You can specify the path of the selenium jar using **SELENIUM_JAR** environment variable and chrome driver using **CHROME_DRIVER** environment variable.

You also need to specify a new database which will be used during tests. To do so, you can add a new configuration file in user's directory under **~/.openveo/core** called **databaseTestConf.json**.

**~/.openveo/core/databaseTestConf.json**

```json
{
  "type": "mongodb",
  "host": "localhost",
  "port": 27017,
  "database": "openveo-test",
  "username": "openveo",
  "password": "<PASSWORD>"
}
```

**WARNING** : Each time you launch end to end tests, all information will be removed from this database ! DO NOT use the same database as the one described in **databaseConf.json**

# Writing tests

## Boot steps

When launching end to end tests, several things happen before the first test is launched :

1. Database defined in **~/.openveo/core/databaseTestConf.json** is dropped
2. Users, roles and applications described in **tests/client/e2eTests/database/data.json**, from core and plugins, are inserted into database
3. Tests suites files, in **tests/client/e2eTests/protractorSuites.json** from core and plugins, are merged into one single file (**tests/client/e2eTests/suites/suites.json**)
4. A database connection is made to be able to use models in tests
5. All plugins are loaded and available in ApplicationStorage

## Add users, roles and application before tests

Users, roles and applications can be added before tests are launched using **tests/client/e2eTests/database/data.json** configuration file.

Structure is as follow :

```json
{
  "roles": {
    ...
  },
  "users": {
    ...
  },
  "applications": {
    ...
  }
}
```

### Create a role

```json
{
  "roles": {
    "coreAdmin": { // Id of the role to use when creating users
      "name": "core-admin", // The name of the role
      "permissions": [ // The list of permissions ids as described in conf.json file
        "create-application",
        "update-application",
        "delete-application",
        "create-taxonomy",
        "update-taxonomy",
        "delete-taxonomy",
        "create-user",
        "update-user",
        "delete-user",
        "create-role",
        "update-role",
        "delete-role",
        "access-applications-page",
        "access-users-page",
        "access-roles-page"
      ]
    }
  }
}
```

### Create a user

```json
{
  "users": {
    "coreAdmin": { // Id of the user (not used)
      "name": "core-admin", // The name of the user
      "email": "<EMAIL>", User's email
      "password": "<PASSWORD>", // <PASSWORD>'s password
      "roles": [ "coreAdmin" ] // User's list of roles (role ids are the one described in the same file)
    }
  }
}
```

### Create an application

```json
{
  "applications": {
    "coreApplicationsGuest": { // Id of the application (not used)
      "name": "core-applications-guest", // Name of the application
      "scopes": [ "video" ] // List of scope ids for the application
    }
  }
}
```

### Create test

Create your test file in **tests/client/e2eTests/** then update the list of suites, if necessary, in  **tests/client/e2eTests/suites/suites.json**.

# Debug

If a test fails, a screenshot of the browser at the instant is taken and available in **build/screenshots** of the core.

# Launch server in test mode

    node server.js -t

# Launch end to end tests

    # Launch all end to end tests on chrome
    grunt test-e2e --capabilities="{\"browserName\": \"chrome\"}" --directConnect=true

    # Launch all end to end tests on firefox
    grunt test-e2e --capabilities="{\"browserName\": \"firefox\"}" --directConnect=true

    # Launch only homePage suite on chrome
    grunt test-e2e --capabilities="{\"browserName\": \"chrome\"}" --directConnect=true --suite="homePage"
{'fraction_non_alphanumeric': 0.12013509166934706, 'fraction_numerical': 0.004342232229012544, 'mean_word_length': 3.5130624092888243, 'pattern_counts': {'":': 35, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1990754', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1784, 'n_words': 708}