Skip to content

Commit aa0b467

Browse files
feat: support dynamic browser name (microsoft#748)
1 parent dae661d commit aa0b467

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

playwright/async_api/_generated.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9930,6 +9930,15 @@ def stop(self) -> NoneType:
99309930

99319931
return mapping.from_maybe_impl(self._impl_obj.stop())
99329932

9933+
def __getitem__(self, value: str) -> "BrowserType":
9934+
if value == "chromium":
9935+
return self.chromium
9936+
elif value == "firefox":
9937+
return self.firefox
9938+
elif value == "webkit":
9939+
return self.webkit
9940+
raise ValueError("Invalid browser " + value)
9941+
99339942

99349943
mapping.register(PlaywrightImpl, Playwright)
99359944

playwright/sync_api/_generated.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9872,6 +9872,15 @@ def stop(self) -> NoneType:
98729872

98739873
return mapping.from_maybe_impl(self._impl_obj.stop())
98749874

9875+
def __getitem__(self, value: str) -> "BrowserType":
9876+
if value == "chromium":
9877+
return self.chromium
9878+
elif value == "firefox":
9879+
return self.firefox
9880+
elif value == "webkit":
9881+
return self.webkit
9882+
raise ValueError("Invalid browser " + value)
9883+
98759884

98769885
mapping.register(PlaywrightImpl, Playwright)
98779886

scripts/generate_async_api.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,19 @@ def generate(t: Any) -> None:
115115
f"""
116116
return {prefix}{arguments(value, len(prefix))}{suffix}"""
117117
)
118-
118+
if class_name == "Playwright":
119+
print(
120+
"""
121+
def __getitem__(self, value: str) -> "BrowserType":
122+
if value == "chromium":
123+
return self.chromium
124+
elif value == "firefox":
125+
return self.firefox
126+
elif value == "webkit":
127+
return self.webkit
128+
raise ValueError("Invalid browser "+value)
129+
"""
130+
)
119131
print("")
120132
print(f"mapping.register({class_name}Impl, {class_name})")
121133

scripts/generate_sync_api.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,19 @@ def generate(t: Any) -> None:
114114
f"""
115115
return {prefix}{arguments(value, len(prefix))}{suffix}"""
116116
)
117-
117+
if class_name == "Playwright":
118+
print(
119+
"""
120+
def __getitem__(self, value: str) -> "BrowserType":
121+
if value == "chromium":
122+
return self.chromium
123+
elif value == "firefox":
124+
return self.firefox
125+
elif value == "webkit":
126+
return self.webkit
127+
raise ValueError("Invalid browser "+value)
128+
"""
129+
)
118130
print("")
119131
print(f"mapping.register({class_name}Impl, {class_name})")
120132

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