Skip to content

Commit

Permalink
executed 'inv lint' to format the code.
Browse files Browse the repository at this point in the history
Signed-off-by: René <snooz@posteo.de>
  • Loading branch information
Snooz82 committed Nov 18, 2023
1 parent 68edcfe commit 29e03b1
Show file tree
Hide file tree
Showing 16 changed files with 775 additions and 212 deletions.
7 changes: 6 additions & 1 deletion atest/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ def execute_tests(interpreter, browser, rf_options, grid, event_firing):
options.extend([opt.format(browser=browser) for opt in ROBOT_OPTIONS])
if rf_options:
options += rf_options
options += ["--exclude", f"known issue {browser.replace('headless', '')}", "--exclude", "triage"]
options += [
"--exclude",
f"known issue {browser.replace('headless', '')}",
"--exclude",
"triage",
]
command = runner
if grid:
command += [
Expand Down
7 changes: 6 additions & 1 deletion src/SeleniumLibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
)
from SeleniumLibrary.keywords.screenshot import EMBED
from SeleniumLibrary.locators import ElementFinder
from SeleniumLibrary.utils import LibraryListener, is_truthy, _convert_timeout, _convert_delay
from SeleniumLibrary.utils import (
LibraryListener,
is_truthy,
_convert_timeout,
_convert_delay,
)


__version__ = "6.1.3"
Expand Down
772 changes: 639 additions & 133 deletions src/SeleniumLibrary/__init__.pyi

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions src/SeleniumLibrary/keywords/browsermanagement.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@

from SeleniumLibrary.base import keyword, LibraryComponent
from SeleniumLibrary.locators import WindowManager
from SeleniumLibrary.utils import timestr_to_secs, secs_to_timestr, _convert_timeout, _convert_delay
from SeleniumLibrary.utils import (
timestr_to_secs,
secs_to_timestr,
_convert_timeout,
_convert_delay,
)

from .webdrivertools import WebDriverCreator

