Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(roll): roll Playwright to 1.23.0-beta-1656026605000 #1374

Merged
merged 6 commits into from Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,9 +4,9 @@ Playwright is a Python library to automate [Chromium](https://www.chromium.org/H

| | Linux | macOS | Windows |
| :--- | :---: | :---: | :---: |
| Chromium <!-- GEN:chromium-version -->102.0.5005.61<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Chromium <!-- GEN:chromium-version -->103.0.5060.53<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| WebKit <!-- GEN:webkit-version -->15.4<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->99.0.1<!-- GEN:stop --> | ✅ | ✅ | ✅ |
| Firefox <!-- GEN:firefox-version -->100.0.2<!-- GEN:stop --> | ✅ | ✅ | ✅ |

## Documentation

Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_api_structures.py
Expand Up @@ -179,6 +179,7 @@ class ExpectedTextValue(TypedDict, total=False):
regexFlags: str
matchSubstring: bool
normalizeWhiteSpace: bool
ignoreCase: Optional[bool]


class FrameExpectOptions(TypedDict, total=False):
Expand Down
75 changes: 61 additions & 14 deletions playwright/_impl/_assertions.py
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, List, Pattern, Union
from typing import Any, List, Optional, Pattern, Union
from urllib.parse import urljoin

from playwright._impl._api_structures import ExpectedTextValue, FrameExpectOptions
Expand Down Expand Up @@ -122,11 +122,15 @@ async def to_contain_text(
expected: Union[List[Union[Pattern, str]], Pattern, str],
use_inner_text: bool = None,
timeout: float = None,
ignore_case: bool = None,
) -> None:
__tracebackhide__ = True
if isinstance(expected, list):
expected_text = to_expected_text_values(
expected, match_substring=True, normalize_white_space=True
expected,
match_substring=True,
normalize_white_space=True,
ignore_case=ignore_case,
)
await self._expect_impl(
"to.contain.text.array",
Expand All @@ -140,7 +144,10 @@ async def to_contain_text(
)
else:
expected_text = to_expected_text_values(
[expected], match_substring=True, normalize_white_space=True
[expected],
match_substring=True,
normalize_white_space=True,
ignore_case=ignore_case,
)
await self._expect_impl(
"to.have.text",
Expand All @@ -158,9 +165,10 @@ async def not_to_contain_text(
expected: Union[List[Union[Pattern, str]], Pattern, str],
use_inner_text: bool = None,
timeout: float = None,
ignore_case: bool = None,
) -> None:
__tracebackhide__ = True
await self._not.to_contain_text(expected, use_inner_text, timeout)
await self._not.to_contain_text(expected, use_inner_text, timeout, ignore_case)

async def to_have_attribute(
self,
Expand Down Expand Up @@ -335,16 +343,41 @@ async def not_to_have_value(
__tracebackhide__ = True
await self._not.to_have_value(value, timeout)

async def to_have_values(
self,
values: List[Union[Pattern, str]],
timeout: float = None,
) -> None:
__tracebackhide__ = True
expected_text = to_expected_text_values(values)
await self._expect_impl(
"to.have.values",
FrameExpectOptions(expectedText=expected_text, timeout=timeout),
values,
"Locator expected to have Values",
)

async def not_to_have_values(
self,
values: List[Union[Pattern, str]],
timeout: float = None,
) -> None:
__tracebackhide__ = True
await self._not.to_have_values(values, timeout)

async def to_have_text(
self,
expected: Union[List[Union[Pattern, str]], Pattern, str],
use_inner_text: bool = None,
timeout: float = None,
ignore_case: bool = None,
) -> None:
__tracebackhide__ = True
if isinstance(expected, list):
expected_text = to_expected_text_values(
expected, normalize_white_space=True
expected,
normalize_white_space=True,
ignore_case=ignore_case,
)
await self._expect_impl(
"to.have.text.array",
Expand All @@ -358,7 +391,7 @@ async def to_have_text(
)
else:
expected_text = to_expected_text_values(
[expected], normalize_white_space=True
[expected], normalize_white_space=True, ignore_case=ignore_case
)
await self._expect_impl(
"to.have.text",
Expand All @@ -376,9 +409,10 @@ async def not_to_have_text(
expected: Union[List[Union[Pattern, str]], Pattern, str],
use_inner_text: bool = None,
timeout: float = None,
ignore_case: bool = None,
) -> None:
__tracebackhide__ = True
await self._not.to_have_text(expected, use_inner_text, timeout)
await self._not.to_have_text(expected, use_inner_text, timeout, ignore_case)

async def to_be_checked(
self,
Expand Down Expand Up @@ -568,33 +602,46 @@ async def not_to_be_ok(self) -> None:


def expected_regex(
pattern: Pattern, match_substring: bool, normalize_white_space: bool
pattern: Pattern,
match_substring: bool,
normalize_white_space: bool,
ignore_case: Optional[bool] = None,
) -> ExpectedTextValue:
expected = ExpectedTextValue(
regexSource=pattern.pattern,
regexFlags=escape_regex_flags(pattern),
matchSubstring=match_substring,
normalizeWhiteSpace=normalize_white_space,
ignoreCase=ignore_case,
)
if expected["ignoreCase"] is None:
rwoll marked this conversation as resolved.
Show resolved Hide resolved
del expected["ignoreCase"]
return expected


def to_expected_text_values(
items: Union[List[Pattern], List[str], List[Union[str, Pattern]]],
match_substring: bool = False,
normalize_white_space: bool = False,
ignore_case: Optional[bool] = None,
) -> List[ExpectedTextValue]:
out: List[ExpectedTextValue] = []
assert isinstance(items, list)
for item in items:
if isinstance(item, str):
o = ExpectedTextValue(
string=item,
matchSubstring=match_substring,
normalizeWhiteSpace=normalize_white_space,
ignoreCase=ignore_case,
)
if o["ignoreCase"] is None:
del o["ignoreCase"]
out.append(o)
elif isinstance(item, Pattern):
out.append(
ExpectedTextValue(
string=item,
matchSubstring=match_substring,
normalizeWhiteSpace=normalize_white_space,
expected_regex(
item, match_substring, normalize_white_space, ignore_case
)
)
elif isinstance(item, Pattern):
out.append(expected_regex(item, match_substring, normalize_white_space))
return out
7 changes: 7 additions & 0 deletions playwright/_impl/_browser.py
Expand Up @@ -32,6 +32,7 @@
ColorScheme,
ForcedColors,
ReducedMotion,
ServiceWorkersPolicy,
async_readfile,
is_safe_close_error,
locals_to_params,
Expand Down Expand Up @@ -75,6 +76,10 @@ def _on_close(self) -> None:
def contexts(self) -> List[BrowserContext]:
return self._contexts.copy()

@property
def browser_type(self) -> "BrowserType":
return self._browser_type

def is_connected(self) -> bool:
return self._is_connected

Expand Down Expand Up @@ -110,6 +115,7 @@ async def new_context(
storageState: Union[StorageState, str, Path] = None,
baseURL: str = None,
strictSelectors: bool = None,
serviceWorkers: ServiceWorkersPolicy = None,
) -> BrowserContext:
params = locals_to_params(locals())
await normalize_context_params(self._connection._is_sync, params)
Expand Down Expand Up @@ -154,6 +160,7 @@ async def new_page(
storageState: Union[StorageState, str, Path] = None,
baseURL: str = None,
strictSelectors: bool = None,
serviceWorkers: ServiceWorkersPolicy = None,
) -> Page:
params = locals_to_params(locals())
context = await self.new_context(**params)
Expand Down
2 changes: 2 additions & 0 deletions playwright/_impl/_browser_type.py
Expand Up @@ -37,6 +37,7 @@
Env,
ForcedColors,
ReducedMotion,
ServiceWorkersPolicy,
locals_to_params,
)
from playwright._impl._transport import WebSocketTransport
Expand Down Expand Up @@ -138,6 +139,7 @@ async def launch_persistent_context(
recordVideoSize: ViewportSize = None,
baseURL: str = None,
strictSelectors: bool = None,
serviceWorkers: ServiceWorkersPolicy = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir))
params = locals_to_params(locals())
Expand Down
14 changes: 14 additions & 0 deletions playwright/_impl/_frame.py
Expand Up @@ -94,6 +94,20 @@ def _on_load_state(
self._event_emitter.emit("loadstate", add)
elif remove and remove in self._load_states:
self._load_states.remove(remove)
if (
not self._parent_frame
and add == "load"
and hasattr(self, "_page")
and self._page
):
self._page.emit("load", self)
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved
if (
not self._parent_frame
and add == "domcontentloaded"
and hasattr(self, "_page")
and self._page
):
self._page.emit("domcontentloaded", self)
mxschmitt marked this conversation as resolved.
Show resolved Hide resolved

def _on_frame_navigated(self, event: FrameNavigatedEvent) -> None:
self._url = event["url"]
Expand Down
1 change: 1 addition & 0 deletions playwright/_impl/_helper.py
Expand Up @@ -62,6 +62,7 @@
DocumentLoadState = Literal["commit", "domcontentloaded", "load", "networkidle"]
KeyboardModifier = Literal["Alt", "Control", "Meta", "Shift"]
MouseButton = Literal["left", "middle", "right"]
ServiceWorkersPolicy = Literal["allow", "block"]


class ErrorPayload(TypedDict, total=False):
Expand Down
4 changes: 4 additions & 0 deletions playwright/_impl/_network.py
Expand Up @@ -343,6 +343,10 @@ def status_text(self) -> str:
def headers(self) -> Headers:
return self._provisional_headers.headers()

@property
def from_service_worker(self) -> bool:
return self._initializer["fromServiceWorker"]

async def all_headers(self) -> Headers:
return (await self._actual_headers()).headers()

Expand Down
4 changes: 0 additions & 4 deletions playwright/_impl/_page.py
Expand Up @@ -164,9 +164,6 @@ def __init__(
)
self._channel.on("crash", lambda _: self._on_crash())
self._channel.on("dialog", lambda params: self._on_dialog(params))
self._channel.on(
"domcontentloaded", lambda _: self.emit(Page.Events.DOMContentLoaded, self)
)
self._channel.on("download", lambda params: self._on_download(params))
self._channel.on(
"fileChooser",
Expand All @@ -185,7 +182,6 @@ def __init__(
"frameDetached",
lambda params: self._on_frame_detached(from_channel(params["frame"])),
)
self._channel.on("load", lambda _: self.emit(Page.Events.Load, self))
self._channel.on(
"pageError",
lambda params: self.emit(
Expand Down