Skip to content

Commit cd14696

Browse files
authored
feat(roll): roll Playwright 1.18.0-next-1636539685000 (microsoft#1021)
1 parent b5ef624 commit cd14696

File tree

6 files changed

+211
-20
lines changed

6 files changed

+211
-20
lines changed

playwright/_impl/_locator.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def locator(
168168
return Locator(self._frame, f"{self._selector} >> {selector}")
169169

170170
def frame_locator(self, selector: str) -> "FrameLocator":
171-
return FrameLocator(self._frame, selector)
171+
return FrameLocator(self._frame, self._selector + " >> " + selector)
172172

173173
async def element_handle(
174174
self,
@@ -477,14 +477,29 @@ async def set_checked(
477477

478478

479479
class FrameLocator:
480-
def __init__(self, frame: "Frame", selector: str) -> None:
480+
def __init__(self, frame: "Frame", frame_selector: str) -> None:
481481
self._frame = frame
482482
self._loop = frame._loop
483483
self._dispatcher_fiber = frame._connection._dispatcher_fiber
484-
self._selector = f"{selector} >> control=enter-frame"
484+
self._frame_selector = frame_selector
485485

486486
def locator(self, selector: str) -> Locator:
487-
return Locator(self._frame, f"{self._selector} >> {selector}")
487+
return Locator(
488+
self._frame, f"{self._frame_selector} >> control=enter-frame >> {selector}"
489+
)
488490

489491
def frame_locator(self, selector: str) -> "FrameLocator":
490-
return FrameLocator(self._frame, f"{self._selector} >> {selector}")
492+
return FrameLocator(
493+
self._frame, f"{self._frame_selector} >> control=enter-frame >> {selector}"
494+
)
495+
496+
@property
497+
def first(self) -> "FrameLocator":
498+
return FrameLocator(self._frame, f"{self._frame_selector} >> nth=0")
499+
500+
@property
501+
def last(self) -> "FrameLocator":
502+
return FrameLocator(self._frame, f"{self._frame_selector} >> nth=-1")
503+
504+
def nth(self, index: int) -> "FrameLocator":
505+
return FrameLocator(self._frame, f"{self._frame_selector} >> nth={index}")

playwright/async_api/_generated.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5221,6 +5221,30 @@ async def set_checked(
52215221

52225222

52235223
class FrameLocator(AsyncBase):
5224+
@property
5225+
def first(self) -> "FrameLocator":
5226+
"""FrameLocator.first
5227+
5228+
Returns locator to the first matching frame.
5229+
5230+
Returns
5231+
-------
5232+
FrameLocator
5233+
"""
5234+
return mapping.from_impl(self._impl_obj.first)
5235+
5236+
@property
5237+
def last(self) -> "FrameLocator":
5238+
"""FrameLocator.last
5239+
5240+
Returns locator to the last matching frame.
5241+
5242+
Returns
5243+
-------
5244+
FrameLocator
5245+
"""
5246+
return mapping.from_impl(self._impl_obj.last)
5247+
52245248
def locator(self, selector: str) -> "Locator":
52255249
"""FrameLocator.locator
52265250

@@ -5256,6 +5280,22 @@ def frame_locator(self, selector: str) -> "FrameLocator":
52565280

52575281
return mapping.from_impl(self._impl_obj.frame_locator(selector=selector))
52585282

5283+
def nth(self, index: int) -> "FrameLocator":
5284+
"""FrameLocator.nth
5285+
5286+
Returns locator to the n-th matching frame.
5287+
5288+
Parameters
5289+
----------
5290+
index : int
5291+
5292+
Returns
5293+
-------
5294+
FrameLocator
5295+
"""
5296+
5297+
return mapping.from_impl(self._impl_obj.nth(index=index))
5298+
52595299

52605300
mapping.register(FrameLocatorImpl, FrameLocator)
52615301

@@ -13792,7 +13832,7 @@ async def delete(
1379213832
url : str
1379313833
Target URL.
1379413834
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13795-
Query parameters to be send with the URL.
13835+
Query parameters to be sent with the URL.
1379613836
headers : Union[Dict[str, str], NoneType]
1379713837
Allows to set HTTP headers.
1379813838
data : Union[Any, bytes, str, NoneType]
@@ -13860,7 +13900,7 @@ async def head(
1386013900
url : str
1386113901
Target URL.
1386213902
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13863-
Query parameters to be send with the URL.
13903+
Query parameters to be sent with the URL.
1386413904
headers : Union[Dict[str, str], NoneType]
1386513905
Allows to set HTTP headers.
1386613906
timeout : Union[float, NoneType]
@@ -13912,7 +13952,7 @@ async def get(
1391213952
url : str
1391313953
Target URL.
1391413954
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13915-
Query parameters to be send with the URL.
13955+
Query parameters to be sent with the URL.
1391613956
headers : Union[Dict[str, str], NoneType]
1391713957
Allows to set HTTP headers.
1391813958
timeout : Union[float, NoneType]
@@ -13969,7 +14009,7 @@ async def patch(
1396914009
url : str
1397014010
Target URL.
1397114011
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13972-
Query parameters to be send with the URL.
14012+
Query parameters to be sent with the URL.
1397314013
headers : Union[Dict[str, str], NoneType]
1397414014
Allows to set HTTP headers.
1397514015
data : Union[Any, bytes, str, NoneType]
@@ -14042,7 +14082,7 @@ async def put(
1404214082
url : str
1404314083
Target URL.
1404414084
params : Union[Dict[str, Union[bool, float, str]], NoneType]
14045-
Query parameters to be send with the URL.
14085+
Query parameters to be sent with the URL.
1404614086
headers : Union[Dict[str, str], NoneType]
1404714087
Allows to set HTTP headers.
1404814088
data : Union[Any, bytes, str, NoneType]
@@ -14115,7 +14155,7 @@ async def post(
1411514155
url : str
1411614156
Target URL.
1411714157
params : Union[Dict[str, Union[bool, float, str]], NoneType]
14118-
Query parameters to be send with the URL.
14158+
Query parameters to be sent with the URL.
1411914159
headers : Union[Dict[str, str], NoneType]
1412014160
Allows to set HTTP headers.
1412114161
data : Union[Any, bytes, str, NoneType]
@@ -14188,7 +14228,7 @@ async def fetch(
1418814228
url_or_request : Union[Request, str]
1418914229
Target URL or Request to get all parameters from.
1419014230
params : Union[Dict[str, Union[bool, float, str]], NoneType]
14191-
Query parameters to be send with the URL.
14231+
Query parameters to be sent with the URL.
1419214232
method : Union[str, NoneType]
1419314233
If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) or
1419414234
[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)). If not specified, GET method is used.

playwright/sync_api/_generated.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5162,6 +5162,30 @@ def set_checked(
51625162

51635163

51645164
class FrameLocator(SyncBase):
5165+
@property
5166+
def first(self) -> "FrameLocator":
5167+
"""FrameLocator.first
5168+
5169+
Returns locator to the first matching frame.
5170+
5171+
Returns
5172+
-------
5173+
FrameLocator
5174+
"""
5175+
return mapping.from_impl(self._impl_obj.first)
5176+
5177+
@property
5178+
def last(self) -> "FrameLocator":
5179+
"""FrameLocator.last
5180+
5181+
Returns locator to the last matching frame.
5182+
5183+
Returns
5184+
-------
5185+
FrameLocator
5186+
"""
5187+
return mapping.from_impl(self._impl_obj.last)
5188+
51655189
def locator(self, selector: str) -> "Locator":
51665190
"""FrameLocator.locator
51675191

@@ -5197,6 +5221,22 @@ def frame_locator(self, selector: str) -> "FrameLocator":
51975221

51985222
return mapping.from_impl(self._impl_obj.frame_locator(selector=selector))
51995223

5224+
def nth(self, index: int) -> "FrameLocator":
5225+
"""FrameLocator.nth
5226+
5227+
Returns locator to the n-th matching frame.
5228+
5229+
Parameters
5230+
----------
5231+
index : int
5232+
5233+
Returns
5234+
-------
5235+
FrameLocator
5236+
"""
5237+
5238+
return mapping.from_impl(self._impl_obj.nth(index=index))
5239+
52005240

52015241
mapping.register(FrameLocatorImpl, FrameLocator)
52025242

@@ -13515,7 +13555,7 @@ def delete(
1351513555
url : str
1351613556
Target URL.
1351713557
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13518-
Query parameters to be send with the URL.
13558+
Query parameters to be sent with the URL.
1351913559
headers : Union[Dict[str, str], NoneType]
1352013560
Allows to set HTTP headers.
1352113561
data : Union[Any, bytes, str, NoneType]
@@ -13583,7 +13623,7 @@ def head(
1358313623
url : str
1358413624
Target URL.
1358513625
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13586-
Query parameters to be send with the URL.
13626+
Query parameters to be sent with the URL.
1358713627
headers : Union[Dict[str, str], NoneType]
1358813628
Allows to set HTTP headers.
1358913629
timeout : Union[float, NoneType]
@@ -13635,7 +13675,7 @@ def get(
1363513675
url : str
1363613676
Target URL.
1363713677
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13638-
Query parameters to be send with the URL.
13678+
Query parameters to be sent with the URL.
1363913679
headers : Union[Dict[str, str], NoneType]
1364013680
Allows to set HTTP headers.
1364113681
timeout : Union[float, NoneType]
@@ -13692,7 +13732,7 @@ def patch(
1369213732
url : str
1369313733
Target URL.
1369413734
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13695-
Query parameters to be send with the URL.
13735+
Query parameters to be sent with the URL.
1369613736
headers : Union[Dict[str, str], NoneType]
1369713737
Allows to set HTTP headers.
1369813738
data : Union[Any, bytes, str, NoneType]
@@ -13765,7 +13805,7 @@ def put(
1376513805
url : str
1376613806
Target URL.
1376713807
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13768-
Query parameters to be send with the URL.
13808+
Query parameters to be sent with the URL.
1376913809
headers : Union[Dict[str, str], NoneType]
1377013810
Allows to set HTTP headers.
1377113811
data : Union[Any, bytes, str, NoneType]
@@ -13838,7 +13878,7 @@ def post(
1383813878
url : str
1383913879
Target URL.
1384013880
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13841-
Query parameters to be send with the URL.
13881+
Query parameters to be sent with the URL.
1384213882
headers : Union[Dict[str, str], NoneType]
1384313883
Allows to set HTTP headers.
1384413884
data : Union[Any, bytes, str, NoneType]
@@ -13911,7 +13951,7 @@ def fetch(
1391113951
url_or_request : Union[Request, str]
1391213952
Target URL or Request to get all parameters from.
1391313953
params : Union[Dict[str, Union[bool, float, str]], NoneType]
13914-
Query parameters to be send with the URL.
13954+
Query parameters to be sent with the URL.
1391513955
method : Union[str, NoneType]
1391613956
If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) or
1391713957
[POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)). If not specified, GET method is used.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
InWheel = None
2929
from wheel.bdist_wheel import bdist_wheel as BDistWheelCommand
3030

31-
driver_version = "1.17.0-next-1636463074000"
31+
driver_version = "1.18.0-next-1636539685000"
3232

3333

3434
def extractall(zip: zipfile.ZipFile, path: str) -> None:

tests/async/test_locators.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414

1515
import os
16+
from urllib.parse import urlparse
1617

1718
import pytest
1819

@@ -537,3 +538,50 @@ async def test_locators_frame_should_work_with_locator_frame_locator(
537538
await button.wait_for()
538539
assert await button.inner_text() == "Hello iframe"
539540
await button.click()
541+
542+
543+
async def route_ambiguous(page: Page) -> None:
544+
await page.route(
545+
"**/empty.html",
546+
lambda route: route.fulfill(
547+
body="""
548+
<iframe src="iframe-1.html"></iframe>
549+
<iframe src="iframe-2.html"></iframe>
550+
<iframe src="iframe-3.html"></iframe>
551+
""",
552+
content_type="text/html",
553+
),
554+
)
555+
await page.route(
556+
"**/iframe-*",
557+
lambda route: route.fulfill(
558+
body=f"<html><button>Hello from {urlparse(route.request.url).path[1:]}</button></html>",
559+
content_type="text/html",
560+
),
561+
)
562+
563+
564+
async def test_locator_frame_locator_should_throw_on_ambiguity(
565+
page: Page, server: Server
566+
) -> None:
567+
await route_ambiguous(page)
568+
await page.goto(server.EMPTY_PAGE)
569+
button = page.locator("body").frame_locator("iframe").locator("button")
570+
with pytest.raises(
571+
Error,
572+
match='.*strict mode violation: "body >> iframe" resolved to 3 elements.*',
573+
):
574+
await button.wait_for()
575+
576+
577+
async def test_locator_frame_locator_should_not_throw_on_first_last_nth(
578+
page: Page, server: Server
579+
) -> None:
580+
await route_ambiguous(page)
581+
await page.goto(server.EMPTY_PAGE)
582+
button1 = page.locator("body").frame_locator("iframe").first.locator("button")
583+
assert await button1.text_content() == "Hello from iframe-1.html"
584+
button2 = page.locator("body").frame_locator("iframe").nth(1).locator("button")
585+
assert await button2.text_content() == "Hello from iframe-2.html"
586+
button3 = page.locator("body").frame_locator("iframe").last.locator("button")
587+
assert await button3.text_content() == "Hello from iframe-3.html"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy