|
| 1 | +// Type definitions for cypress-cdp 1.3 |
| 2 | +// Project: https://github.com/bahmutov/cypress-cdp#readme |
| 3 | +// Definitions by: Anthony Froissant <https://github.com/froissant> |
| 4 | +// Louis Loiseau-Billon <https://github.com/LouisLoiseau> |
| 5 | +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped |
| 6 | + |
| 7 | +/// <reference types="cypress" /> |
| 8 | + |
| 9 | +import type Protocol from 'devtools-protocol/types/protocol'; |
| 10 | +import type ProtocolMapping from 'devtools-protocol/types/protocol-mapping'; |
| 11 | + |
| 12 | +declare global { |
| 13 | + // Augment the Cypress namespace to include type definitions for cypress-cdp. |
| 14 | + namespace Cypress { |
| 15 | + namespace CDP { |
| 16 | + //#region CDP |
| 17 | + type RdpCommands = ProtocolMapping.Commands; |
| 18 | + type RdpCommandNames = keyof RdpCommands; |
| 19 | + |
| 20 | + type CdpCommandFnParams<RdpCommandName extends RdpCommandNames> = |
| 21 | + RdpCommands[RdpCommandName]['paramsType'][number] extends never |
| 22 | + ? Record<string, never> |
| 23 | + : RdpCommands[RdpCommandName]['paramsType'][number]; |
| 24 | + type CdpCommandFnReturnType<RdpCommandName extends RdpCommandNames> = |
| 25 | + RdpCommands[RdpCommandName]['returnType']; |
| 26 | + interface CdpCommandFnOptions { |
| 27 | + log: LogConfig; |
| 28 | + } |
| 29 | + type CdpCommandFn = <RdpCommandName extends RdpCommandNames>( |
| 30 | + rdpCommand: RdpCommandName, |
| 31 | + params: CdpCommandFnParams<RdpCommandName>, |
| 32 | + options?: CdpCommandFnOptions, |
| 33 | + ) => Chainable<CdpCommandFnReturnType<RdpCommandName>>; |
| 34 | + //#endregion |
| 35 | + |
| 36 | + //#region getCDPNodeId |
| 37 | + type getCDPNodeIdFn = (selector: string) => Chainable<number>; |
| 38 | + //#endregion |
| 39 | + |
| 40 | + //#region hasEventListeners |
| 41 | + interface hasEventListenersFnOptions { |
| 42 | + log: LogConfig; |
| 43 | + type: string; |
| 44 | + } |
| 45 | + type hasEventListenersFn = ( |
| 46 | + selector: string, |
| 47 | + options?: hasEventListenersFnOptions, |
| 48 | + ) => Chainable<Protocol.DOMDebugger.GetEventListenersResponse>; |
| 49 | + //#endregion |
| 50 | + } |
| 51 | + |
| 52 | + interface Chainable<Subject = any> { |
| 53 | + /** |
| 54 | + * Custom command to send a RDP command to Chrome DevTools. |
| 55 | + * @example |
| 56 | + * const selector = 'button#one' |
| 57 | + * cy.CDP('Runtime.evaluate', { |
| 58 | + * expression: 'frames[0].document.querySelector("' + selector + '")', |
| 59 | + * }).should((v) => { |
| 60 | + * expect(v.result).to.have.property('objectId') |
| 61 | + * }) |
| 62 | + */ |
| 63 | + CDP: CDP.CdpCommandFn; |
| 64 | + |
| 65 | + /** |
| 66 | + * Custom command to return the internal element's Node Id that can be used to query the run-time properties, for example the rendered font. |
| 67 | + * @example |
| 68 | + * cy.getCDPNodeId('body').then((nodeId) => { |
| 69 | + * cy.CDP('CSS.getPlatformFontsForNode', { |
| 70 | + * nodeId |
| 71 | + * }); |
| 72 | + * }); |
| 73 | + */ |
| 74 | + getCDPNodeId: CDP.getCDPNodeIdFn; |
| 75 | + |
| 76 | + /** |
| 77 | + * Custom command to get listeners attached to a DOM element. |
| 78 | + * @example |
| 79 | + * cy.hasEventListeners('button#one') |
| 80 | + * @example |
| 81 | + * cy.hasEventListeners('button#one', { type: 'click' }) |
| 82 | + */ |
| 83 | + hasEventListeners: CDP.hasEventListenersFn; |
| 84 | + } |
| 85 | + } |
| 86 | +} |
0 commit comments