Skip to content

Commit

Permalink
Merge pull request #61 from mfeckie/support-page-content
Browse files Browse the repository at this point in the history
Support page content
  • Loading branch information
coreyti authored Sep 26, 2024
2 parents bdda4ee + bf7a47a commit ba27dea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/playwright/frame.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

# ---

Expand Down
5 changes: 5 additions & 0 deletions lib/playwright/page.ex
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ defmodule Playwright.Page do
Channel.find(session, {:guid, page.parent.guid})
end

@spec content(t()) :: binary() | {:error, term()}
def content(%Page{} = page) do
main_frame(page) |> Frame.content()
end

@doc """
A shortcut for the main frame's `Playwright.Frame.dblclick/3`.
"""
Expand Down
12 changes: 11 additions & 1 deletion test/api/page_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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/<html>/
end
end

describe "Page.title/1" do
test "retrieves the title text", %{assets: assets, page: page} do
page
Expand Down

0 comments on commit ba27dea

Please sign in to comment.