From e20301d9e805a84bb54998d9f8c15b2f7426c7a2 Mon Sep 17 00:00:00 2001 From: "Atthaboon Sanurt (P'Art)" Date: Tue, 20 Apr 2021 09:37:24 +0700 Subject: [PATCH] Auto convert open browser parameters (#111) * Force convert browser params * enhance browser params * Fixed missing bracket --- PuppeteerLibrary/playwright/playwright_context.py | 10 +++++++++- PuppeteerLibrary/puppeteer/puppeteer_context.py | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/PuppeteerLibrary/playwright/playwright_context.py b/PuppeteerLibrary/playwright/playwright_context.py index 5e8ac1c..4aa050e 100644 --- a/PuppeteerLibrary/playwright/playwright_context.py +++ b/PuppeteerLibrary/playwright/playwright_context.py @@ -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 @@ -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": @@ -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']] diff --git a/PuppeteerLibrary/puppeteer/puppeteer_context.py b/PuppeteerLibrary/puppeteer/puppeteer_context.py index cc84615..82dfcfa 100644 --- a/PuppeteerLibrary/puppeteer/puppeteer_context.py +++ b/PuppeteerLibrary/puppeteer/puppeteer_context.py @@ -1,3 +1,4 @@ +from PuppeteerLibrary.utils.coverter import str2bool, str2int import sys from pyppeteer import launch from pyppeteer.browser import Browser @@ -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}