Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jruizg23 committed Jul 12, 2024
1 parent 1dd1b5d commit 15d0c1d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 30 deletions.
43 changes: 21 additions & 22 deletions toolium/config_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create_driver(self):
raise

return driver

def create_playwright_browser(self):
"""
Create a playwright browser using specified config properties
Expand Down Expand Up @@ -194,16 +194,16 @@ def _create_local_driver(self):
driver = driver_setup_method()

return driver

def _create_playwright_browser(self):
"""Create a browser in local machine using Playwright
:returns: a new browser Playwright
"""
driver_name = self.utils.get_driver_name()
if driver_name in ('android', 'ios', 'iphone'):
raise Exception('Playwright does not support mobile devices')
else:
else:
if driver_name in ['chrome', 'chromium']:
browser = self._setup_playwright_chrome()
elif driver_name == 'firefox':
Expand All @@ -213,16 +213,16 @@ def _create_playwright_browser(self):
else:
raise Exception(f'Playwright does not support {driver_name} driver')
return browser

def _create_playwright_persistent_browser_context(self):
"""Create a browser in local machine using Playwright
:returns: a new persistent browser context Playwright
"""
driver_name = self.utils.get_driver_name()
if driver_name in ('android', 'ios', 'iphone'):
raise Exception('Playwright does not support mobile devices')
else:
else:
if driver_name in ['chrome', 'chromium']:
browser_context = self._setup_playwright_persistent_chrome()
elif driver_name == 'firefox':
Expand Down Expand Up @@ -250,7 +250,7 @@ def get_playwright_context_options(self):
if window_width and window_height:
context_options['viewport'] = {'width': int(window_width), 'height': int(window_height)}
return context_options

def get_playwright_page_options(self):
"""Get Playwright page options from properties file
Expand All @@ -265,7 +265,6 @@ def get_playwright_page_options(self):
pass
return page_options


def _get_capabilities_from_driver_type(self):
"""Extract browserVersion and platformName from driver type and add them to capabilities
Expand Down Expand Up @@ -415,7 +414,7 @@ def _setup_playwright_firefox(self):
headless=headless_mode,
**browser_options
)

def _setup_playwright_persistent_firefox(self):
"""Setup Playwright Firefox persistent browser context
Expand All @@ -430,11 +429,11 @@ def _setup_playwright_persistent_firefox(self):
context_options = self.get_playwright_context_options()
context_options = self._update_dict(context_options, {'args': arguments})
context_options = self._update_dict(context_options, {'firefox_user_prefs': preferences})
return self.playwright.firefox.launch_persistent_context(
return self.playwright.firefox.launch_persistent_context(
headless=headless_mode,
**context_options
)

def _add_playwright_firefox_arguments(self, arguments):
"""Add Firefox arguments from properties file prepared for Playwright
Expand Down Expand Up @@ -526,7 +525,7 @@ def _get_chrome_options(self, capabilities={}):
self._update_dict(options.capabilities, capabilities)

return options

def _get_playwright_browser_options(self):
"""
Get Playwright browser options from properties file
Expand All @@ -541,7 +540,7 @@ def _get_playwright_browser_options(self):
except NoSectionError:
pass
return browser_options

def _setup_playwright_chrome(self):
"""
Setup Playwright Chrome browser
Expand All @@ -558,7 +557,7 @@ def _setup_playwright_chrome(self):
headless=headless_mode,
**browser_options
)

def _setup_playwright_persistent_chrome(self):
"""
Setup Playwright Chrome persistent browser context
Expand All @@ -571,7 +570,7 @@ def _setup_playwright_persistent_chrome(self):
self._add_playwright_chrome_extensions(arguments)
context_options = self.get_playwright_context_options()
context_options = self._update_dict(context_options, {'args': arguments})
return self.playwright.chromium.launch_persistent_context(
return self.playwright.chromium.launch_persistent_context(
headless=headless_mode,
**context_options
)
Expand All @@ -587,7 +586,7 @@ def _add_playwright_chrome_arguments(self, arguments):
self.logger.debug("Added Chrome argument: %s%s", pref, pref_value)
arguments.append('--{}{}'.format(pref, self._convert_property_type(pref_value)))
except NoSectionError:
pass
pass

def _add_playwright_chrome_extensions(self, arguments):
"""Add Chrome extensions from properties file
Expand All @@ -599,7 +598,7 @@ def _add_playwright_chrome_extensions(self, arguments):
self.logger.debug("Added Chrome extension: %s = %s", pref, pref_value)
arguments.append('--load-extension={}'.format(pref_value))
except NoSectionError:
pass
pass

def _add_chrome_options(self, options, option_name):
"""Add Chrome options from properties file
Expand Down Expand Up @@ -697,7 +696,7 @@ def _get_safari_options(self, capabilities={}):
self._add_capabilities_from_properties(capabilities, 'Capabilities')
self._update_dict(options.capabilities, capabilities)
return options

def _setup_playwright_webkit(self):
"""Setup Playwright Webkit browser
Expand All @@ -709,18 +708,18 @@ def _setup_playwright_webkit(self):
headless=headless_mode,
**browser_options
)

def _setup_playwright_persistent_webkit(self):
"""Setup Playwright Webkit persistent browser context
:returns: a new Playwright Webkit persistent browser context
"""
headless_mode = self.config.getboolean_optional('Driver', 'headless')
context_options = self.get_playwright_context_options()
return self.playwright.webkit.launch_persistent_context(
headless=headless_mode,
**context_options
)
)

def _setup_explorer(self):
"""Setup Internet Explorer webdriver
Expand Down
27 changes: 19 additions & 8 deletions toolium/driver_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,23 +267,34 @@ def connect_playwright(self):
async_loop = self.async_loop
self.playwright = async_loop.run_until_complete(async_playwright().start())

# In case of using a persistent context this property must be set and a BrowserContext is returned instead of a Browser
# In case of using a persistent context this property must be set and
# a BrowserContext is returned instead of a Browser
user_data_dir = self.config.get_optional('PlaywrightContextOptions', 'user_data_dir', None)
config_driver = ConfigDriver(self.config, self.utils, self.playwright)
if user_data_dir:
self.playwright_context = async_loop.run_until_complete(config_driver.create_playwright_persistent_browser_context())
else:
self.playwright_browser = async_loop.run_until_complete(config_driver.create_playwright_browser())
self.playwright_context = async_loop.run_until_complete(self.playwright_browser.new_context(**config_driver.get_playwright_context_options()))
self.driver = async_loop.run_until_complete(self.playwright_context.new_page(**config_driver.get_playwright_page_options()))
self.playwright_context = async_loop.run_until_complete(
config_driver.create_playwright_persistent_browser_context()
)
else:
self.playwright_browser = async_loop.run_until_complete(
config_driver.create_playwright_browser()
)
self.playwright_context = async_loop.run_until_complete(
self.playwright_browser.new_context(**config_driver.get_playwright_context_options())
)
self.driver = async_loop.run_until_complete(
self.playwright_context.new_page(**config_driver.get_playwright_page_options())
)

async def connect_playwright_new_page(self):
"""Set up and additional playwright driver creating a new page in current browser and context instance
It is an async method to be called from async steps or page objects
:returns: playwright driver
"""
self.driver = await self.playwright_context.new_page(**ConfigDriver(self.config, self.utils).get_playwright_page_options())
"""
self.driver = await self.playwright_context.new_page(
**ConfigDriver(self.config, self.utils).get_playwright_page_options()
)
return self.driver

def stop(self):
Expand Down

0 comments on commit 15d0c1d

Please sign in to comment.