Skip to content

Commit

Permalink
API: scaffold "tracing"
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyti committed Oct 6, 2024
1 parent f4c9f7a commit acc143f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
4 changes: 4 additions & 0 deletions lib/playwright/artifact.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
defmodule Playwright.Artifact do
@moduledoc false
use Playwright.SDK.ChannelOwner
end
19 changes: 10 additions & 9 deletions lib/playwright/browser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,19 @@ defmodule Playwright.Browser do

# ---

# test_chromium_tracing.py
# @spec start_tracing(t(), Page.t(), options()) :: :ok
# def start_tracing(browser, page \\ nil, options \\ %{})
@type opts_tracing :: map()

# test_chromium_tracing.py
# @spec stop_tracing(t()) :: binary()
# def stop_tracing(browser)
@spec start_tracing(t(), Page.t(), opts_tracing()) :: t() | {:error, Error.t()}
def start_tracing(browser, page \\ nil, options \\ %{})

# @spec version(BrowserContext.t()) :: binary
# def version(browser)
def start_tracing(%Browser{} = browser, _page, _options) do
Channel.post({browser, :start_tracing})
end

# ---
@spec stop_tracing(t()) :: binary()
def stop_tracing(%Browser{} = browser) do
Channel.post({browser, :stop_tracing})
end

# events
# ----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ defmodule Playwright.MixProject do
Playwright.APIRequest,
Playwright.APIRequestContext,
Playwright.APIResponse,
Playwright.Artifact,
Playwright.Browser,
Playwright.BrowserContext,
Playwright.BrowserType,
Expand Down
21 changes: 21 additions & 0 deletions test/api/browser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,28 @@ defmodule Playwright.BrowserTest do
end
end

describe "Browser.start_tracing/3" do
test "on success, returns the 'subject' `Browser`", %{browser: browser} do
assert %Browser{} = Browser.start_tracing(browser)
Browser.stop_tracing(browser)
end

test "on failure, returns `{:error, error}`", %{browser: browser} do
browser = %{browser | guid: "bogus"}
assert {:error, %Error{type: "TargetClosedError"}} = Browser.start_tracing(browser)
end
end

describe "Browser.stop_tracing/1" do
test "on success, returns the resultant `Artifact`", %{browser: browser} do
Browser.start_tracing(browser)
assert %Playwright.Artifact{} = Browser.stop_tracing(browser)
end

test "on failure, returns `{:error, error}`", %{browser: browser} do
Browser.start_tracing(browser)
browser = %{browser | guid: "bogus"}
assert {:error, %Error{type: "TargetClosedError"}} = Browser.start_tracing(browser)
end
end
end
1 change: 1 addition & 0 deletions test/api/tracing_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# test_chromium_tracing.py

0 comments on commit acc143f

Please sign in to comment.