Expand Down Expand Up @@ -278,7 +283,9 @@ def open_browser(
self.go_to(url)
return index
if desired_capabilities:
self.warn("desired_capabilities has been deprecated and removed. Please use options to configure browsers as per documentation.")
self.warn(
"desired_capabilities has been deprecated and removed. Please use options to configure browsers as per documentation."
)
return self._make_new_browser(
url,
browser,
Expand Down Expand Up @@ -334,7 +341,11 @@ def _make_new_browser(

@keyword
def create_webdriver(
self, driver_name: str, alias: Optional[str] = None, kwargs: Optional[dict] = None, **init_kwargs
self,
driver_name: str,
alias: Optional[str] = None,
kwargs: Optional[dict] = None,
**init_kwargs,
) -> str:
"""Creates an instance of Selenium WebDriver.
Expand Down Expand Up @@ -713,8 +724,7 @@ def set_action_chain_delay(self, value: timedelta) -> str:

@keyword
def get_action_chain_delay(self):
"""Gets the currently stored value for chain_delay_value in timestr format.
"""
"""Gets the currently stored value for chain_delay_value in timestr format."""
return timestr_to_secs(f"{self.ctx.action_chain_delay} milliseconds")

@keyword
Expand Down
12 changes: 9 additions & 3 deletions src/SeleniumLibrary/keywords/element.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,9 @@ def scroll_element_into_view(self, locator: Union[WebElement, str]):
New in SeleniumLibrary 3.2.0
"""
element = self.find_element(locator)
ActionChains(self.driver, duration=self.ctx.action_chain_delay).move_to_element(element).perform()
ActionChains(self.driver, duration=self.ctx.action_chain_delay).move_to_element(
element
).perform()

@keyword
def drag_and_drop(
Expand Down Expand Up @@ -831,7 +833,9 @@ def mouse_up(self, locator: Union[WebElement, str]):
"""
self.info(f"Simulating Mouse Up on element '{locator}'.")
element = self.find_element(locator)
ActionChains(self.driver, duration=self.ctx.action_chain_delay).release(element).perform()
ActionChains(self.driver, duration=self.ctx.action_chain_delay).release(
element
).perform()

@keyword
def open_context_menu(self, locator: Union[WebElement, str]):
Expand Down Expand Up @@ -925,7 +929,9 @@ def press_keys(self, locator: Union[WebElement, None, str] = None, *keys: str):
if not is_noney(locator):
self.info(f"Sending key(s) {keys} to {locator} element.")
element = self.find_element(locator)
ActionChains(self.driver, duration=self.ctx.action_chain_delay).click(element).perform()
ActionChains(self.driver, duration=self.ctx.action_chain_delay).click(
element
).perform()
else:
self.info(f"Sending key(s) {keys} to page.")
element = None
Expand Down
1 change: 0 additions & 1 deletion src/SeleniumLibrary/keywords/javascript.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@


class JavaScriptKeywords(LibraryComponent):

js_marker = "JAVASCRIPT"
arg_marker = "ARGUMENTS"

Expand Down
32 changes: 20 additions & 12 deletions src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@


class WebDriverCreator:

browser_names = {
"googlechrome": "chrome",
"gc": "chrome",
Expand All @@ -58,7 +57,7 @@ class WebDriverCreator:
def __init__(self, log_dir):
self.log_dir = log_dir
self.selenium_options = SeleniumOptions()
#self.selenium_service = SeleniumService()
# self.selenium_service = SeleniumService()

def create_driver(
self,
Expand Down Expand Up @@ -134,11 +133,12 @@ def _remote_capabilities_resolver(self, set_capabilities, default_capabilities):
def _get_log_method(self, service_cls, service_log_path):
# -- temporary fix to transition selenium to v4.13 from v4.11 and prior
from inspect import signature

sig = signature(service_cls)
if 'log_output' in str(sig):
return {'log_output': service_log_path}
if "log_output" in str(sig):
return {"log_output": service_log_path}
else:
return {'log_path': service_log_path}
return {"log_path": service_log_path}
# --

def create_chrome(
Expand All @@ -154,7 +154,9 @@ def create_chrome(
options = webdriver.ChromeOptions()
return self._remote(remote_url, options=options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.chrome.service.Service)
executable_path = self._get_executable_path(
webdriver.chrome.service.Service
)
log_method = self._get_log_method(ChromeService, service_log_path)
service = ChromeService(executable_path=executable_path, **log_method)
return webdriver.Chrome(
Expand All @@ -172,7 +174,7 @@ def create_headless_chrome(
):
if not options:
options = webdriver.ChromeOptions()
options.add_argument('--headless=new')
options.add_argument("--headless=new")
return self.create_chrome(
desired_capabilities, remote_url, options, service_log_path, executable_path
)
Expand Down Expand Up @@ -207,8 +209,12 @@ def create_firefox(
if remote_url:
return self._remote(remote_url, options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.firefox.service.Service)
log_method = self._get_log_method(FirefoxService, service_log_path or self._geckodriver_log)
executable_path = self._get_executable_path(
webdriver.firefox.service.Service
)
log_method = self._get_log_method(
FirefoxService, service_log_path or self._geckodriver_log
)
service = FirefoxService(executable_path=executable_path, **log_method)
return webdriver.Firefox(
options=options,
Expand Down Expand Up @@ -253,7 +259,7 @@ def create_headless_firefox(
):
if not options:
options = webdriver.FirefoxOptions()
options.add_argument('-headless')
options.add_argument("-headless")
return self.create_firefox(
desired_capabilities,
remote_url,
Expand Down Expand Up @@ -282,7 +288,7 @@ def create_ie(
return webdriver.Ie(
options=options,
service=service,
#**desired_capabilities,
# **desired_capabilities,
)

def _has_options(self, web_driver):
Expand All @@ -308,7 +314,7 @@ def create_edge(
return webdriver.Edge(
options=options,
service=service,
#**desired_capabilities,
# **desired_capabilities,
)

def create_safari(
Expand Down Expand Up @@ -444,6 +450,7 @@ def _get_index(self, alias_or_index):
except ValueError:
return None


# Temporarily removing as not going to use with initial 4.10.0 hotfixq
# class SeleniumService:
# """ executable_path: str = DEFAULT_EXECUTABLE_PATH,
Expand Down Expand Up @@ -492,6 +499,7 @@ def _get_index(self, alias_or_index):
# service = importlib.import_module(f"selenium.webdriver.{browser}.service")
# return service.Service


class SeleniumOptions:
def create(self, browser, options):
if not options:
Expand Down
2 changes: 1 addition & 1 deletion src/SeleniumLibrary/keywords/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def switch_window(

@keyword
def close_window(self):
"""Closes currently opened and selected browser window/tab. """
"""Closes currently opened and selected browser window/tab."""
self.driver.close()

@keyword
Expand Down
5 changes: 3 additions & 2 deletions src/SeleniumLibrary/utils/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
def is_noney(item):
return item is None or is_string(item) and item.upper() == "NONE"


def _convert_delay(delay):
if isinstance(delay, timedelta):
return delay.microseconds // 1000
else:
x = timestr_to_secs(delay)
return int( x * 1000)
x = timestr_to_secs(delay)
return int(x * 1000)


def _convert_timeout(timeout):
Expand Down
2 changes: 1 addition & 1 deletion tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def atest(ctx, suite=None):
Args:
suite: Select which suite to run.
Example:
inv utest --suite keywords/test_browsermanagement.py
inv utest --suite keywords/test_selenium_options_parser.py::test_create_chrome_with_options
Expand Down
6 changes: 4 additions & 2 deletions utest/test/keywords/IGNOREDtest_webdrivercreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ def test_capabilities_resolver_chrome(creator):
def test_chrome(creator):
expected_webdriver = mock()
when(webdriver).Chrome(
options=None, service=None # service=ANY # service_log_path=None, executable_path="chromedriver"
options=None,
service=None, # service=ANY # service_log_path=None, executable_path="chromedriver"
).thenReturn(expected_webdriver)
driver = creator.create_chrome({}, None)
assert driver == expected_webdriver
Expand Down Expand Up @@ -208,7 +209,8 @@ def test_chrome_headless(creator):
service = mock()
when(webdriver).ChromeOptions().thenReturn(options)
when(webdriver).Chrome(
options=options, service=ANY # service=None # service_log_path=None, executable_path="chromedriver"
options=options,
service=ANY, # service=None # service_log_path=None, executable_path="chromedriver"
).thenReturn(expected_webdriver)
driver = creator.create_headless_chrome({}, None)
assert options.headless is True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def teardown_function():
def test_create_chrome_executable_path_set(creator):
expected_webdriver = mock()
when(webdriver).Chrome(
options=None, service=ANY, # service_log_path=None, executable_path="/path/to/chromedriver"
options=None,
service=ANY, # service_log_path=None, executable_path="/path/to/chromedriver"
).thenReturn(expected_webdriver)
driver = creator.create_chrome({}, None, executable_path="/path/to/chromedriver")
assert driver == expected_webdriver
Expand All @@ -33,7 +34,8 @@ def test_create_chrome_executable_path_set(creator):
def test_create_chrome_executable_path_not_set(creator):
expected_webdriver = mock()
when(webdriver).Chrome(
options=None, service=ANY, # service_log_path=None, executable_path="chromedriver"
options=None,
service=ANY, # service_log_path=None, executable_path="chromedriver"
).thenReturn(expected_webdriver)
when(creator)._get_executable_path(ANY).thenReturn("chromedriver")
driver = creator.create_chrome({}, None, executable_path=None)
Expand Down Expand Up @@ -72,7 +74,8 @@ def test_create_heasless_chrome_executable_path_set(creator):
options = mock()
when(webdriver).ChromeOptions().thenReturn(options)
when(webdriver).Chrome(
options=options, service = ANY # service_log_path=None, executable_path="/path/to/chromedriver"
options=options,
service=ANY, # service_log_path=None, executable_path="/path/to/chromedriver"
).thenReturn(expected_webdriver)
driver = creator.create_headless_chrome(
{}, None, executable_path="/path/to/chromedriver"
Expand All @@ -92,7 +95,7 @@ def test_create_firefox_executable_path_set(creator):
when(webdriver).Firefox(
options=options,
# firefox_profile=profile,
service = ANY,
service=ANY,
# service_log_path=log_file,
# executable_path=executable,
).thenReturn(expected_webdriver)
Expand Down Expand Up @@ -248,4 +251,4 @@ def get_geckodriver_log():
# return os.path.join(LOG_DIR, "geckodriver-1.log")
# print(f"{os.getcwd()}")
cwd = os.getcwd()
return cwd
return cwd
Loading

0 comments on commit 29e03b1

Please sign in to comment.