-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat(recorder): display primary page URL in recorder title #34637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,29 +19,33 @@ import * as React from 'react'; | |
| import { Recorder } from './recorder'; | ||
| import './recorder.css'; | ||
|
|
||
| export const Main: React.FC = ({ | ||
| }) => { | ||
| export const Main: React.FC = ({}) => { | ||
| const [sources, setSources] = React.useState<Source[]>([]); | ||
| const [paused, setPaused] = React.useState(false); | ||
| const [log, setLog] = React.useState(new Map<string, CallLog>()); | ||
| const [mode, setMode] = React.useState<Mode>('none'); | ||
|
|
||
| window.playwrightSetMode = setMode; | ||
| window.playwrightSetSources = React.useCallback((sources: Source[]) => { | ||
| setSources(sources); | ||
| window.playwrightSourcesEchoForTest = sources; | ||
| React.useLayoutEffect(() => { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why blocking effect?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the way these side effects are supposed to be triggered in React (though ideally it would be |
||
| window.playwrightSetMode = setMode; | ||
| window.playwrightSetSources = (sources, primaryPageURL) => { | ||
| setSources(sources); | ||
| window.playwrightSourcesEchoForTest = sources; | ||
| document.title = primaryPageURL | ||
| ? `Playwright Inspector - ${primaryPageURL}` | ||
| : `Playwright Inspector`; | ||
| }; | ||
| window.playwrightSetPaused = setPaused; | ||
| window.playwrightUpdateLogs = callLogs => { | ||
| setLog(log => { | ||
| const newLog = new Map<string, CallLog>(log); | ||
| for (const callLog of callLogs) { | ||
| callLog.reveal = !log.has(callLog.id); | ||
| newLog.set(callLog.id, callLog); | ||
| } | ||
| return newLog; | ||
| }); | ||
| }; | ||
| }, []); | ||
| window.playwrightSetPaused = setPaused; | ||
| window.playwrightUpdateLogs = callLogs => { | ||
| setLog(log => { | ||
| const newLog = new Map<string, CallLog>(log); | ||
| for (const callLog of callLogs) { | ||
| callLog.reveal = !log.has(callLog.id); | ||
| newLog.set(callLog.id, callLog); | ||
| } | ||
| return newLog; | ||
| }); | ||
| }; | ||
|
|
||
| return <Recorder sources={sources} paused={paused} log={log} mode={mode} />; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /** | ||
| * Copyright (c) Microsoft Corporation. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { test, expect } from './inspectorTest'; | ||
|
|
||
| test('should reflect formatted URL of the page', async ({ | ||
| openRecorder, | ||
| server, | ||
| }) => { | ||
| const { recorder } = await openRecorder(); | ||
| await recorder.setContentAndWait(''); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| 'Playwright Inspector - about:blank', | ||
| ); | ||
|
|
||
| await recorder.setContentAndWait('', server.EMPTY_PAGE); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.EMPTY_PAGE}`, | ||
| ); | ||
| }); | ||
|
|
||
| test('should update primary page URL when original primary closes', async ({ | ||
| context, | ||
| openRecorder, | ||
| server, | ||
| }) => { | ||
| const { recorder } = await openRecorder(); | ||
| await recorder.setContentAndWait( | ||
| '', | ||
| `${server.PREFIX}/background-color.html`, | ||
| ); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/background-color.html`, | ||
| ); | ||
|
|
||
| const page2 = await context.newPage(); | ||
| await page2.goto(`${server.PREFIX}/empty.html`); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/background-color.html`, | ||
| ); | ||
|
|
||
| const page3 = await context.newPage(); | ||
| await page3.goto(`${server.PREFIX}/dom.html`); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/background-color.html`, | ||
| ); | ||
|
|
||
| const page4 = await context.newPage(); | ||
| await page4.goto(`${server.PREFIX}/grid.html`); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/background-color.html`, | ||
| ); | ||
|
|
||
| await page2.close(); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/background-color.html`, | ||
| ); | ||
|
|
||
| await recorder.page.close(); | ||
| // URL will not update without performing some action | ||
| await page3.getByRole('checkbox').click(); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/dom.html`, | ||
| ); | ||
|
|
||
| await page3.close(); | ||
| await expect(recorder.recorderPage).toHaveTitle( | ||
| `Playwright Inspector - ${server.PREFIX}/grid.html`, | ||
| ); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.