@@ -641,6 +641,57 @@ defmodule Playwright.LocatorTest do
641641 end
642642 end
643643
644+ describe "Locator.or_/2" do
645+ test "returns a locator that matches either given condition" , % { page: page } do
646+ page
647+ |> Page . set_content ( """
648+ <section>
649+ <div class="pink">pink</div>
650+ <div class="orange">orange</div>
651+ <div class="green">green</div>
652+ </section>
653+ """ )
654+
655+ pink = Page . locator ( page , ".pink" )
656+ orange = Page . locator ( page , ".orange" )
657+ redish = Locator . or_ ( pink , orange )
658+ assert Locator . text_content ( redish ) == "pink"
659+
660+ page
661+ |> Page . set_content ( """
662+ <section>
663+ <div class="orange">orange</div>
664+ <div class="green">green</div>
665+ </section>
666+ """ )
667+
668+ pink = Page . locator ( page , ".pink" )
669+ orange = Page . locator ( page , ".orange" )
670+ redish = Locator . or_ ( pink , orange )
671+
672+ assert Locator . text_content ( redish ) == "orange"
673+ end
674+
675+ test "raises an error when the given locators don't share a frame" , % { page: page , browser: browser } do
676+ other_page = Playwright.Browser . new_page ( browser )
677+
678+ on_exit ( :ok , fn ->
679+ Playwright.Page . close ( other_page )
680+ end )
681+ page
682+ |> Page . set_content ( "<div></div>" )
683+
684+ div_locator = Page . locator ( page , "div" )
685+ other_page
686+ |> Page . set_content ( "<span></span>" )
687+ span_locator = Page . locator ( other_page , "span" )
688+
689+ assert_raise ArgumentError , "Locators must belong to the same frame" , fn ->
690+ Locator . or_ ( div_locator , span_locator )
691+ end
692+ end
693+ end
694+
644695 describe "Locator.press/2" do
645696 test "focuses an element and 'presses' a key within it" , % { page: page } do
646697 locator = Page . locator ( page , "input" )
0 commit comments