grafana/contribute/style-guides/e2e-plugins.md
Erik Sundell 0f1b65a7ad
Grafana E2E: Add deprecation notice and update docs (#85619)
* add deprecation notice

* update docs

* Update packages/grafana-e2e/README.md

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>

---------

Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>
2024-04-09 10:10:19 +02:00

2.6 KiB

end-to-end tests for plugins

When end-to-end testing Grafana plugins, it's recommended to use the @grafana/plugin-e2e testing tool. @grafana/plugin-e2e extends @playwright/test capabilities with relevant fixtures, models, and expect matchers; enabling comprehensive end-to-end testing of Grafana plugins across multiple versions of Grafana. For information on how to get started with Plugin end-to-end testing and Playwright, checkout the Get started guide.

Adding end-to-end tests for a core plugin

Playwright end-to-end tests for plugins should be added to the e2e/plugin-e2e directory.

  1. Add a new directory that has the name as your plugin here. This is where your plugin tests will be kept.

  2. Playwright uses projects to logically group tests together. All tests in a project share the same configuration. In the Playwright config file, add a new project item. Make sure the name and the testDir sub directory matches the name of the directory that contains your plugin tests. Adding 'authenticate' to the list of dependencies and specifying 'playwright/.auth/admin.json' as storage state will ensure all tests in your project will start already authenticated as an admin user. If you wish to use a different role for and perhaps test RBAC for some of your tests, please refer to the plugin-e2e documentation.

    {
       name: 'mysql',
       testDir: path.join(testDirRoot, '/mysql'),
       use: {
         ...devices['Desktop Chrome'],
         storageState: 'playwright/.auth/admin.json',
       },
       dependencies: ['authenticate'],
     },
    
  3. Update the CODEOWNERS file so that your team is owner of the tests in the directory you added in step 1.

Commands

  • yarn e2e:playwright will run all Playwright tests. Optionally, you can provide the --project mysql argument to run tests in a certain project.

The script above assumes you have Grafana running on localhost:3000. You may change this by providing environment variables.

HOST=127.0.0.1 PORT=3001 yarn e2e:playwright