Skip to content

Commit

Permalink
Fixes Locator.wait_for support for waiting for hidden state elements
Browse files Browse the repository at this point in the history
  • Loading branch information
ry4n1m3 committed Aug 20, 2024
1 parent 778e0f4 commit bdda4ee
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/playwright/locator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1325,11 +1325,11 @@ defmodule Playwright.Locator do
@spec wait_for(t(), options()) :: t() | {:error, Channel.Error.t()}
def wait_for(%Locator{} = locator, options \\ %{}) do
case Frame.wait_for_selector(locator.frame, locator.selector, options) do
%ElementHandle{} ->
locator

{:error, _} = error ->
error

_ ->
locator
end
end

Expand Down
16 changes: 16 additions & 0 deletions test/api/locator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,22 @@ defmodule Playwright.LocatorTest do
assert [:ok, %Locator{}] = Task.await_many([setup, check])
end

test "on success with nil return (i.e., a match is found in time) returns the `Locator` instance", %{page: page} do
locator = Locator.new(page, "div > span")

setup =
Task.async(fn ->
Page.set_content(page, "<div><span style='visibility: hidden;'>target</span></div>")
end)

check =
Task.async(fn ->
Locator.wait_for(locator, %{timeout: 100, state: "hidden"})
end)

assert [:ok, %Locator{}] = Task.await_many([setup, check])
end

test "on failure (i.e., the timeout is reached) returns an `{:error, error}` tuple", %{page: page} do
locator = Locator.new(page, "div > span")

Expand Down

0 comments on commit bdda4ee

Please sign in to comment.