Grafana / 插件 E2E
端到端的测试 Grafana 插件轻松.
链接
概览
@grafana/plugin-e2e 是专门为Grafana插件开发者设计的。 它延伸 剧作家测试 具有固定装置、模型和预期匹配者的能力,从而能够对Grafana插件进行跨多个版本的全面端到端测试。 这个软件包简化了测试过程,确保了您的插件坚固并兼容各种Grafana环境.
特征
- 预定义的固定线 : 为 Grafana 插件测试提供一套预定义的固定装置.
- 自定义模型 : 提供代表Grafana中的页面和组件的自定义模型,简化维护并创建可重复使用的代码来避免重复.
- 期待匹配者 : 包括一系列针对 Grafana 插件断言的预期匹配者, 帮助您更有效地验证插件行为 .
- 版本兼容性 : 保证您的插件在 Grafana 的多版本测试,保证兼容性和稳定性 .
- 无障碍测试: 与 Axe 整合,支持测试中的可配置无障碍测试,默认规则与 Grafana 一致 WCAG2 导弹 AA 对 目标.
- 与 Playwright 合并 : 与Playwright测试框架无缝地融合,利用其强大的浏览器自动化能力.
开始吧
检查我们 Get started 关于如何安装、配置、写入测试和在CI中运行端到端测试的详细指南.
先决条件
安装播放机
请参看 剧作家文档 用于指导如何安装. @grafana/plugin-e2e 扩展 Playwright API, 因此您需要拥有 Playwright/test 在您的插件的软件包.json文件中,将最小版本的1.41.2作为dev依赖性安装.
配置剧作家
打开 Playwright 安装时生成的 Playwright 配置文件并粘贴以下配置.
import { dirname } from 'path';
import { defineConfig, devices } from '@playwright/test';
import type { PluginOptions } from '@grafana/plugin-e2e';
const pluginE2eAuth = `${dirname(require.resolve('@grafana/plugin-e2e'))}/auth`;
export default defineConfig<PluginOptions>({
testDir: './tests', // change this to the directory that was chosen when installing Playwright
reporter: 'html',
use: {
baseURL: process.env.GRAFANA_URL || 'http://localhost:3000',
},
projects: [
{
name: 'auth',
testDir: pluginE2eAuth,
testMatch: [/.*\.js/],
},
{
name: 'run-tests',
use: {
...devices['Desktop Chrome'],
storageState: 'playwright/.auth/admin.json',
},
dependencies: ['auth'],
},
],
});
写入测试
以下是一个基本例子,说明如何使用 @grafana/plugin-e2e数字 :
import { test, expect } from '@grafana/plugin-e2e';
test('data query should return values 10 and 20', async ({ panelEditPage, readProvisionedDataSource }) => {
const ds = await readProvisionedDataSource({ fileName: 'datasources.yml' });
await panelEditPage.datasource.set(ds.name);
await panelEditPage.setVisualization('Table');
await expect(panelEditPage.refreshPanel()).toBeOK();
await expect(panelEditPage.panel.data).toContainText(['10', '20']);
});
运行测试
要进行测试,请使用以下命令:
npx playwright test
捐款
我们欢迎向@grafana/plugin-e2e捐款。 如果有兴趣的话,请读一下我们 提供指南。 。 。 .
贷项
@grafana/plugin-e2e 没有我不可能 剧作家测试非常感谢微软和所有为这个惊人的工具献计献策的人!