From 8a00f17b6850da661bb0c15d976c164e2b322af5 Mon Sep 17 00:00:00 2001 From: Martin Feckie Date: Fri, 30 Aug 2024 09:12:54 +0800 Subject: [PATCH 1/4] Fix typo --- test/api/page_test.exs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/page_test.exs b/test/api/page_test.exs index bdae066..1206d8c 100644 --- a/test/api/page_test.exs +++ b/test/api/page_test.exs @@ -441,7 +441,7 @@ defmodule Playwright.PageTest do end end - describe "Page.test_content/2" do + describe "Page.text_content/2" do test "retrieves content", %{assets: assets, page: page} do page |> Page.goto(assets.prefix <> "/dom.html") From 5ae1f727a28c25f63a709ab122e61b9b33f4c157 Mon Sep 17 00:00:00 2001 From: Martin Feckie Date: Fri, 30 Aug 2024 09:15:04 +0800 Subject: [PATCH 2/4] Add test for `.content` --- test/api/page_test.exs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/api/page_test.exs b/test/api/page_test.exs index 1206d8c..d539f4d 100644 --- a/test/api/page_test.exs +++ b/test/api/page_test.exs @@ -450,6 +450,16 @@ defmodule Playwright.PageTest do end end + describe "Page.content/0" do + test "retrieves the page content", %{assets: assets, page: page} do + page + |> Page.goto(assets.prefix <> "/dom.html") + + assert Page.content(page) =~ + ~r// + end + end + describe "Page.title/1" do test "retrieves the title text", %{assets: assets, page: page} do page From 23920e806d6d73254abecf810d6b4f844467a240 Mon Sep 17 00:00:00 2001 From: Martin Feckie Date: Fri, 30 Aug 2024 09:21:35 +0800 Subject: [PATCH 3/4] Add support for `.content` to Page and Frame --- lib/playwright/frame.ex | 12 ++++++++++-- lib/playwright/page.ex | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/playwright/frame.ex b/lib/playwright/frame.ex index 8d526c8..e635054 100644 --- a/lib/playwright/frame.ex +++ b/lib/playwright/frame.ex @@ -127,8 +127,16 @@ defmodule Playwright.Frame do # --- - # @spec content(Frame.t()) :: binary() - # def content(frame) + @spec content(Frame.t()) :: binary() | {:error, term()} + def content(%Frame{session: session} = frame) do + case Channel.post(session, {:guid, frame.guid}, :content) do + {:error, error} -> + {:error, error} + + content -> + content + end + end # --- diff --git a/lib/playwright/page.ex b/lib/playwright/page.ex index b8b34f6..a99b262 100644 --- a/lib/playwright/page.ex +++ b/lib/playwright/page.ex @@ -243,6 +243,11 @@ defmodule Playwright.Page do Channel.find(session, {:guid, page.parent.guid}) end + @spec content(t()) :: binary() + def content(%Page{} = page) do + main_frame(page) |> Frame.content() + end + @doc """ A shortcut for the main frame's `Playwright.Frame.dblclick/3`. """ From bf7a47a0af17c7b52758cd52721f8d54706241ed Mon Sep 17 00:00:00 2001 From: Martin Feckie Date: Fri, 30 Aug 2024 09:27:09 +0800 Subject: [PATCH 4/4] Update spec --- lib/playwright/page.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/playwright/page.ex b/lib/playwright/page.ex index a99b262..0d27158 100644 --- a/lib/playwright/page.ex +++ b/lib/playwright/page.ex @@ -243,7 +243,7 @@ defmodule Playwright.Page do Channel.find(session, {:guid, page.parent.guid}) end - @spec content(t()) :: binary() + @spec content(t()) :: binary() | {:error, term()} def content(%Page{} = page) do main_frame(page) |> Frame.content() end