虚拟测试- 图书馆
安装
npm install @globalpayments/vega-testing-library
什么是用户Event api
用户- event 是测试库的辅助库, 通过发送如果交互发生在浏览器中而会发生的事件来模拟用户交互
为什么我们需要扩展用户事件 API
目前,在使用测试库进行交互操作时,由于使用了Shadow DOM,找到可触发元素变得非常麻烦和繁琐
const shadowInput: Element = document
.querySelector("vega-input")
?.shadowRoot?.querySelector("input") as Element;
userEvent.type(shadowInput, "input text");
何时使用此库
涉及用户互动的组件应全部使用此库来简化操作,使用户事件简单高效.
使用量
waitForVega ——选择正确的导入
有两个 waitForVega 维加生态系统中的功能。 对上下文使用正确的:
| A. 背景情况 | 从 | 页:1 |
|---|---|---|
| 生产/应用代码 | @globalpayments/vega | 等待网页上所有Vega网络组件的水合. 没有延迟,没有试验框架的组合. |
| 测试代码 | @globalpayments/vega-testing-library | 以上超集: 也等待可选的后水分延迟和 支持 Jest 假定时器 自动. |
// ✅ In tests — use the testing-library version
import { waitForVega } from '@globalpayments/vega-testing-library';
it('renders the button label', async () => {
render(<MyComponent />);
await waitForVega(); // supports jest.useFakeTimers(), optional delay param (default 300 ms)
// Optional: pass a custom delay when a test needs additional render settling time
// await waitForVega(500);
expect(screen.getByText('Submit')).toBeInTheDocument();
});
// ✅ In application / production code — use the core version
import { waitForVega } from '@globalpayments/vega';
async function initPage() {
await waitForVega(); // waits for hydration only
}
waitForVegaReady 从 @globalpayments/vega-angular, (中文(简体) ), @globalpayments/vega-react,以及
@globalpayments/vega-vue 实值 已贬值。迁移到 waitForVega 从
@globalpayments/vega-testing-library数字 :
// Before (deprecated)
import { waitForVegaReady } from '@globalpayments/vega-angular/testing';
const result = await waitForVegaReady(renderResult);
// After
import { waitForVega } from '@globalpayments/vega-testing-library';
await waitForVega();
mockResizeObserver
替换全局 ResizeObserver 带有可控模拟器,用于决定大小调整活动。 以前每个框架包件库都单独提供,现在合并到这里.
import { mockResizeObserver, MockedResizeObserverController } from '@globalpayments/vega-testing-library';
let resizeController: MockedResizeObserverController;
beforeEach(() => {
resizeController = mockResizeObserver();
});
it('hides element when height is 0', () => {
resizeController.hide('.my-element');
expect(screen.queryByText('Content')).not.toBeVisible();
});
mockResizeObserver 从 @globalpayments/vega-angular, (中文(简体) ), @globalpayments/vega-react,以及
@globalpayments/vega-vue 实值 已贬值。从
@globalpayments/vega-testing-library。 。 。 .
假定时器兼容性
vega-testing-library 所有内部变速器的自动推进器,
包括内部 waitForVega。使用 jest.useFakeTimers() 能够全部使用
userForVega APIs和 waitForVega 无需手动呼叫
jest.advanceTimersByTime(...)。 。 。 .
如果你的测试也有自己的解禁逻辑, 你仍然可以明确提前计时器 在您的断言流 视需要.
五十四国
npm i @testing-library/user-event -D
npm i @globalpayments/vega-testing-library -D
import userEvent, { UserEvent } from '@testing-library/user-event'; // v14
import { createUserEventForVega, CompatibleUserEventMethods, UserEventCompatible } from '@globalpayments/vega-testing-library';
let user: UserEvent = userEvent.setup();
const userForVega: CompatibleUserEventMethods<UserEventCompatible> = createUserEventForVega(user);
// Example using vega-input
const vegaInputElement = document.querySelector('vega-input');
await userForVega.type(vegaInputElement, 'input text');
expect(vegaInputElement.value).toBe('input text');
....
V13型
npm i @testing-library/[email protected] -D
npm i @globalpayments/vega-testing-library -D
import userEvent from '@testing-library/user-event'; // v13
import { createUserEventForVega, CompatibleUserEventMethods, UserEventType13 } from '@globalpayments/vega-testing-library';
const userForVega: CompatibleUserEventMethods<UserEventType13<typeof userEvent>> = createUserEventForVega(userEvent);
// Example using vega-input
const vegaInputElement = document.querySelector('vega-input');
userEvent.type(vegaInputElement, 'input text');
expect(vegaInputElement.value).toBe('input text');
....
支助构成部分
| 组件名称 | 支持用户事件 API |
|---|---|
| 维加星等 | 单击: 模拟用户点击手风琴 用法示例: V14 await userForVega.click(vegaAccordion); // will click to toggle expandV13 userForVega.click(vegaAccordion); // will click to toggle expand盘旋:模拟用户在手风琴上徘徊指针 用法示例: V14 await userForVega.hover(vegaAccordion); // will hover toggle buttonV13 userForVega.hover(vegaAccordion); // will hover toggle button卸载:模拟用户将指针移出手风琴 用法示例: V14 await userForVega.unhover(vegaAccordion); // will unhover toggle buttonV13 userForVega.unhover(vegaAccordion); // will unhover toggle button |
| 维加-面包屑b | 单击: 模拟点击面包屑的用户 用法示例: V14 await userForVega.click(vegaBreadcrumb, { index: 0 }); // will click breadcrumb item by indexawait userForVega.click(vegaBreadcrumb, { label: 'level2' }); // will click item by label (visible or in dropdown)V13 userForVega.click(vegaBreadcrumb, undefined, { index: 0 }); // will click breadcrumb item by indexuserForVega.click(vegaBreadcrumb, undefined, { label: 'level2' }); // will click item by label (visible or in dropdown)盘旋:模拟用户在面包屑上徘徊指针 用法示例: V14 await userForVega.hover(vegaBreadcrumb, { index: 0 }); // will hover breadcrumb item by indexawait userForVega.hover(vegaBreadcrumb, { label: 'level2' }); // will hover item by label (visible or in dropdown)V13 userForVega.hover(vegaBreadcrumb, undefined, { index: 0 }); // will hover breadcrumb item by indexuserForVega.hover(vegaBreadcrumb, undefined, { label: 'level2' }); // will hover item by label (visible or in dropdown)卸载:模拟用户将指针移出面包屑 用法示例: V14 await userForVega.unhover(vegaBreadcrumb, { index: 0 }); // will unhover breadcrumb item by indexawait userForVega.unhover(vegaBreadcrumb, { label: 'level2' }); // will unhover item by label (visible or in dropdown)V13 userForVega.unhover(vegaBreadcrumb, undefined, { index: 0 }); // will unhover breadcrumb item by indexuserForVega.unhover(vegaBreadcrumb, undefined, { label: 'level2' }); // will unhover item by label (visible or in dropdown) |
| 维加按钮 | 单击: 模拟用户点击按钮 用法示例: V14 await userForVega.click(vegaButton); // will click buttonV13 userForVega.click(vegaButton); // will click button盘旋: 模拟用户在按钮上徘徊指针 用法示例: V14 await userForVega.hover(vegaButton); // will hover buttonV13 userForVega.hover(vegaButton); // will hover button卸载:模拟用户将指针移出按钮 用法示例: V14 await userForVega.unhover(vegaButton); // will unhover buttonV13 userForVega.unhover(vegaButton); // will unhover button |
| 虚拟按钮圈 | 单击: 模拟点击按钮圆的用户 用法示例: V14 await userForVega.click(vegaButtonCircle); // will click button circleV13 userForVega.click(vegaButtonCircle); // will click button circle盘旋:模拟用户在按钮圆上徘徊指针 用法示例: V14 await userForVega.hover(vegaButtonCircle); // will hover button circleV13 userForVega.hover(vegaButtonCircle); // will hover button circle卸载:模拟一个用户将指针从按钮圆移出 用法示例: V14 await userForVega.unhover(vegaButtonCircle); // will unhover button circleV13 userForVega.unhover(vegaButtonCircle); // will unhover button circle |
| 维加- 按钮链接 | 单击: 模拟点击按钮链接的用户 用法示例: V14 await userForVega.click(vegaButtonLink); // will click button linkV13 userForVega.click(vegaButtonLink); // will click button link盘旋:模拟用户在按钮链接上徘徊指针 用法示例: V14 await userForVega.hover(vegaButtonLink); // will hover button linkV13 userForVega.hover(vegaButtonLink); // will hover button link卸载:模拟用户将指针移出按钮链接 用法示例: V14 await userForVega.unhover(vegaButtonLink); // will unhover button linkV13 userForVega.unhover(vegaButtonLink); // will unhover button link |
| 维加胡萝卜 | 单击:模拟点击旋转木马的用户 用法示例: V14 await userForVega.click(vegaCarousel); // Click page 1await userForVega.click(vegaCarousel, { page: 2 }); // Click page 2V13 userForVega.click(vegaCarousel); // Click page 1userForVega.click(vegaCarousel, undefined, { page: 2 }); // Click page 2盘旋:模拟用户在旋转木马上徘徊指针 用法示例: V14 await userForVega.hover(vegaCarousel); // Hover on carouselV13 userForVega.hover(vegaCarousel); // Hover on carousel卸载:模拟用户将指针移出旋转木马 用法示例: V14 await userForVega.unhover(vegaCarousel); // Unhover on carouselV13 userForVega.unhover(vegaCarousel); // Unhover on carousel |
| vega 检查框 | 单击: 模拟用户点击复选框 用法示例: V14 await userForVega.click(vegaCheckbox); // will click checkboxV13 userForVega.click(vegaCheckbox); // will click checkbox盘旋: 模拟一个用户在复选框上徘徊指针 用法示例: V14 await userForVega.hover(vegaCheckbox); // will hover checkboxV13 userForVega.hover(vegaCheckbox); // will hover checkbox卸载:模拟用户将指针移出复选框 用法示例: V14 await userForVega.unhover(vegaCheckbox); // will unhover checkboxV13 userForVega.unhover(vegaCheckbox); // will unhover checkbox |
| 维加芯片 | 单击:模拟点击芯片的用户 用法示例: V14 await userForVega.click(vegaChip, { iconClose: true }); // will click close iconawait userForVega.click(vegaChip); // will click vega-chip buttonV13 userForVega.click(vegaChip, { iconClose: true }); // will click close iconuserForVega.click(vegaChip); // will click vega-chip button盘旋:模拟用户在芯片上徘徊指针 用法示例: V14 await userForVega.hover(vegaChip); // will hover chipV13 userForVega.hover(vegaChip); // will hover chip卸载:模拟用户将指针移出芯片 用法示例: V14 await userForVega.unhover(vegaChip); // will unhover chipV13 userForVega.unhover(vegaChip); // will unhover chip |
| 彩色选手 | 单击: 模拟用户点击取色器 用法示例: V14 await userForVega.click(vegaColorPicker, {value: '#00BBFF'}); // will selected the colorV13 userForVega.click(vegaColorPicker, undefined, {value: '#00BBFF'}); // will selected the color |
| 虚拟组合 | 清除: 模拟用户清除组合框的值 用法示例: V14 await userForVega.clear(vegaComboBox, 'key', {keyOrLabel: 'key'}); // will clear chip by keyawait userForVega.clear(vegaComboBox, 'label', {keyOrLabel: 'label'}); // will clear chip by labelawait userForVega.clear(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will clear multiple chips by labelawait userForVega.clear(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will clear multiple chips by keyV13 userForVega.clear(vegaComboBox, 'key', {keyOrLabel: 'key'}); // will clear chip by keyuserForVega.clear(vegaComboBox, 'label', {keyOrLabel: 'label'}); // will clear chip by labeluserForVega.clear(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will clear multiple chips by labeluserForVega.clear(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will clear multiple chips by key单击: 模拟用户点击组合框 用法示例: V14 await userForVega.click(vegaComboBox, {triggerDynamicAdd: true}); // will trigger the "Add" button in the dropdownV13 userForVega.click(vegaComboBox, undefined, {triggerDynamicAdd: true}); // will trigger the "Add" button in the dropdown取消选择选项: 模拟用户从多选项中取消选择选项 用法示例: V14 await userForVega.deselectOptions(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will deselect the options according to keyawait userForVega.deselectOptions(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will deselect the options according to labelV13 userForVega.deselectOptions(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will deselect the options according to keyuserForVega.deselectOptions(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will deselect the options according to label选择选项: 模拟用户从选中选项 用法示例: V14 await userForVega.selectOptions(vegaComboBox, 'label', {keyOrLabel: 'label'}); // will select the option according to labelawait userForVega.selectOptions(vegaComboBox, 'key', {keyOrLabel: 'key'}); // will select the option according to keyawait userForVega.selectOptions(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will select the options according to labelawait userForVega.selectOptions(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will select the options according to keyV13 userForVega.selectOptions(vegaComboBox, 'label', {keyOrLabel: 'label'}); // will select the option according to labeluserForVega.selectOptions(vegaComboBox, 'key', {keyOrLabel: 'key'}); // will select the option according to keyuserForVega.selectOptions(vegaComboBox, ['label', ...], {keyOrLabel: 'label'}); // will select the options according to labeluserForVega.selectOptions(vegaComboBox, ['key', ...], {keyOrLabel: 'key'}); // will select the options according to key类型:模拟用户将文本输入组合框 用法示例: V14 await userForVega.type(vegaComboBox, 'Peaches'); // will type 'Peaches' in the input boxV13 userForVega.type(vegaComboBox, 'Peaches'); // will type 'Peaches' in the input box |
| 选择日期者 | 清除:模拟用户清除取日期器的值 用法示例: V14 await userForVega.clear(vegaDatePicker); //For both single & range modeV13 userForVega.clear(vegaDatePicker); //For both single & range mode单击: 模拟用户点击取日期器 用法示例: V14 await userForVega.click(vegaDatePicker); //Click start inputawait userForVega.click(vegaDatePicker, {startOrEnd: 'start'}); //Click start inputawait userForVega.click(vegaDatePicker, {startOrEnd: 'end'}); //Click end inputV13 userForVega.click(vegaDatePicker); //Click start inputuserForVega.click(vegaDatePicker, undefined, {startOrEnd: 'start'}); //Click start inputuserForVega.click(vegaDatePicker, undefined, {startOrEnd: 'end'}); //Click end input类型:模拟用户将文本打入取日期器 用法示例: V14 await userForVega.type(vegaDatePicker, '12/12/2000'); //Type in start inputawait userForVega.type(vegaDatePicker, '12/12/2000', {startOrEnd: 'start', delay: 0}); //Type in start inputawait userForVega.type(vegaDatePicker, '12/12/2000', {startOrEnd: 'end', delay: 0}); //Type in start inputV13 userForVega.type(vegaDatePicker, '12/12/2000'); //Type in start inputuserForVega.type(vegaDatePicker, '12/12/2000', {startOrEnd: 'start', delay: 0}); //Type in start inputuserForVega.type(vegaDatePicker, '12/12/2000', {startOrEnd: 'end', delay: 0}); //Type in start input |
| 维加下拉 | 清除:模拟用户清除下拉值 用法示例: V14 await userForVega.clear(vegaDropdown, 'string'); // Will open dropdown and clear search inputV13 userForVega.clear(vegaDropdown, 'string'); // Will open dropdown and clear search input单击: 模拟用户点击下拉 用法示例: V14 await userForVega.click(vegaDropdown); // will click to openawait userForVega.click(vegaDropdown, { keyOrLabel: 'key', value: 'key' }); // will click dropdown item by item keyawait userForVega.click(vegaDropdown, { keyOrLabel: 'key', value: ['key1', 'key2', 'key3'] }); // will click multiple dropdown items by item keyawait userForVega.click(vegaDropdown, { keyOrLabel: 'label', value: 'Label 1' }); // will click dropdown item by item labelawait userForVega.click(vegaDropdown, { keyOrLabel: 'label', value: ['Label 1', 'Label 2', 'Label 3'] }); // will click multiple dropdown items by item labelawait userForVega.click(vegaDropdown, { action: 'reset' }); // will click reset selection button when items are selectedawait userForVega.click(vegaDropdown, { action: 'add' }); // will click add item button when searched item is not foundV13 userForVega.click(vegaDropdown); // will click to openuserForVega.click(vegaDropdown, undefined, { keyOrLabel: 'key', value: 'key' }); // will click dropdown item by item keyuserForVega.click(vegaDropdown, undefined, { keyOrLabel: 'key', value: ['key1', 'key2', 'key3'] }); // will click multiple dropdown items by item keyuserForVega.click(vegaDropdown, undefined, { keyOrLabel: 'label', value: 'Label 1' }); // will click dropdown item by item labeluserForVega.click(vegaDropdown, undefined, { keyOrLabel: 'label', value: ['Label 1', 'Label 2', 'Label 3'] }); // will click multiple dropdown items by item labeluserForVega.click(vegaDropdown, undefined, { action: 'reset' }); // will click reset selection button when items are selecteduserForVega.click(vegaDropdown, undefined, { action: 'add' }); // will click add item button when searched item is not found类型: 模拟用户将文本输入下拉 用法示例: V14 await userForVega.type(vegaDropdown, 'string'); // Will open dropdown and search by stringV13 userForVega.type(vegaDropdown, 'string'); // Will open dropdown and search by string |
| vega- 下拉组 | 单击: 模拟用户点击下拉组 用法示例: V14 await userForVega.click(vegaDropdownGroup); // will click dropdown group first itemawait userForVega.click(vegaDropdownGroup, { keyOrLabel: 'key', value: 'item1' }); // will click dropdown item by keyawait userForVega.click(vegaDropdownGroup, { keyOrLabel: 'label', value: 'Item 1' }); // will click dropdown item by labelV13 userForVega.click(vegaDropdownGroup); // will click dropdown group first itemuserForVega.click(vegaDropdownGroup, undefined, { keyOrLabel: 'key', value: 'item1' }); // will click dropdown item by keyuserForVega.click(vegaDropdownGroup, undefined, { keyOrLabel: 'label', value: 'Item 1' }); // will click dropdown item by label |
| viga- 下拉项目 | 单击: 模拟用户点击下拉项目 用法示例: V14 await userForVega.click(vegaDropdownItem); // will click dropdown itemV13 userForVega.click(vegaDropdownItem); // will click dropdown item盘旋: 模拟用户在下拉项目上徘徊指针 用法示例: V14 await userForVega.hover(vegaDropdownItem); // will hover dropdown itemV13 userForVega.hover(vegaDropdownItem); // will hover dropdown item卸载: 模拟用户将指针移出下拉项目 用法示例: V14 await userForVega.unhover(vegaDropdownItem); // will unhover dropdown itemV13 userForVega.unhover(vegaDropdownItem); // will unhover dropdown item |
| vega 文件装入器 | 清除: 模拟用户清除文件上传器的值 用法示例: V14 await userForVega.clear(vegaFileUploader, {values: 'file name', indexOrName: 'name'}); // Delete file by nameawait userForVega.clear(vegaFileUploader, {values: ['file name1', 'file name2', ...], indexOrName: 'name'}); // Delete files by nameawait userForVega.clear(vegaFileUploader, {values: '0', indexOrName: 'index'}); // Delete file by indexawait userForVega.clear(vegaFileUploader, {values: ['0', '1', ...], indexOrName: 'index'}); // Delete files by indexV13 userForVega.clear(vegaFileUploader, {values: 'file name', indexOrName: 'name'}); // Delete file by nameuserForVega.clear(vegaFileUploader, {values: ['file name1', 'file name2', ...], indexOrName: 'name'}); // Delete files by nameuserForVega.clear(vegaFileUploader, {values: '0', indexOrName: 'index'}); // Delete file by indexuserForVega.clear(vegaFileUploader, {values: ['0', '1', ...], indexOrName: 'index'}); // Delete files by index上传: 模拟用户上传文件到文件上传器 用法示例: V14 await userForVega.upload(vegaFileUploader, 'file name'); // will upload the single file according to file nameawait userForVega.upload(vegaFileUploader, '['file name', 'file name 1', ....]); // will upload the multiple files according to file namesV13 userForVega.upload(vegaFileUploader, 'file name'); // will upload the single file according to file nameuserForVega.upload(vegaFileUploader, '['file name', 'file name 1', ....]); // will upload the multiple files according to file names |
| 虚拟图像上载器 | 清除: 模拟用户清除图像上传器的值 用法示例: V14 await userForVega.clear(vegaImageUploader); //Delete uploaded imageV13 userForVega.clear(vegaImageUploader); //Delete uploaded image单击: 模拟用户点击图像上传器 用法示例: V14 await userForVega.click(vegaImageUploader, { action: 'replace', file: file }); //Replace imageawait userForVega.click(vegaImageUploader, { action: 'delete' }); //Remove uploaded imageawait userForVega.click(vegaImageUploader, { action: 'cancel' }); //Cancel upload of imageawait userForVega.click(vegaImageUploader, { action: 'preview' }); //Preview uploaded imageV13 userForVega.click(vegaImageUploader, undefined, { action: 'replace', file: file }); //Replace imageuserForVega.click(vegaImageUploader, undefined, { action: 'delete' }); //Remove uploaded imageuserForVega.click(vegaImageUploader, undefined, { action: 'cancel' }); //Cancel upload of imageuserForVega.click(vegaImageUploader, undefined, { action: 'preview' }); //Preview uploaded image上传: 模拟用户上传文件到图像上传器 用法示例: V14 await userForVega.upload(vegaImageUploader, imageFile); //Upload imageV13 userForVega.upload(vegaImageUploader, imageFile); //Upload image |
| 虚拟输入 | 清除: 模拟用户清除输入值 用法示例: V14 await userForVega.clear(vegaInput, { iconClear: true }); // Clear input field by clicking the clear iconawait userForVega.clear(vegaInput); // Clear input field by userEvent.clearV13 userForVega.clear(vegaInput, { iconClear: true }); // Clear input field by clicking the clear iconuserForVega.clear(vegaInput); // Clear input field by userEvent.clear单击: 模拟用户点击输入 用法示例: V14 await userForVega.click(vegaInput); // will click the input boxV13 userForVega.click(vegaInput); // will click the input box类型:模拟用户输入文本 用法示例: V14 await userForVega.type(vegaInput, 'Hello World'); // will type 'Hello World' in the input boxV13 userForVega.type(vegaInput, 'Hello World'); // will type 'Hello World' in the input box |
| 虚拟输入-信用卡 | 清除:模拟用户清除信用卡输入值 用法示例: V14 await userForVega.clear(vegaInputCreditCard); // Clear input field by userEvent.clearV13 userForVega.clear(vegaInputCreditCard); // Clear input field by userEvent.clear单击:模拟用户点击信用卡输入 用法示例: V14 await userForVega.click(vegaInputCreditCard); // Click input field by userEvent.clickV13 userForVega.click(vegaInputCreditCard); // Click input field by userEvent.click类型:模拟用户将文本输入信用卡输入 用法示例: V14 await userForVega.type(vegaInputCreditCard, '1234'); // Type into input field by userEvent.typeV13 userForVega.type(vegaInputCreditCard, '1234'); // Type into input field by userEvent.type |
| 虚拟输入-数字 | 清除: 模拟用户清除数字输入值 用法示例: V14 await userForVega.clear(vegaInputNumeric, { iconClear: true }); // Clear input field by clicking the clear iconawait userForVega.clear(vegaInputNumeric); // Clear input field by userEvent.clearV13 userForVega.clear(vegaInputNumeric, { iconClear: true }); // Clear input field by clicking the clear iconuserForVega.clear(vegaInputNumeric); // Clear input field by userEvent.clear单击: 模拟用户点击数字输入 用法示例: V14 await userForVega.click(vegaInputNumeric); // will click the input boxV13 userForVega.click(vegaInputNumeric); // will click the input box类型: 模拟用户将文本输入数字输入 用法示例: V14 await userForVega.type(vegaInputNumeric, '12345'); // will type '12345' in the input boxV13 userForVega.type(vegaInputNumeric, '12345'); // will type '12345' in the input box |
| 维加-输入-电话号码 | 清除:模拟用户清除电话号码输入值 用法示例: V14 await userForVega.clear(vegaInputPhoneNumber); // Clear input field with userEvent clear methodawait userForVega.clear(vegaInputPhoneNumber, { source: 'input' }); // Clear input field with userEvent clear methodawait userForVega.clear(vegaInputPhoneNumber, { source: 'dropDown' }); // Clear drop down input field with userEvent clear methodawait userForVega.clear(vegaInputPhoneNumber, { iconClear: true }); // Clear input field with clear icon buttonawait userForVega.clear(vegaInputPhoneNumber, { source: 'dropDown', iconClear: true }); // Clear drop down input field with clear icon buttonV13 userForVega.clear(vegaInputPhoneNumber); // Clear input field with userEvent clear methoduserForVega.clear(vegaInputPhoneNumber, { source: 'input' }); // Clear input field with userEvent clear methoduserForVega.clear(vegaInputPhoneNumber, { source: 'dropDown' }); // Clear drop down input field with userEvent clear methoduserForVega.clear(vegaInputPhoneNumber, { iconClear: true }); // Clear input field with clear icon buttonuserForVega.clear(vegaInputPhoneNumber, { source: 'dropDown', iconClear: true }); // Clear drop down input field with clear icon button选择选项: 模拟用户从选中选项 用法示例: V14 await userForVega.selectOptions(vegaInputPhoneNumber, 'key', {keyOrLabel: 'key'}); // Select option by key using userEvent.clickawait userForVega.selectOptions(vegaInputPhoneNumber, 'label', {keyOrLabel: 'label'}); // Select option by label using userEvent.clickV13 userForVega.selectOptions(vegaInputPhoneNumber, 'key', {keyOrLabel: 'key'}); // Select option by key using userEvent.clickuserForVega.selectOptions(vegaInputPhoneNumber, 'label', {keyOrLabel: 'label'}); // Select option by label using userEvent.click类型: 模拟用户将文本输入电话号码输入 用法示例: V14 await userForVega.type(vegaInputPhoneNumber, '123', {source: 'input'}); // Type into input field or dropdown input field using userEvent.typeV13 userForVega.type(vegaInputPhoneNumber, '123', {source: 'input', delay: 0}); // Type into input field or dropdown input field using userEvent.type |
| 输入范围 | 清除: 模拟用户清除范围输入值 用法示例: V14 await userForVega.clear(vegaInputRange); // Clear minimum input field using userEvent.clear (keyboard action)await userForVega.clear(vegaInputRange, {minOrMax: 'min'}); // Clear minimum input field using userEvent.clear (keyboard action)await userForVega.clear(vegaInputRange, {minOrMax: 'max'}); // Clear maximum input field using userEvent.clear (keyboard action)await userForVega.clear(vegaInputRange, {iconClear: true}); // Clear both fields (min and max) using the clear iconV13 userForVega.clear(vegaInputRange); // Clear minimum input field using userEvent.clear (keyboard action)userForVega.clear(vegaInputRange, {minOrMax: 'min'}); // Clear minimum input field using userEvent.clear (keyboard action)userForVega.clear(vegaInputRange, {minOrMax: 'max'}); // Clear maximum input field using userEvent.clear (keyboard action)userForVega.clear(vegaInputRange, {iconClear: true}); // Clear both fields (min and max) using the clear icon单击: 模拟点击范围输入的用户 用法示例: V14 await userForVega.click(vegaInputRange, {minOrMax: 'min'}); // will click the minimum input boxawait userForVega.click(vegaInputRange, {minOrMax: 'max'}); // will click the maximum input boxV13 userForVega.click(vegaInputRange, undefined, {minOrMax: 'max'}); // will click the maximum input box类型: 模拟用户将文本输入范围输入 用法示例: V14 await userForVega.type(vegaInputRange, '10', {minOrMax: 'min'}); // will type '10' in the minimum input boxawait userForVega.type(vegaInputRange, '10', {minOrMax: 'max'}); // will type '10' in the maximum input boxV13 userForVega.type(vegaInputRange, '10', {minOrMax: 'min', delay: 0}); // will type '10' in the minimum input boxuserForVega.type(vegaInputRange, '10', {minOrMax: 'max', delay: 0}); // will type '10' in the maximum input box |
| 虚拟输入选择 | 取消选择选项: 模拟用户从多选项中取消选择选项 用法示例: V14 await userForVega.deselectOptions(vegaInputSelect, ['key', 'key1', ...], {keyOrLabel: 'key'}); // will deselect the option with specified keyawait userForVega.deselectOptions(vegaInputSelect, ['label', 'label1', ...], {keyOrLabel: 'label'}); // will deselect the option with specified labelV13 userForVega.deselectOptions(vegaInputSelect, ['key', 'key1', ...], {keyOrLabel: 'key'}); // will deselect the option with specified keyuserForVega.deselectOptions(vegaInputSelect, ['label', 'label1', ...], {keyOrLabel: 'label'}); // will deselect the option with specified label选择选项: 模拟用户从选中选项 用法示例: V14 await userForVega.selectOptions(vegaInputSelect, 'key', {keyOrLabel: 'key'}); // will select the option with specified keyawait userForVega.selectOptions(vegaInputSelect, ['label', 'label1', ...], {keyOrLabel: 'label'}); // will select the option with specified labelV13 userForVega.selectOptions(vegaInputSelect, 'label', {keyOrLabel: 'label'}); // will select the option with specified labeluserForVega.selectOptions(vegaInputSelect, ['key', 'key1', ...], {keyOrLabel: 'key'}); // will select the options with specified keys类型:模拟用户将文本输入到选定的输入中 用法示例: V14 await userForVega.type(vegaInputSelect, 'Peaches'); // will type 'text' in the input box and filter options by labelV13 userForVega.type(vegaInputSelect, 'Peaches'); // will type 'text' in the input box and filter options by label |
| viga- 对象切换 | 单击: 模拟用户点击项目切换 用法示例: V14 await userForVega.click(vegaItemToggle); // will click item toggleawait waitFor(() => { expect(vegaItemToggle.isToggled).toBe(true); }, { timeout: 1550 }); // wait for the toggle animation to finishV13 userForVega.click(vegaItemToggle); // will click item toggleawait waitFor(() => { expect(vegaItemToggle.isToggled).toBe(true); }, { timeout: 1550 }); // wait for the toggle animation to finish |
| vega- 左向导航组 | 单击: 模拟用户点击左侧导航组 用法示例: V14 await userForVega.click(vegaLeftNavGroup); //Click left nav groupV13 userForVega.click(vegaLeftNavGroup); //Click left nav group盘旋:模拟一个在左侧导航组上徘徊指针的用户 用法示例: V14 await userForVega.hover(vegaLeftNavGroup); //hover left nav groupV13 userForVega.hover(vegaLeftNavGroup); //hover left nav group卸载:模拟用户将指针从左侧导航组移出 用法示例: V14 await userForVega.unhover(vegaLeftNavGroup); //unhover left nav groupV13 userForVega.unhover(vegaLeftNavGroup); //unhover left nav group |
| vega-左向导航链接 | 单击: 模拟用户点击左侧导航链接 用法示例: V14 await userForVega.click(vegaLeftNavLink); //Click left nav linkV13 userForVega.click(vegaLeftNavLink); //Click left nav link盘旋:模拟用户在左向导航链接上徘徊指针 用法示例: V14 await userForVega.hover(vegaLeftNavLink); //hover left nav linkV13 userForVega.hover(vegaLeftNavLink); //hover left nav link卸载:模拟用户将指针移出左向导航链接 用法示例: V14 await userForVega.unhover(vegaLeftNavLink); //unhover left nav linkV13 userForVega.unhover(vegaLeftNavLink); //unhover left nav link |
| vega-左向导航区 | 单击:模拟用户点击左侧导航部分 用法示例: V14 await userForVega.click(vegaLeftNavSection); //Click left nav section action button link if action title is setV13 userForVega.click(vegaLeftNavSection); //Click left nav section action button link if action title is set盘旋: 模拟一个用户在左侧导航段盘旋指针 用法示例: V14 await userForVega.hover(vegaLeftNavSection); //hover left nav section action button link if action title is setV13 userForVega.hover(vegaLeftNavSection); //hover left nav section action button link if action title is set卸载: 模拟一个用户将指针移出左侧导航部分 用法示例: V14 await userForVega.unhover(vegaLeftNavSection); //unhover left nav sectionV13 userForVega.unhover(vegaLeftNavSection); //unhover left nav section |
| 虚拟模式 | 单击: 模拟用户点击模式 用法示例: V14 await userForVega.click(vegaModal); // will simulate click to open modalawait userForVega.click(vegaModal, { action: 'open' }); // will open modalawait userForVega.click(vegaModal, { action: 'close' }); // will close modalawait userForVega.click(vegaModal, { target: 'closeIcon' }); // On open modal, click close iconV13 userForVega.click(vegaModal); // will simulate click to open modaluserForVega.click(vegaModal, undefined, { action: 'open' }); // will open modaluserForVega.click(vegaModal, undefined, { action: 'close' }); // will close modaluserForVega.click(vegaModal, { target: 'closeIcon' }); // On open modal, click close icon |
| 虚拟导航卡 | 单击: 模拟点击导航卡的用户 用法示例: V14 await userForVega.click(vegaNavCard); //Click first vega-left-nav-link by defaultawait userForVega.click(vegaNavCard, { prop: 'key', propValue: 'settings' }); //Click nav item by key:'settings'await userForVega.click(vegaNavCard, { prop: 'url', propValue: '#settings' }); //Click nav item by urlawait userForVega.click(vegaNavCard, { prop: 'label', propValue: 'SETTINGS' }); //Click nav item by label textawait userForVega.click(vegaNavCard, { prop: 'label', propValue: 'Profile', targetType: 'group' }); //Click label for for group elementV13 userForVega.click(vegaNavCard); //Click first vega-left-nav-link by defaultuserForVega.click(vegaNavCard, undefined, { prop: 'key', propValue: 'settings' }); //Click nav item by key:'settings'userForVega.click(vegaNavCard, undefined, { prop: 'url', propValue: '#settings' }); //Click nav item by urluserForVega.click(vegaNavCard, undefined, { prop: 'label', propValue: 'SETTINGS' }); //Click nav item by label textuserForVega.click(vegaNavCard, undefined, { prop: 'label', propValue: 'Profile', targetType: 'group' }); //Click label for for group element |
| vega- 涂鸦 | 单击: 模拟用户点击页码 用法示例: V14 await userForVega.click(vegaPagination, { next: true }); // go to next pageawait userForVega.click(vegaPagination, { prev: true }); // go to previous pageawait userForVega.click(vegaPagination, { page: 5 }); // go to specific pageV13 userForVega.click(vegaPagination, undefined, { next: true }); // go to next pageuserForVega.click(vegaPagination, undefined, { prev: true }); // go to previous pageuserForVega.click(vegaPagination, undefined, { page: 5 }); // go to specific page选择选项: 模拟用户从选中选项 用法示例: V14 await waitFor(() => { expect(vegaPagination.shadowRoot.querySelector('vega-input-select').classList.contains('hydrated')).toBe(true); }); // wait for the inner input-select to be rendered.await userForVega.selectOptions(vegaPagination, '20'); // change page size to 20V13 await waitFor(() => { expect(vegaPagination.shadowRoot.querySelector('vega-input-select').classList.contains('hydrated')).toBe(true); }); // wait for the inner input-select to be rendered.userForVega.selectOptions(vegaPagination, '20'); // change page size to 20类型:模拟用户将文本输入到页码 用法示例: V14 await waitFor(() => { expect(vegaPagination.shadowRoot.querySelector('vega-input[data-vega-form="paginationGoTo"]').classList.contains('hydrated')).toBe(true); }); // wait for the inner vega-input to be rendered.await userForVega.type(vegaPagination, '5'); // type target page number and goTo that pageV13 await waitFor(() => { expect(vegaPagination.shadowRoot.querySelector('vega-input[data-vega-form="paginationGoTo"]').classList.contains('hydrated')).toBe(true); }); // wait for the inner vega-input to be rendered.userForVega.type(vegaPagination, '5'); // type target page number and goTo that page |
| 维加 - 流行 | 单击: 模拟用户点击弹出器 用法示例: V14 await userForVega.click(vegaPopover); // will click popover-content slot to open or close the popoverV13 userForVega.click(vegaPopover); // will click popover-content slot to open or close the popover盘旋:模拟用户在弹出器上徘徊指针 用法示例: V14 await userForVega.hover(vegaPopover); // will hover popover-content slot to open or close the popoverV13 userForVega.hover(vegaPopover); // will hover popover-content slot to open or close the popover卸载:模拟用户将指针移出弹出器 用法示例: V14 await userForVega.unhover(vegaPopover); // will unhover popover-content slot to open or close the popoverawait waitFor(() => { expect(vegaPopoverContent).toHaveClass('vega-force-hidden');}); // wait for the popover to be hiddenV13 userForVega.unhover(vegaPopover); // will unhover popover-content slot to open or close the popoverawait waitFor(() => { expect(vegaPopoverContent).toHaveClass('vega-force-hidden');}); // wait for the popover to be hidden |
| 维加无线电 | 单击: 模拟用户点击收音机 用法示例: V14 await userForVega.click(vegaRadio); // will click radioV13 userForVega.click(vegaRadio); // will click radio盘旋:模拟一个用户在收音机上徘徊指针 用法示例: V14 await userForVega.hover(vegaRadio); // will hover radioV13 userForVega.hover(vegaRadio); // will hover radio卸载:模拟一个用户将指针移出收音机 用法示例: V14 await userForVega.unhover(vegaRadio); // will unhover radioV13 userForVega.unhover(vegaRadio); // will unhover radio |
| 区域控制 | 单击: 模拟用户点击段控件 用法示例: V14 await userForVega.click(vegaSegmentControl, {value: 'Right', textOrIndexOrKey: 'text'}); // will click the right buttonawait userForVega.click(vegaSegmentControl, {value: 'Center', textOrIndexOrKey: 'text'}); // will click the center buttonawait userForVega.click(vegaSegmentControl, {value: 'left', textOrIndexOrKey: 'text'}); // will click the left buttonawait userForVega.click(vegaSegmentControl, {value: '1', textOrIndexOrKey: 'index'}); // will click the first button by indexawait userForVega.click(vegaSegmentControl, {value: 'right', textOrIndexOrKey: 'key'}); // will click the button with key 'right'await userForVega.click(vegaSegmentControl, {value: 'center', textOrIndexOrKey: 'key'}); // will click the button with key 'center'await userForVega.click(vegaSegmentControl, {value: 'left', textOrIndexOrKey: 'key'}); // will click the button with key 'left'V13 userForVega.click(vegaSegmentControl, undefined, {value: 'Right', textOrIndexOrKey: 'text'}); // will click the right buttonuserForVega.click(vegaSegmentControl, undefined, {value: 'Center', textOrIndexOrKey: 'text'}); // will click the center buttonuserForVega.click(vegaSegmentControl, undefined, {value: 'left', textOrIndexOrKey: 'text'}); // will click the left buttonuserForVega.click(vegaSegmentControl, undefined, {value: '1', textOrIndexOrKey: 'index'}); // will click the first button by indexuserForVega.click(vegaSegmentControl, undefined, {value: 'right', textOrIndexOrKey: 'key'}); // will click the button with key 'right'userForVega.click(vegaSegmentControl, undefined, {value: 'center', textOrIndexOrKey: 'key'}); // will click the button with key 'center'userForVega.click(vegaSegmentControl, undefined, {value: 'left', textOrIndexOrKey: 'key'}); // will click the button with key 'left' |
| 维加- 选择- 芯片 | 清除: 模拟用户清除选择芯片的值 用法示例: V14 await userForVega.clear(vegaSelectionChip); //clear selection chipV13 userForVega.clear(vegaSelectionChip); //clear selection chip单击: 模拟用户点击选择芯片 用法示例: V14 await userForVega.click(vegaSelectionChip); //click selection chipV13 userForVega.click(vegaSelectionChip); //click selection chip盘旋:模拟用户在选择芯片上徘徊指针 用法示例: V14 await userForVega.hover(vegaSelectionChip); //hover on selection chipV13 userForVega.hover(vegaSelectionChip); //hover on selection chip卸载:模拟用户将指针移出选择芯片 用法示例: V14 await userForVega.unhover(vegaSelectionChip); //unhover selection chipV13 userForVega.unhover(vegaSelectionChip); //unhover selection chip |
| vega - 选择- 芯片组 | 清除: 模拟用户清除选择芯片组的值 用法示例: V14 await userForVega.clear(vegaSelectionChipGroup); //clear group selectionV13 userForVega.clear(vegaSelectionChipGroup); //clear group selection单击: 模拟用户点击选择芯片组 用法示例: V14 await userForVega.click(vegaSelectionChipGroup, {label: 'Label for ABC'}); //Select by labelawait userForVega.click(vegaSelectionChipGroup, {label: ['Label for ABC', 'Label for DEF']}); //Multi selectawait userForVega.click(vegaSelectionChipGroup, {value: 'ABC'}); //Select by valueawait userForVega.click(vegaSelectionChipGroup, {value: ['ABC', 'DEF']}); //Multi selectV13 userForVega.click(vegaSelectionChipGroup, undefined, {label: 'Label for ABC'}); //Select by labeluserForVega.click(vegaSelectionChipGroup, undefined, {label: ['Label for ABC', 'Label for DEF']}); //Multi selectuserForVega.click(vegaSelectionChipGroup, undefined, {value: 'ABC'}); //Select by valueuserForVega.click(vegaSelectionChipGroup, undefined, {value: ['ABC', 'DEF']}); //Multi select |
| vega - 选择牌 | 清除: 模拟一个用户清除选择牌的值 用法示例: V14 await userForVega.clear(vegaSelectionTile); //Clear selectionV13 userForVega.clear(vegaSelectionTile); //Clear selection单击: 模拟用户点击所选牌 用法示例: V14 await userForVega.click(vegaSelectionTile); //Click selection tileV13 userForVega.click(vegaSelectionTile); //Click selection tile盘旋:模拟用户在选择的平板上徘徊指针 用法示例: V14 await userForVega.hover(vegaSelectionTile); //Hover on selection tileV13 userForVega.hover(vegaSelectionTile); //Hover on selection tile卸载:模拟一个用户将指针移出选择牌 用法示例: V14 await userForVega.unhover(vegaSelectionTile); //Unhover on selection tileV13 userForVega.unhover(vegaSelectionTile); //Unhover on selection tile |
| vega - 选择牌组 | 清除: 模拟用户清除选中的平板组的值 用法示例: V14 await userForVega.clear(vegaSelectionTileGroup); // Clear selected valuesV13 userForVega.clear(vegaSelectionTileGroup); // Clear selected values单击: 模拟用户点击所选的平板组 用法示例: V14 await userForVega.click(vegaSelectionTileGroup, {value: 'ABC'}); //Select by valueawait userForVega.click(vegaSelectionTileGroup, {value: ['ABC', 'DEF']}); //Select multiple optionsawait userForVega.click(vegaSelectionTileGroup, {title: 'Title for ABC'}); //Select by titleawait userForVega.click(vegaSelectionTileGroup, {title: ['Title ABC', 'Title DEF']}); //Select multiple optionsV13 userForVega.click(vegaSelectionTileGroup, undefined, {value: 'ABC'}); //Select by valueuserForVega.click(vegaSelectionTileGroup, undefined, {value: ['ABC', 'DEF']}); //Select multiple optionsuserForVega.click(vegaSelectionTileGroup, undefined, {title: 'Title for ABC'}); //Select by titleuserForVega.click(vegaSelectionTileGroup, undefined, {title: ['Title ABC', 'Title DEF']}); //Select multiple options |
| 维加签名-抓取 | 清除: 模拟用户清除签名抓取值 用法示例: V14 await userForVega.clear(vegaSignatureCapture); // Clear the signature captureV13 userForVega.clear(vegaSignatureCapture); // Clear the signature capture指针: 模拟指向签名抓取的用户 用法示例: V14 await userForVega.pointer(vegaSignatureCapture, [{ keys: '[MouseLeft>]', coords: { x: 100, y: 200 } },{ coords: { x: 200, y: 200 } },{ keys: '[/MouseLeft]' },]); // Draw a signatureV13 userForVega.pointer(vegaSignatureCapture, [{mouseDown: { clientX: 100, clientY: 200 }, mouseMove: { clientX: 200, clientY: 200 }, mouseUp: { clientX: 200, clientY: 200 },},]); // Draw a signature |
| vega 步进器 | 清除: 模拟用户清除阶梯值 用法示例: V14 await userForVega.clear(vegaStepper); // will clear the stepper input and set the value to 0V13 userForVega.clear(vegaStepper); // will clear the stepper input and set the value to 0单击: 模拟用户点击阶梯 用法示例: V14 await userForVega.click(vegaStepper, {actionSource: 'minus'}); // Decrease valueawait userForVega.click(vegaStepper, {actionSource: 'plus'}); // Increase valueawait userForVega.click(vegaStepper, {actionSource: 'input'}); // To focus on the inputV13 userForVega.click(vegaStepper, undefined, {actionSource: 'minus'}); // Decrease valueuserForVega.click(vegaStepper, undefined, {actionSource: 'plus'}); // Increase valueuserForVega.click(vegaStepper, undefined, {actionSource: 'input'}); // To focus on the input类型:模拟用户将文本输入到阶梯 用法示例: V14 await userForVega.type(vegaStepper, '10'); // will type '10' in the stepper inputV13 userForVega.type(vegaStepper, '10'); // will type '10' in the stepper input |
| 虚拟文本区域 | 清除: 模拟用户清除文本区域的值 用法示例: V14 await userForVega.clear(vegaTextarea); // Delete all textV13 userForVega.clear(vegaTextarea); // Delete all text单击: 模拟用户点击文本区域 用法示例: V14 await userForVega.click(vegaTextarea); // click textareaV13 userForVega.click(vegaTextarea); // click textarea类型:模拟用户将文本输入文本区域 用法示例: V14 await userForVega.type(vegaTextarea, 'text'); // will type 'text' in the textarea boxV13 userForVega.type(vegaTextarea, 'text'); // will type '12345' in the textarea box |
| 时间选择者 | 清除: 模拟用户清除取时器的值 用法示例: V14 await userForVega.clear(vegaTimePicker); // Clear start time inputawait userForVega.clear(vegaTimePicker, {startOrEnd: 'start'}); // Clear start time inputawait userForVega.clear(vegaTimePicker, {startOrEnd: 'end'}); // Clear end time inputV13 userForVega.clear(vegaTimePicker); // Clear start time inputuserForVega.clear(vegaTimePicker, {startOrEnd: 'start'}); // Clear start time inputuserForVega.clear(vegaTimePicker, {startOrEnd: 'end'}); // Clear end time input单击: 模拟点击取时器的用户 用法示例: V14 await userForVega.click(vegaTimePicker); // Click start time input fieldawait userForVega.click(vegaTimePicker, {startOrEnd: 'start'}); // Click start time input fieldawait userForVega.click(vegaTimePicker, {startOrEnd: 'end'}); // Click end time input fieldV13 userForVega.click(vegaTimePicker, undefined, {startOrEnd: 'start'}); // Click start time input fielduserForVega.click(vegaTimePicker, undefined, {startOrEnd: 'end'}); // Click end time input field类型:模拟用户将文本输入取时器 用法示例: V14 await userForVega.type(vegaTimePicker, '10:00'); // Type into start time input fieldawait userForVega.type(vegaTimePicker, '10:00', {startOrEnd: 'start'}); // Type into start time input fieldawait userForVega.type(vegaTimePicker, '11:15', {startOrEnd: 'end'}); // Type into end time input fieldV13 userForVega.type(vegaTimePicker, '10:00', {startOrEnd: 'start', delay: 0}); // Type into start time input fielduserForVega.type(vegaTimePicker, '10:00', {startOrEnd: 'end', delay: 0}); // Type into end time input field |
| 虚拟切换 | 单击: 模拟用户点击切换开关 用法示例: V14 await userForVega.click(vegaToggleSwitch); // will click toggle switchV13 userForVega.click(vegaToggleSwitch); // will click toggle switch |