Repository navigation
Let libraries built on Browser hand over their own BrowserContext #5318
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3d4c8e5
feat: let JavaScript extensions adopt a context they created
d-biehl e77ffd2
fix: wait for the browser of a closed persistent or adopted context
d-biehl 8a5c4ec
docs: adoptContext takes app.context() of an Electron app
d-biehl 1d0ffbb
feat: adoptContext takes options and sets the library timeout
d-biehl 86d4609
test: import only the variables in the adopt context suite
d-biehl ec98f0e
feat: adoptContext takes tracing and contextOptions
d-biehl 6032943
feat: let JavaScript extensions take the library timeout as defaultTi…
d-biehl 43b35d4
fix: pass null and undefined values of injected extension arguments on
d-biehl a6acf22
docs: adoptContext takes an absolute trace path
d-biehl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| let adoptedContextClosed = false; | ||
| let onCloseCalled = false; | ||
|
|
||
| async function openAdoptedPersistentContext(userDataDir, url, headless, playwright, adoptContext, defaultTimeout) { | ||
| const context = await playwright.chromium.launchPersistentContext(userDataDir, { | ||
| headless: String(headless).toLowerCase() !== 'false', | ||
| }); | ||
| context.setDefaultTimeout(defaultTimeout); | ||
| context.on('close', () => (adoptedContextClosed = true)); | ||
| await context.pages()[0].goto(url); | ||
| return adoptContext(context, { | ||
| onClose: async () => { | ||
| onCloseCalled = true; | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| async function openAdoptedPersistentContextWithTracingAndDownloads(userDataDir, url, headless, tracing, playwright, adoptContext) { | ||
| const contextOptions = { acceptDownloads: true }; | ||
| const context = await playwright.chromium.launchPersistentContext(userDataDir, { | ||
| headless: String(headless).toLowerCase() !== 'false', | ||
| ...contextOptions, | ||
| }); | ||
| await context.pages()[0].goto(url); | ||
| return adoptContext(context, { tracing, contextOptions }); | ||
| } | ||
|
|
||
| async function millisecondsUntilAWaitFails(page) { | ||
| const start = Date.now(); | ||
| try { | ||
| await page.waitForSelector('#not-on-the-page'); | ||
| } catch { | ||
| return Date.now() - start; | ||
| } | ||
| return -1; | ||
| } | ||
|
|
||
| async function adoptedContextIsClosed() { | ||
| return adoptedContextClosed; | ||
| } | ||
|
|
||
| async function adoptedContextOnCloseWasCalled() { | ||
| return onCloseCalled; | ||
| } | ||
|
|
||
| exports.__esModule = true; | ||
| exports.openAdoptedPersistentContext = openAdoptedPersistentContext; | ||
| exports.openAdoptedPersistentContextWithTracingAndDownloads = openAdoptedPersistentContextWithTracingAndDownloads; | ||
| exports.millisecondsUntilAWaitFails = millisecondsUntilAWaitFails; | ||
| exports.adoptedContextIsClosed = adoptedContextIsClosed; | ||
| exports.adoptedContextOnCloseWasCalled = adoptedContextOnCloseWasCalled; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| *** Settings *** | ||
| Library Browser jsextension=${CURDIR}/adopt.js | ||
| Library OperatingSystem | ||
| Resource ../variables.resource | ||
|
|
||
| Test Tags no-iframe | ||
|
|
||
| *** Test Cases *** | ||
| Browser Keywords Work On A Context Adopted By A JavaScript Extension | ||
| ${adopted} = Open Adopted Persistent Context ${OUTPUT_DIR}/adopted-profile ${LOGIN_URL} ${HEADLESS} | ||
| Get Browser Ids ACTIVE contains ${adopted}[browserId] | ||
| Get Browser Catalog validate [b["type"] for b in value if b["id"] == "${adopted}[browserId]"] == ["adopted"] | ||
| Get Text h1 == Login Page | ||
| Close Browser | ||
| ${closed} = Adopted Context Is Closed | ||
| Should Be True ${closed} | ||
| ${on_close_called} = Adopted Context On Close Was Called | ||
| Should Be True ${on_close_called} | ||
|
|
||
| An Extension Gives An Adopted Context The Library Timeout | ||
| Set Browser Timeout 1s scope=Test | ||
| Open Adopted Persistent Context ${OUTPUT_DIR}/adopted-profile-timeout ${LOGIN_URL} ${HEADLESS} | ||
| ${elapsed} = Milliseconds Until A Wait Fails | ||
| Should Be True ${elapsed} < 5000 | ||
| [Teardown] Close Browser | ||
|
|
||
| An Adopted Context Is Traced And Accepts Downloads | ||
| Open Adopted Persistent Context With Tracing And Downloads | ||
| ... ${OUTPUT_DIR}/adopted-profile-traced ${LOGIN_URL} ${HEADLESS} ${OUTPUT_DIR}/adopted-trace.zip | ||
| ${download_url} = Get Property id=file_download href | ||
| ${download} = Download ${download_url} | ||
| File Should Exist ${download}[saveAs] | ||
| Close Browser | ||
| File Should Exist ${OUTPUT_DIR}/adopted-trace.zip |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.