Magnitude:一个基于AI的端到端Web测试平台
Magnitude是什么?
Magnitude是一个基于ai的端到端Web测试平台,可以通过自然语言和视觉智能技术简化Web应用的测试流程。它提供了一个SDK和一个UI仪表板,支持托管服务和自托管两种模式,能够帮助开发者和测试人员快速编写、执行和管理测试用例。
Magnitude功能特征
自然语言测试编写
使用自然语言描述测试用例,无需编写复杂的代码或依赖DOM元素。
示例: TypeScript 复制 test('can log in and create company') .step('Log in to the app') .data({ username: 'test-user@magnitude.run' }) .secureData({ password: 'test' }) .check('Can see dashboard') .step('Create a new company') .data('Make up the first 2 values and use defaults for the rest') .check('Company added successfully');
视觉驱动的测试执行
内置视觉AI代理,能够识别Web界面的变化并自动调整测试步骤,确保测试用例的稳定性和可靠性。
测试用例对界面变化具有高度适应性,无需频繁更新。
托管与自托管支持
托管服务:提供托管的浏览器基础设施和LLM(大型语言模型)服务,用户无需自行搭建环境。
自托管:完全开源,支持自托管模式,用户可以使用自己的基础设施和LLM提供商。
测试管理与可视化
提供UI仪表板,用于管理测试用例、查看测试运行历史和结果。
支持本地运行和CI/CD管道集成,方便自动化测试。
智能推理与动态调整
内置推理代理,能够根据测试执行中的问题动态调整测试策略。
测试计划保存后可以重复执行,确保每次测试的一致性。
应用场景
Web应用开发:在开发过程中快速编写和执行测试用例,确保功能的正确性和稳定性。
持续集成/持续部署(CI/CD):集成到CI/CD管道中,自动化运行测试,提高开发效率。
界面变更测试:由于其视觉驱动的特性,Magnitude能够有效应对界面变化,减少测试维护成本。
团队协作:通过自然语言编写测试用例,降低测试人员的技术门槛,便于团队协作和知识共享。
使用方法
1. 安装Magnitude SDK
在Node.js项目中安装Magnitude测试运行器:
npm install --save-dev magnitude-test
2. 初始化Magnitude
运行以下命令初始化Magnitude,生成基本的测试目录和配置文件:
npx magnitude init
3. 配置Magnitude
如果使用托管服务,需要获取Magnitude API密钥并设置环境变量:
export MAGNITUDE_API_KEY=<your-api-key-here>
如果使用自托管模式,需要自行配置LLM和浏览器基础设施。
4. 编写测试用例
使用自然语言编写测试用例,示例如下:
import { test } from 'magnitude-test'; test('can log in and create company') .step('Log in to the app') .data({ username: 'test-user@magnitude.run' }) .secureData({ password: 'test' }) .check('Can see dashboard') .step('Create a new company') .data('Make up the first 2 values and use defaults for the rest') .check('Company added successfully');
5. 运行测试
使用以下命令运行Magnitude测试:
npx magnitude run
测试结果可以在Magnitude仪表板中查看。
GitHub代码库:https://github.com/magnitudedev/magnitude
Magnitude官网:https://magnitude.run/