Skip to content

Commit

Permalink
chore: send aria snapshot to the debug controller (#33969)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman authored Dec 12, 2024
1 parent 0e2b984 commit 29fd2df
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/playwright-core/src/protocol/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ scheme.DebugControllerInitializer = tOptional(tObject({}));
scheme.DebugControllerInspectRequestedEvent = tObject({
selector: tString,
locator: tString,
ariaSnapshot: tString,
});
scheme.DebugControllerSetModeRequestedEvent = tObject({
mode: tString,
Expand Down
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/debugController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class InspectingRecorderApp extends EmptyRecorderApp {

override async elementPicked(elementInfo: ElementInfo): Promise<void> {
const locator: string = asLocator(this._debugController._sdkLanguage, elementInfo.selector);
this._debugController.emit(DebugController.Events.InspectRequested, { selector: elementInfo.selector, locator });
this._debugController.emit(DebugController.Events.InspectRequested, { selector: elementInfo.selector, locator, ariaSnapshot: elementInfo.ariaSnapshot });
}

override async setSources(sources: Source[]): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export class DebugControllerDispatcher extends Dispatcher<DebugController, chann
eventsHelper.addEventListener(this._object, DebugController.Events.StateChanged, params => {
this._dispatchEvent('stateChanged', params);
}),
eventsHelper.addEventListener(this._object, DebugController.Events.InspectRequested, ({ selector, locator }) => {
this._dispatchEvent('inspectRequested', { selector, locator });
eventsHelper.addEventListener(this._object, DebugController.Events.InspectRequested, ({ selector, locator, ariaSnapshot }) => {
this._dispatchEvent('inspectRequested', { selector, locator, ariaSnapshot });
}),
eventsHelper.addEventListener(this._object, DebugController.Events.SourceChanged, ({ text, header, footer, actions }) => {
this._dispatchEvent('sourceChanged', ({ text, header, footer, actions }));
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/src/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,7 @@ export interface DebugControllerChannel extends DebugControllerEventTarget, Chan
export type DebugControllerInspectRequestedEvent = {
selector: string,
locator: string,
ariaSnapshot: string,
};
export type DebugControllerSetModeRequestedEvent = {
mode: string,
Expand Down
1 change: 1 addition & 0 deletions packages/protocol/src/protocol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ DebugController:
parameters:
selector: string
locator: string
ariaSnapshot: string

setModeRequested:
parameters:
Expand Down
2 changes: 2 additions & 0 deletions tests/library/debug-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ test('should pick element', async ({ backend, connectedBrowser }) => {

expect(events).toEqual([
{
ariaSnapshot: '- button "Submit"',
selector: 'internal:role=button[name=\"Submit\"i]',
locator: 'getByRole(\'button\', { name: \'Submit\' })',
}, {
ariaSnapshot: '- button "Submit"',
selector: 'internal:role=button[name=\"Submit\"i]',
locator: 'getByRole(\'button\', { name: \'Submit\' })',
},
Expand Down

0 comments on commit 29fd2df

Please sign in to comment.