Repository navigation
Let libraries trace and record adopted contexts the way New Context does #5326
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
a362031
1c19439
ccb951e
6da0ee2
0c42907
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 |
|---|---|---|
|
|
@@ -707,7 +707,8 @@ class RecordHar(TypedDict, total=False): | |
| `omitContent`: Optional setting to control whether to omit request content | ||
| from the HAR. Default is False | ||
|
|
||
| `path`: Path on the filesystem to write the HAR file to. | ||
| `path`: Path on the filesystem to write the HAR file to. A relative path is | ||
| relative to the output directory. | ||
|
|
||
| Example: | ||
| | ${har} = Create Dictionary path=/path/to/har.file omitContent=True | ||
|
|
@@ -718,6 +719,21 @@ class RecordHar(TypedDict, total=False): | |
| path: str | ||
|
|
||
|
|
||
| class AdoptedContextOptions(TypedDict): | ||
| """Tracing and recording options of a context that a JavaScript extension | ||
| creates and hands over with ``adoptContext``, as ``adopted_context_options`` | ||
| returns them. ``None`` means off. | ||
|
|
||
| The keys are named like the options they are meant for, so that they can be | ||
| passed on to the extension function as keyword arguments. | ||
| """ | ||
|
|
||
| tracing: str | None | ||
| recordVideo: dict[str, Any] | None | ||
|
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
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. Because of
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. I agree with your suggestion. I will merge this PR and send time on fixing few other minor things in the same go. |
||
| recordHar: dict[str, Any] | None | ||
| tracesDir: str | ||
|
|
||
|
|
||
| class _HttpCredentials(TypedDict): | ||
| username: str | Secret | ||
| password: str | Secret | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from pathlib import Path | ||
|
|
||
| from robot.api.deco import keyword | ||
|
|
||
| from Browser import Browser | ||
| from Browser.utils.data_types import RecordVideo | ||
|
|
||
|
|
||
| class AdoptingLibrary(Browser): | ||
| @keyword | ||
| def open_adopted_context_with_recording( | ||
| self, | ||
| user_data_dir: str, | ||
| url: str, | ||
| headless: bool, | ||
| tracing: Path, | ||
| record_video: RecordVideo, | ||
| ) -> str: | ||
| """Opens a persistent context in the JavaScript extension with the options of | ||
| ``adopted_context_options``, registers it with ``register_adopted_context`` | ||
| and returns the path of its video.""" | ||
| options = self.adopted_context_options( | ||
| tracing=tracing, recordVideo=record_video | ||
| ) | ||
| adopted = self.call_js_keyword( | ||
| "openAdoptedPersistentContextWithRecording", | ||
| userDataDir=user_data_dir, | ||
| url=url, | ||
| headless=headless, | ||
| **options, | ||
| ) | ||
| return self.register_adopted_context( | ||
| adopted["contextId"], options, adopted["videoPath"] | ||
| ) |
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.
When Browser launches a browser, it sets
tracesDirto a unique folder under${OUTPUT_DIR}/browser/traces/temp(_set_browser_options), and Browser removes these temporary trace files. The options here do not includetracesDir, so when an extension launches its own browser or Electron app with tracing, the temporary trace files end up outside that folder. Couldadopted_context_optionsreturntracesDirtoo, so that the extension can pass it to the launch?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.
Done. The options include
tracesDir, a new folder underbrowser/traces/temp, asNew Browseruses for the browsers it launches, and the docstring says to pass it to the launch. The Electron library passes it to_electron.launch, and the new acceptance test passes it tolaunchPersistentContext.