diff --git a/docs/api/README.md b/docs/api/README.md index 6faa45ca..5cbd2005 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -323,7 +323,7 @@ limitations under the License. #### Defined in -[Runner.ts:172](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L172) +[Runner.ts:61](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L61) --- diff --git a/docs/api/classes/PuppeteerRunnerExtension.md b/docs/api/classes/PuppeteerRunnerExtension.md index d7c8ddd6..8eb9f6e9 100644 --- a/docs/api/classes/PuppeteerRunnerExtension.md +++ b/docs/api/classes/PuppeteerRunnerExtension.md @@ -53,13 +53,13 @@ ### afterAllSteps -▸ `Optional` **afterAllSteps**(`flow?`): `Promise`<`void`\> +▸ `Optional` **afterAllSteps**(`flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -77,14 +77,14 @@ ### afterEachStep -▸ `Optional` **afterEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **afterEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -102,13 +102,13 @@ ### beforeAllSteps -▸ `Optional` **beforeAllSteps**(`flow?`): `Promise`<`void`\> +▸ `Optional` **beforeAllSteps**(`flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -126,14 +126,14 @@ ### beforeEachStep -▸ `Optional` **beforeEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **beforeEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -151,14 +151,14 @@ ### runStep -▸ **runStep**(`step`, `flow?`): `Promise`<`void`\> +▸ **runStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns diff --git a/docs/api/classes/PuppeteerRunnerOwningBrowserExtension.md b/docs/api/classes/PuppeteerRunnerOwningBrowserExtension.md index 4073da6d..7a7ffe84 100644 --- a/docs/api/classes/PuppeteerRunnerOwningBrowserExtension.md +++ b/docs/api/classes/PuppeteerRunnerOwningBrowserExtension.md @@ -67,14 +67,14 @@ ### afterEachStep -▸ `Optional` **afterEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **afterEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -92,13 +92,13 @@ ### beforeAllSteps -▸ `Optional` **beforeAllSteps**(`flow?`): `Promise`<`void`\> +▸ `Optional` **beforeAllSteps**(`flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -116,14 +116,14 @@ ### beforeEachStep -▸ `Optional` **beforeEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **beforeEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -141,14 +141,14 @@ ### runStep -▸ **runStep**(`step`, `flow?`): `Promise`<`void`\> +▸ **runStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns diff --git a/docs/api/classes/Runner.md b/docs/api/classes/Runner.md index 75c6f977..c64b836d 100644 --- a/docs/api/classes/Runner.md +++ b/docs/api/classes/Runner.md @@ -7,19 +7,7 @@ ### Methods - [abort](Runner.md#abort) -- [change](Runner.md#change) -- [click](Runner.md#click) -- [close](Runner.md#close) -- [doubleClick](Runner.md#doubleclick) -- [emulateNetworkConditions](Runner.md#emulatenetworkconditions) -- [hover](Runner.md#hover) -- [keyDown](Runner.md#keydown) -- [keyUp](Runner.md#keyup) -- [navigate](Runner.md#navigate) - [run](Runner.md#run) -- [runStep](Runner.md#runstep) -- [scroll](Runner.md#scroll) -- [setViewport](Runner.md#setviewport) ## Methods @@ -33,187 +21,7 @@ #### Defined in -[Runner.ts:58](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L58) - ---- - -### change - -▸ **change**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :-------------------------------------------------------------------- | -| `step` | `Omit`<[`ChangeStep`](../interfaces/Schema.ChangeStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:117](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L117) - ---- - -### click - -▸ **click**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------ | -| `step` | `Omit`<[`ClickStep`](../interfaces/Schema.ClickStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:66](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L66) - ---- - -### close - -▸ **close**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------ | -| `step` | `Omit`<[`CloseStep`](../interfaces/Schema.CloseStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:101](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L101) - ---- - -### doubleClick - -▸ **doubleClick**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------------------ | -| `step` | `Omit`<[`DoubleClickStep`](../interfaces/Schema.DoubleClickStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:124](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L124) - ---- - -### emulateNetworkConditions - -▸ **emulateNetworkConditions**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :-------------------------------------------------------------------------------------------------------- | -| `step` | `Omit`<[`EmulateNetworkConditionsStep`](../interfaces/Schema.EmulateNetworkConditionsStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:108](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L108) - ---- - -### hover - -▸ **hover**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------ | -| `step` | `Omit`<[`HoverStep`](../interfaces/Schema.HoverStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:73](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L73) - ---- - -### keyDown - -▸ **keyDown**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :---------------------------------------------------------------------- | -| `step` | `Omit`<[`KeyDownStep`](../interfaces/Schema.KeyDownStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:80](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L80) - ---- - -### keyUp - -▸ **keyUp**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------ | -| `step` | `Omit`<[`KeyUpStep`](../interfaces/Schema.KeyUpStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:87](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L87) - ---- - -### navigate - -▸ **navigate**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------------ | -| `step` | `Omit`<[`NavigateStep`](../interfaces/Schema.NavigateStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:131](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L131) +[Runner.ts:34](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L34) --- @@ -231,64 +39,4 @@ whether all the steps are run or the execution is aborted #### Defined in -[Runner.ts:149](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L149) - ---- - -### runStep - -▸ **runStep**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :---------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:62](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L62) - ---- - -### scroll - -▸ **scroll**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :----------------------------------------------------------------- | -| `step` | `Omit`<[`ScrollStep`](../modules/Schema.md#scrollstep), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:138](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L138) - ---- - -### setViewport - -▸ **setViewport**(`step`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :----- | :------------------------------------------------------------------------------ | -| `step` | `Omit`<[`SetViewportStep`](../interfaces/Schema.SetViewportStep.md), `"type"`\> | - -#### Returns - -`Promise`<`void`\> - -#### Defined in - -[Runner.ts:94](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L94) +[Runner.ts:42](https://github.com/puppeteer/replay/blob/main/src/Runner.ts#L42) diff --git a/docs/api/classes/RunnerExtension.md b/docs/api/classes/RunnerExtension.md index bc6f9350..f34ee5cc 100644 --- a/docs/api/classes/RunnerExtension.md +++ b/docs/api/classes/RunnerExtension.md @@ -32,13 +32,13 @@ ### afterAllSteps -▸ `Optional` **afterAllSteps**(`flow?`): `Promise`<`void`\> +▸ `Optional` **afterAllSteps**(`flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -52,14 +52,14 @@ ### afterEachStep -▸ `Optional` **afterEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **afterEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -73,13 +73,13 @@ ### beforeAllSteps -▸ `Optional` **beforeAllSteps**(`flow?`): `Promise`<`void`\> +▸ `Optional` **beforeAllSteps**(`flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -93,14 +93,14 @@ ### beforeEachStep -▸ `Optional` **beforeEachStep**(`step`, `flow?`): `Promise`<`void`\> +▸ `Optional` **beforeEachStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns @@ -114,14 +114,14 @@ ### runStep -▸ **runStep**(`step`, `flow?`): `Promise`<`void`\> +▸ **runStep**(`step`, `flow`): `Promise`<`void`\> #### Parameters -| Name | Type | -| :------ | :--------------------------------------------- | -| `step` | [`Step`](../modules/Schema.md#step) | -| `flow?` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | +| Name | Type | +| :----- | :--------------------------------------------- | +| `step` | [`Step`](../modules/Schema.md#step) | +| `flow` | [`UserFlow`](../interfaces/Schema.UserFlow.md) | #### Returns diff --git a/src/Runner.ts b/src/Runner.ts index 6bb4819d..bb1fffc2 100644 --- a/src/Runner.ts +++ b/src/Runner.ts @@ -16,21 +16,7 @@ import { PuppeteerRunnerOwningBrowserExtension } from './PuppeteerRunnerExtension.js'; import { RunnerExtension } from './RunnerExtension.js'; -import { - UserFlow, - Step, - ClickStep, - SetViewportStep, - KeyDownStep, - KeyUpStep, - HoverStep, - CloseStep, - EmulateNetworkConditionsStep, - ChangeStep, - DoubleClickStep, - NavigateStep, - ScrollStep, -} from './Schema.js'; +import { UserFlow, Step } from './Schema.js'; async function _runStepWithHooks( extension: RunnerExtension, @@ -63,85 +49,6 @@ export class Runner { await _runStepWithHooks(this.#extension, step); } - async click(step: Omit): Promise { - await this.runStep({ - type: 'click', - ...step, - }); - } - - async hover(step: Omit): Promise { - await this.runStep({ - type: 'hover', - ...step, - }); - } - - async keyDown(step: Omit): Promise { - await this.runStep({ - type: 'keyDown', - ...step, - }); - } - - async keyUp(step: Omit): Promise { - await this.runStep({ - type: 'keyUp', - ...step, - }); - } - - async setViewport(step: Omit): Promise { - await this.runStep({ - type: 'setViewport', - ...step, - }); - } - - async close(step: Omit): Promise { - await this.runStep({ - type: 'close', - ...step, - }); - } - - async emulateNetworkConditions( - step: Omit - ): Promise { - await this.runStep({ - type: 'emulateNetworkConditions', - ...step, - }); - } - - async change(step: Omit): Promise { - await this.runStep({ - type: 'change', - ...step, - }); - } - - async doubleClick(step: Omit): Promise { - await this.runStep({ - type: 'doubleClick', - ...step, - }); - } - - async navigate(step: Omit): Promise { - await this.runStep({ - type: 'navigate', - ...step, - }); - } - - async scroll(step: Omit): Promise { - await this.#extension.runStep({ - type: 'scroll', - ...step, - }); - } - /** * Run all the steps in the flow * @returns whether all the steps are run or the execution is aborted diff --git a/test/runner.test.ts b/test/runner.test.ts index d917642b..c1cbe977 100644 --- a/test/runner.test.ts +++ b/test/runner.test.ts @@ -946,18 +946,19 @@ describe('Runner', () => { }, new PuppeteerRunnerExtension(browser, page) ); - await runner.navigate({ + await runner.runStep({ + type: StepType.Navigate as const, url: `${HTTP_PREFIX}/main.html`, assertedEvents: [ { title: '', - type: 'navigation', + type: AssertedEventType.Navigation, url: `${HTTP_PREFIX}/main.html`, }, ], }); - await runner.hover({ - target: 'main', + await runner.runStep({ + type: StepType.Hover as const, selectors: [['#hover-button']], }); assert.ok(