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

Auto convert open browser parameters #111

Merged
merged 3 commits into from
Apr 20, 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
10 changes: 9 additions & 1 deletion PuppeteerLibrary/playwright/playwright_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from PuppeteerLibrary.playwright.async_keywords.playwright_pdf import PlaywrightPDF
from PuppeteerLibrary.playwright.async_keywords.playwright_javascript import PlaywrightJavascript
from PuppeteerLibrary.library_context.ilibrary_context import iLibraryContext
from PuppeteerLibrary.utils.coverter import str2bool, str2int
try:
from playwright.async_api import async_playwright
from playwright.playwright import Playwright as AsyncPlaywright
Expand Down Expand Up @@ -46,6 +47,11 @@ async def start_server(self, options: dict={}):
}
merged_options = default_options
merged_options = {**merged_options, **options}
for key in merged_options.keys():
if key in ['headless', 'devtools', 'accept_downloads', 'is_mobile']:
merged_options[key] = str2bool(merged_options[key])
elif key in ['slowMo', 'width', 'height']:
merged_options[key] = str2int(merged_options[key])

self.playwright = await async_playwright().start()
if self.browser_type == "pwchrome":
Expand Down Expand Up @@ -75,7 +81,9 @@ async def create_new_page(self, options: dict={}) -> BasePage:

for support_key in self.page_support_options:
if support_key in options:
device_options[support_key] = options[support_key]
device_options[support_key] = options[support_key]
if support_key in ['accept_downloads', 'ignore_https_errors']:
device_options[support_key] = str2bool(device_options[support_key])

if 'emulate' in options:
device_options = self.playwright.devices[options['emulate']]
Expand Down
11 changes: 11 additions & 0 deletions PuppeteerLibrary/puppeteer/puppeteer_context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from PuppeteerLibrary.utils.coverter import str2bool, str2int
import sys
from pyppeteer import launch
from pyppeteer.browser import Browser
Expand Down Expand Up @@ -49,6 +50,16 @@ async def start_server(self, options: dict={}):
}
}
merged_options = {**merged_options, **options}
for key in merged_options.keys():
if key in ['headless', 'devtools', 'ignoreHTTPSErrors']:
merged_options[key] = str2bool(merged_options[key])
elif key in ['slowMo']:
merged_options[key] = str2int(merged_options[key])
elif key == 'defaultViewport':
merged_options[key] = {
'width': str2int(merged_options[key]['width']),
'height': str2int(merged_options[key]['height'])
}

if self.debug_mode is True:
merged_options = {**merged_options, **self.debug_mode_options}
Expand Down