Skip to content

Commit

Permalink
Auto convert open browser parameters (#111)
Browse files Browse the repository at this point in the history
* Force convert browser params

* enhance browser params

* Fixed missing bracket
  • Loading branch information
atthaboon authored Apr 20, 2021
1 parent 0326ef4 commit e20301d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
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

0 comments on commit e20301d

Please sign in to comment.