Add `include_shadow=` argument to `Get Page Source`

オープン
#5,502 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
78/100
issue の種類
機能追加
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
playwright, python, typescript

調査の方向性

Read Browser/keywords/getters.py and trace Get Page Source through protobuf/playwright.proto, node/playwright-wrapper/grpc-service.ts, and node/playwright-wrapper/getters.ts. Add the named include_shadow option with a default of False, and check that it reaches Playwright's page.content() call. Add coverage in atest/test/02_Content_Keywords/basic_getters.robot and a focused wrapper test; done means open shadow content appears only when enabled and existing output stays unchanged by default.

索引モデルが issue の本文から書いたものです。

説明

Use case

Get Page Source returns the page HTML from page.content(). Elements inside a shadow root are not in it: a web component appears as an empty host element. For pages built from web components (Lit, Stencil, Shoelace, Salesforce Lightning and similar) the page source is then nearly empty, so asserting on it, or saving it to debug a failure, shows little.

Playwright 1.64 added includeShadow to page.content(). With it, open shadow roots are written as declarative shadow DOM, <template shadowrootmode="open"> inside the host element. Closed shadow roots are never included.

Proposed keyword / arguments

Get Page Source assertion_operator=None assertion_expected=None message=None * include_shadow=False

  • include_shadow: named-only, defaults to False. When True, the content of open shadow roots is included as <template shadowrootmode="open"> elements inside their hosts. Closed shadow roots are never included.
*** Test Cases ***
Page Source Shows Web Component Content
    New Page    ${WEB_COMPONENT_URL}
    Get Page Source    not contains    Inside Shadow DOM
    Get Page Source    contains    <template shadowrootmode="open">    include_shadow=True
    Get Page Source    contains    Inside Shadow DOM    include_shadow=True

Playwright API

Checked with Playwright 1.65.0 and Chromium: an open root comes out as <div id="host"><template shadowrootmode="open"><b>in shadow</b></template></div>, a closed root as an empty <div id="closed"></div>, and without the option the open host is empty too.

Implementation notes

All references are to upstream main (5e350998).

  • protobuf/playwright.proto:596: rpc GetPageSource(Request.Empty) becomes rpc GetPageSource(Request.Bool). Request.Bool (:421-423) already exists and is used for similar single flags (SetOffline, GetConsoleLog). Still one Playwright call per rpc.
  • node/playwright-wrapper/grpc-service.ts:296-305 getPageSource: take pb.Request_Bool and pass request.value on.
  • node/playwright-wrapper/getters.ts:380-381 getPageSource(page): add the flag and call page.content({ includeShadow }). The chunking that follows (:383-394) stays as is.
  • Browser/keywords/getters.py:189-227 get_page_source: add *, include_shadow: bool = False after message, send Request().Bool(value=include_shadow) at :215, and document the argument, including that closed shadow roots are never included. The docstring also points to Get Property outerHTML for one element (:206-209); that does not include shadow content, which is worth one sentence.
  • Tests: atest/test/02_Content_Keywords/basic_getters.robot:181-182 has the plain Get Page Source case. Add one against node/dynamic-test-app/static/webcomponent.html, which attaches an open shadow root with the heading "Inside Shadow DOM" (:24-30): that text is missing by default and present with include_shadow=True. There is no Jest test for getPageSource in node/playwright-wrapper/__tests__/ today; a small one that mocks page.content and checks the option is passed is enough.

Backwards compatibility

Additive, named-only argument with a default that keeps today's output. The proto request type changes, but the rpc is internal to the library.

主要言語
Python
スター
662
フォーク
149
平均マージ
6時間 13分
マージ済み PR(30日)
121

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

MarketSquare/robotframework-browser のほかの issue

MarketSquare/robotframework-browser の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。