Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ async function handleGetByRole(
browser: BrowserManager
): Promise<Response> {
const page = browser.getPage();
const locator = page.getByRole(command.role as any, { name: command.name });
const locator = page.getByRole(command.role as any, { name: command.name, exact: command.exact });

switch (command.subaction) {
case 'click':
Expand Down Expand Up @@ -927,7 +927,7 @@ async function handleGetByLabel(
browser: BrowserManager
): Promise<Response> {
const page = browser.getPage();
const locator = page.getByLabel(command.label);
const locator = page.getByLabel(command.label, { exact: command.exact });

switch (command.subaction) {
case 'click':
Expand All @@ -947,7 +947,7 @@ async function handleGetByPlaceholder(
browser: BrowserManager
): Promise<Response> {
const page = browser.getPage();
const locator = page.getByPlaceholder(command.placeholder);
const locator = page.getByPlaceholder(command.placeholder, { exact: command.exact });

switch (command.subaction) {
case 'click':
Expand Down
51 changes: 51 additions & 0 deletions src/protocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,23 @@ describe('parseCommand', () => {
expect(result.success).toBe(true);
});

it('should parse getbyrole with exact', () => {
const result = parseCommand(
cmd({
id: '1',
action: 'getbyrole',
role: 'button',
name: 'Continue',
subaction: 'click',
exact: true,
})
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.exact).toBe(true);
}
});

it('should parse getbytext', () => {
const result = parseCommand(
cmd({
Expand All @@ -388,6 +405,40 @@ describe('parseCommand', () => {
);
expect(result.success).toBe(true);
});

it('should parse getbylabel with exact', () => {
const result = parseCommand(
cmd({
id: '1',
action: 'getbylabel',
label: 'Email',
subaction: 'fill',
value: 'test@test.com',
exact: true,
})
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.exact).toBe(true);
}
});

it('should parse getbyplaceholder with exact', () => {
const result = parseCommand(
cmd({
id: '1',
action: 'getbyplaceholder',
placeholder: 'Search',
subaction: 'fill',
value: 'test',
exact: true,
})
);
expect(result.success).toBe(true);
if (result.success) {
expect(result.command.exact).toBe(true);
}
});
});

describe('tabs', () => {
Expand Down
3 changes: 3 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const getByRoleSchema = baseCommandSchema.extend({
action: z.literal('getbyrole'),
role: z.string().min(1),
name: z.string().optional(),
exact: z.boolean().optional(),
subaction: z.enum(['click', 'fill', 'check', 'hover']),
value: z.string().optional(),
});
Expand All @@ -140,13 +141,15 @@ const getByTextSchema = baseCommandSchema.extend({
const getByLabelSchema = baseCommandSchema.extend({
action: z.literal('getbylabel'),
label: z.string().min(1),
exact: z.boolean().optional(),
subaction: z.enum(['click', 'fill', 'check']),
value: z.string().optional(),
});

const getByPlaceholderSchema = baseCommandSchema.extend({
action: z.literal('getbyplaceholder'),
placeholder: z.string().min(1),
exact: z.boolean().optional(),
subaction: z.enum(['click', 'fill']),
value: z.string().optional(),
});
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface GetByRoleCommand extends BaseCommand {
action: 'getbyrole';
role: string;
name?: string;
exact?: boolean;
subaction: 'click' | 'fill' | 'check' | 'hover';
value?: string;
}
Expand All @@ -122,13 +123,15 @@ export interface GetByTextCommand extends BaseCommand {
export interface GetByLabelCommand extends BaseCommand {
action: 'getbylabel';
label: string;
exact?: boolean;
subaction: 'click' | 'fill' | 'check';
value?: string;
}

export interface GetByPlaceholderCommand extends BaseCommand {
action: 'getbyplaceholder';
placeholder: string;
exact?: boolean;
subaction: 'click' | 'fill';
value?: string;
}
Expand Down