Skip to content

feat: support dynamic browser name #748

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

Merged
merged 1 commit into from
Jun 28, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions playwright/async_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -9930,6 +9930,15 @@ def stop(self) -> NoneType:

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

def __getitem__(self, value: str) -> "BrowserType":
if value == "chromium":
return self.chromium
elif value == "firefox":
return self.firefox
elif value == "webkit":
return self.webkit
raise ValueError("Invalid browser " + value)


mapping.register(PlaywrightImpl, Playwright)

Expand Down
9 changes: 9 additions & 0 deletions playwright/sync_api/_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -9872,6 +9872,15 @@ def stop(self) -> NoneType:

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

def __getitem__(self, value: str) -> "BrowserType":
if value == "chromium":
return self.chromium
elif value == "firefox":
return self.firefox
elif value == "webkit":
return self.webkit
raise ValueError("Invalid browser " + value)


mapping.register(PlaywrightImpl, Playwright)

Expand Down
14 changes: 13 additions & 1 deletion scripts/generate_async_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,19 @@ def generate(t: Any) -> None:
f"""
return {prefix}{arguments(value, len(prefix))}{suffix}"""
)

if class_name == "Playwright":
print(
"""
def __getitem__(self, value: str) -> "BrowserType":
if value == "chromium":
return self.chromium
elif value == "firefox":
return self.firefox
elif value == "webkit":
return self.webkit
raise ValueError("Invalid browser "+value)
"""
)
print("")
print(f"mapping.register({class_name}Impl, {class_name})")

Expand Down
14 changes: 13 additions & 1 deletion scripts/generate_sync_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ def generate(t: Any) -> None:
f"""
return {prefix}{arguments(value, len(prefix))}{suffix}"""
)

if class_name == "Playwright":
print(
"""
def __getitem__(self, value: str) -> "BrowserType":
if value == "chromium":
return self.chromium
elif value == "firefox":
return self.firefox
elif value == "webkit":
return self.webkit
raise ValueError("Invalid browser "+value)
"""
)
print("")
print(f"mapping.register({class_name}Impl, {class_name})")

Expand Down