-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore: add _browserTypes helpers to playwright #34611
Conversation
packages/playwright/src/index.ts
Outdated
for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit, playwright._bidiChromium, playwright._bidiFirefox]) | ||
(browserType as any)._defaultLaunchOptions = options; | ||
for (const browserType of playwright._browserTypes()) | ||
browserType._defaultLaunchOptions = options; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these to playwright
right away!
packages/playwright/src/index.ts
Outdated
contexts.push(...(browserType as any)._contexts); | ||
const pages = contexts.map(ctx => ctx.pages()).flat(); | ||
await Promise.all(pages.map(page => this._screenshotPage(page, false))); | ||
await Promise.all(this._playwright._allPages().map(page => this._screenshotPage(page, false))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about places like this one: https://github.com/microsoft/playwright/blob/main/packages/playwright/src/index.ts#L625?
This comment has been minimized.
This comment has been minimized.
packages/playwright/src/index.ts
Outdated
(browserType as any)._defaultContextNavigationTimeout = navigationTimeout || 0; | ||
|
||
for (const browserType of playwright._browserTypes()) { | ||
browserType._defaultContextOptions = _combinedContextOptions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well move these to Playwright
.
packages/playwright/src/index.ts
Outdated
(playwright.request as any)._defaultContextOptions = { ..._combinedContextOptions }; | ||
(playwright.request as any)._defaultContextOptions.tracesDir = tracing().tracesDir(); | ||
(playwright.request as any)._defaultContextOptions.timeout = actionTimeout || 0; | ||
playwright.request._defaultContextOptions = { ..._combinedContextOptions }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
@@ -47,7 +47,7 @@ export type FetchOptions = { | |||
|
|||
type NewContextOptions = Omit<channels.PlaywrightNewRequestOptions, 'extraHTTPHeaders' | 'clientCertificates' | 'storageState' | 'tracesDir'> & { | |||
extraHTTPHeaders?: Headers, | |||
storageState?: string | StorageState, | |||
storageState?: string | SetStorageState, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unrelated, please move it into some IndexedDB pr instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's related! NewContextOptions
is for writing, so it needs to use SetStorageState
. This should've been fixed earlier, but was always covered because we had all these (... as any)
s in the code.
@@ -73,4 +82,16 @@ export class Playwright extends ChannelOwner<channels.PlaywrightChannel> { | |||
static from(channel: channels.PlaywrightChannel): Playwright { | |||
return (channel as any)._object; | |||
} | |||
|
|||
_browserTypes(): BrowserType[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at least for the lines below - I made it private for now.
const launchOptions: channels.BrowserTypeLaunchParams = { | ||
...options, | ||
tracesDir: options.tracesDir ?? this._playwright._defaultTracesDir, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better update options
variable at line 67 with the new tracesDir
instead of changing launchOptions
, because options
is later used at line 77 and so we want all the values there be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I moved tracesDir
back into _defaultLaunchOptions
, things should be good now.
assert(!(options as any).port, 'Cannot specify a port without launching as a server.'); | ||
options = { ...this._defaultLaunchOptions, ...this._defaultContextOptions, ...options }; | ||
options = { ...this._playwright._defaultLaunchOptions, ...this._playwright._defaultContextOptions, ...options }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tracesDir
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've moved tracesDir back into _defaultLaunchOptions
, so it should work now
@@ -81,13 +83,11 @@ const playwrightFixtures: Fixtures<TestFixtures, WorkerFixtures> = ({ | |||
options.headless = headless; | |||
if (channel !== undefined) | |||
options.channel = channel; | |||
options.tracesDir = tracing().tracesDir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that _browserOptions
is also used for connect, and we are now missing tracesDir
there. Perhaps it was not the best idea to plumb it separately, sorry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tangled tracesDir
back into _defaultLaunchOptions
:D Hoping that works.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with just a single comment.
packages/playwright/src/index.ts
Outdated
for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit, playwright._bidiChromium, playwright._bidiFirefox]) | ||
(browserType as any)._defaultLaunchOptions = options; | ||
playwright._defaultLaunchOptions = options; | ||
playwright._defaultLaunchOptions.tracesDir = tracing().tracesDir(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this makes options
exposed in the next line missing the tracesDir
😄
This comment has been minimized.
This comment has been minimized.
Test results for "tests 1"1 failed 7 flaky37814 passed, 655 skipped Merge workflow run. |
There's a couple of spots throughout the client where we iterate through all browser types and pages. This PR extract some logic onto
Playwright
. This came up earlier today, while discussing with Dima. We already have similar logic on the Playwright server side.