Skip to content
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
12 changes: 11 additions & 1 deletion Examples/browser-management/open-close-browser.robot
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ ${DEFAULT_BROWSER} pwchrome
Open browser without option
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
Open browser http://127.0.0.1:7272/basic-html-elements.html browser=${BROWSER}


Open ssl issue page
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
${HEADLESS} = Get variable value ${HEADLESS} ${False}
&{options} = create dictionary
... headless=${HEADLESS}
... ignore_https_errors=${True}
... ignoreHTTPSErrors=${True}
Open browser https://expired.badssl.com/ browser=${BROWSER} options=${options}
Capture Page Screenshot

Switch to new browser
${BROWSER} = Get variable value ${BROWSER} ${DEFAULT_BROWSER}
${HEADLESS} = Get variable value ${HEADLESS} ${False}
Expand Down
7 changes: 7 additions & 0 deletions PuppeteerLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ def open_browser(self, url, browser="chrome", alias=None, options={}):
| height | default 768 |
| emulate | iPhone 11 |

**Other options**
pwchrome, webkit and firefox please visit: https://playwright.dev/python/docs/api/class-browser?_highlight=new_page#browsernew_pagekwargs
chrome please visit: https://pptr.dev/#?product=Puppeteer&version=v8.0.0&show=api-puppeteerlaunchoptions

Example:

| &{options} = | create dictionary | headless=${False} |
| `Open browser` | https://www.w3schools.com/html/html_forms.asp | options=${options} |

"""
if options is None:
options = {}

self.info(url)
library_context = self.ctx.create_library_context(alias, browser)
self.loop.run_until_complete(library_context.start_server(options))
Expand Down
13 changes: 10 additions & 3 deletions PuppeteerLibrary/playwright/playwright_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class PlaywrightContext(iLibraryContext):
browser: any = None
current_page: any = None
current_iframe = None

page_support_options = ['accept_downloads', 'bypass_csp', 'color_scheme', 'device_scale_factor', 'extra_http_headers', 'geolocation', 'has_touch', 'http_credentials', 'ignore_https_errors', 'is_mobile', 'java_script_enabled', 'locale', 'no_viewport', 'offline', 'permissions', 'proxy', 'record_har_omit_content', 'record_har_path', 'record_video_dir', 'record_video_size', 'timezone_id', 'user_agent', 'viewport']

def __init__(self, browser_type: str):
super().__init__(browser_type)
Expand All @@ -43,8 +45,7 @@ async def start_server(self, options: dict={}):
'accept_downloads': True
}
merged_options = default_options
if options is not None:
merged_options = {**merged_options, **options}
merged_options = {**merged_options, **options}

self.playwright = await async_playwright().start()
if self.browser_type == "pwchrome":
Expand All @@ -55,7 +56,7 @@ async def start_server(self, options: dict={}):
headless=merged_options['headless'])
elif self.browser_type == "firefox":
self.browser = await self.playwright.firefox.launch(
headless=merged_options['headless'])
headless=merged_options['headless'])
self.browser.accept_downloads = True

async def stop_server(self):
Expand All @@ -71,8 +72,14 @@ async def create_new_page(self, options: dict={}) -> BasePage:
device_options = {
'accept_downloads': True
}

for support_key in self.page_support_options:
if support_key in options:
device_options[support_key] = options[support_key]

if 'emulate' in options:
device_options = self.playwright.devices[options['emulate']]

new_page = await self.browser.new_page(**device_options)
self.current_page = PlaywrightPage(new_page)
return self.current_page
Expand Down
27 changes: 13 additions & 14 deletions PuppeteerLibrary/puppeteer/puppeteer_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,36 @@ class PuppeteerContext(iLibraryContext):
'devtools': False
}

page_support_options = ['ignoreHTTPSErrors', 'headless', 'executablePath', 'slowMo', 'defaultViewport', 'handleSIGINT', 'handleSIGTERM', 'handleSIGHUP', 'userDataDir', 'env', 'devtools']

def __init__(self, browser_type: str):
super().__init__(browser_type)

async def start_server(self, options: dict={}):
default_args = []
default_options = {
merged_options = {
'slowMo': 0,
'headless': True,
'devtools': False,
'width': 1366,
'height': 768
'defaultViewport': {
'width': 1366,
'height': 768
}
}
merged_options = default_options

if options is not None:
merged_options = {**merged_options, **options}
merged_options = {**merged_options, **options}

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

if 'win' not in sys.platform.lower():
default_args = ['--no-sandbox', '--disable-setuid-sandbox']

for support_key in self.page_support_options:
if support_key in options:
merged_options[support_key] = options[support_key]

self.browser = await launch(
headless=merged_options['headless'],
slowMo=merged_options['slowMo'],
devtools=merged_options['devtools'],
defaultViewport={
'width': merged_options['width'],
'height': merged_options['height']
},
**merged_options,
args=default_args)

async def stop_server(self):
Expand Down