diff --git a/index.js b/index.js index 0bce8a7abc..4b9607bba4 100644 --- a/index.js +++ b/index.js @@ -14,5 +14,4 @@ * limitations under the License. */ -const { setUnderTest } = require('./lib/utils/utils'); module.exports = require('./lib/inprocess'); diff --git a/src/dispatchers/dispatcher.ts b/src/dispatchers/dispatcher.ts index eb9cfe9586..c3e1a56c8b 100644 --- a/src/dispatchers/dispatcher.ts +++ b/src/dispatchers/dispatcher.ts @@ -214,6 +214,7 @@ export class DispatcherConnection { this.onmessage({ id, result: this._replaceDispatchersWithGuids(result) }); } catch (e) { // Dispatching error + callMetadata.error = e.message; if (callMetadata.log.length) rewriteErrorMessage(e, e.message + formatLogRecording(callMetadata.log) + kLoggingNote); this.onmessage({ id, error: serializeError(e) }); diff --git a/src/server/browserContext.ts b/src/server/browserContext.ts index 6bf085489b..2b0f52f9db 100644 --- a/src/server/browserContext.ts +++ b/src/server/browserContext.ts @@ -345,8 +345,8 @@ export abstract class BrowserContext extends SdkObject { } } - async extendInjectedScript(source: string) { - const installInFrame = (frame: frames.Frame) => frame.extendInjectedScript(source).catch(e => {}); + async extendInjectedScript(source: string, arg?: any) { + const installInFrame = (frame: frames.Frame) => frame.extendInjectedScript(source, arg).catch(() => {}); const installInPage = (page: Page) => { page.on(Page.Events.InternalFrameNavigatedToNewDocument, installInFrame); return Promise.all(page.frames().map(installInFrame)); diff --git a/src/server/instrumentation.ts b/src/server/instrumentation.ts index 2b63c06e68..5544d779df 100644 --- a/src/server/instrumentation.ts +++ b/src/server/instrumentation.ts @@ -39,7 +39,7 @@ export type CallMetadata = { params: any; stack?: StackFrame[]; log: string[]; - error?: Error; + error?: string; point?: Point; }; diff --git a/src/server/supplements/injected/recorder.ts b/src/server/supplements/injected/recorder.ts index c4313eeac6..80bde3de35 100644 --- a/src/server/supplements/injected/recorder.ts +++ b/src/server/supplements/injected/recorder.ts @@ -51,8 +51,10 @@ export class Recorder { private _actionPointElement: HTMLElement; private _actionPoint: Point | undefined; private _actionSelector: string | undefined; + private _params: { isUnderTest: boolean; }; - constructor(injectedScript: InjectedScript) { + constructor(injectedScript: InjectedScript, params: { isUnderTest: boolean }) { + this._params = params; this._injectedScript = injectedScript; this._outerGlassPaneElement = html` { + await page.setContent(''); + const scriptPromise = (async () => { + await page.pause(); + await page.click('button'); + })(); + const recorderPage = await recorderPageGetter(); + const source = await recorderPage.textContent('.source-line-paused'); + expect(source).toContain('page.pause();'); + + await recorderPage.click('[title="Step over"]'); + await recorderPage.waitForSelector('.source-line-paused :has-text("page.click")'); + + await recorderPage.click('[title=Resume]'); + await scriptPromise; + }); + + it('should highlight pointer', async ({page, recorderPageGetter}) => { + await page.setContent(''); + const scriptPromise = (async () => { + await page.pause(); + await page.click('button'); + })(); + const recorderPage = await recorderPageGetter(); + await recorderPage.click('[title="Step over"]'); + + const point = await page.waitForSelector('x-pw-action-point'); + const button = await page.waitForSelector('button'); + const box1 = await button.boundingBox(); + const box2 = await point.boundingBox(); + + const x1 = box1.x + box1.width / 2; + const y1 = box1.y + box1.height / 2; + const x2 = box2.x + box2.width / 2; + const y2 = box2.y + box2.height / 2; + + expect(Math.abs(x1 - x2) < 2).toBeTruthy(); + expect(Math.abs(y1 - y2) < 2).toBeTruthy(); + + await recorderPage.click('[title="Step over"]'); + await scriptPromise; }); }); diff --git a/test/recorder.fixtures.ts b/test/recorder.fixtures.ts index 7e690653d7..952a5c2296 100644 --- a/test/recorder.fixtures.ts +++ b/test/recorder.fixtures.ts @@ -15,25 +15,21 @@ */ import { folio as baseFolio } from './fixtures'; -import { internalCallMetadata } from '../lib/server/instrumentation'; +import { Page } from '..'; +import { chromium } from '../index'; const fixtures = baseFolio.extend<{ - recorderFrame: () => Promise, - recorderClick: (selector: string) => Promise + recorderPageGetter: () => Promise, }>(); -fixtures.recorderFrame.init(async ({context, toImpl}, runTest) => { +fixtures.recorderPageGetter.init(async ({context, toImpl}, runTest) => { await runTest(async () => { while (!toImpl(context).recorderAppForTest) await new Promise(f => setTimeout(f, 100)); - return toImpl(context).recorderAppForTest._page.mainFrame(); - }); -}); - -fixtures.recorderClick.init(async ({ recorderFrame }, runTest) => { - await runTest(async (selector: string) => { - const frame = await recorderFrame(); - await frame.click(internalCallMetadata(), selector, {}); + const wsEndpoint = toImpl(context).recorderAppForTest.wsEndpoint; + const browser = await chromium.connectOverCDP({ wsEndpoint }); + const c = browser.contexts()[0]; + return c.pages()[0] || await c.waitForEvent('page'); }); });