Packages
playwright
0.1.17-preview-1
1.49.1-alpha.2
1.49.1-alpha.1
1.44.0-alpha.4
1.44.0-alpha.3
1.44.0-alpha.2
1.44.0-alpha.1
1.18.0-alpha.1
0.1.17-preview-7
0.1.17-preview-6
0.1.17-preview-5
0.1.17-preview-4
0.1.17-preview-3
0.1.17-preview-2
0.1.17-preview-1
0.1.16-preview-3
0.1.16-preview-2
0.1.16-preview-1
0.1.1-preview
0.1.0-preview
Playwright is an Elixir library to automate Chromium, Firefox and WebKit browsers with a single API. Playwright delivers automation that is ever-green, capable, reliable and fast.
Current section
Files
Jump to
Current section
Files
lib/playwright/locator/macros.ex
defmodule Playwright.Locator.Macros do
@moduledoc false
# NOTE: need to DRY these once patterns emerge.
defmacro def_locator(name, method) do
quote do
@spec unquote(name)(Playwright.Locator.t(), Playwright.Locator.options()) ::
:ok | {:error, Playwright.Runner.Channel.Error.t()}
def unquote(name)(locator, options \\ %{}) do
case Playwright.Runner.Channel.post(
locator.frame,
unquote(method),
Map.merge(options, %{selector: locator.selector})
) do
{:ok, %{id: _id}} -> :ok
{:ok, %{guid: _id}} -> :ok
{:ok, value} -> {:ok, value}
{:error, error} -> {:error, error}
end
end
end
end
defmacro def_locator(name, method, arguments) do
quote do
@spec unquote(name)(Playwright.Locator.t(), unquote(arguments)) ::
:ok | {:error, Playwright.Runner.Channel.Error.t()}
def unquote(name)(locator, options \\ %{}) do
case Playwright.Runner.Channel.post(
locator.frame,
unquote(method),
Map.merge(options, %{selector: locator.selector})
) do
{:ok, %{id: _id}} -> :ok
{:ok, %{guid: _id}} -> :ok
{:ok, value} -> {:ok, value}
{:error, error} -> {:error, error}
end
end
end
end
end