Skip to content

Commit 984d2a3

Browse files
committed
ruff format fixes
1 parent b8a0d3e commit 984d2a3

44 files changed

Lines changed: 328 additions & 234 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

atest/acceptance/1-plugin/OpenBrowserExample.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ def create_driver(
121121
)
122122

123123
def create_seleniumwire(
124-
self, desired_capabilities, remote_url, options=None, service_log_path=None, service=None,
124+
self,
125+
desired_capabilities,
126+
remote_url,
127+
options=None,
128+
service_log_path=None,
129+
service=None,
125130
):
126131
logger.info(self.extra_dictionary)
127132
return webdriver.Chrome()

atest/resources/testlibs/get_driver_path.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def _import_options(self, browser):
1818
return options.Options
1919
2020
"""
21+
2122
from selenium import webdriver
2223
from selenium.webdriver.common import driver_finder
2324
import importlib
@@ -30,12 +31,12 @@ def get_driver_path(browser):
3031
options = importlib.import_module(f"selenium.webdriver.{browser}.options")
3132

3233
args = inspect.signature(driver_finder.DriverFinder.__init__).parameters.keys()
33-
if ('service' in args) and ('options' in args):
34+
if ("service" in args) and ("options" in args):
3435
# Selenium V4.20.0 or greater
3536
finder = driver_finder.DriverFinder(service.Service(), options.Options())
3637
return finder.get_driver_path()
3738
else:
3839
# Selenium v4.19.0 and prior
3940
finder = driver_finder.DriverFinder()
40-
func = getattr(finder, 'get_path')
41+
func = getattr(finder, "get_path")
4142
return finder.get_path(service.Service(), options.Options())

atest/run.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def _grid_status(status=False, role="hub"):
181181

182182

183183
@contextmanager
184-
def http_server(interpreter, port:int):
184+
def http_server(interpreter, port: int):
185185
serverlog = open(os.path.join(RESULTS_DIR, "serverlog.txt"), "w")
186186
interpreter = "python" if not interpreter else interpreter
187187
process = subprocess.Popen(
@@ -215,7 +215,12 @@ def execute_tests(interpreter, browser, rf_options, grid, event_firing, port):
215215
options.extend([opt.format(browser=browser) for opt in ROBOT_OPTIONS])
216216
if rf_options:
217217
options += rf_options
218-
options += ["--exclude", f"known issue {browser.replace('headless', '')}", "--exclude", "triage"]
218+
options += [
219+
"--exclude",
220+
f"known issue {browser.replace('headless', '')}",
221+
"--exclude",
222+
"triage",
223+
]
219224
command = runner
220225
if grid:
221226
command += [
@@ -259,7 +264,7 @@ def process_output(browser):
259264
return exit.code
260265

261266

262-
def create_zip(browser = None):
267+
def create_zip(browser=None):
263268
if os.path.exists(ZIP_DIR):
264269
shutil.rmtree(ZIP_DIR)
265270
os.mkdir(ZIP_DIR)

src/SeleniumLibrary/keywords/alert.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ def _wait_alert(self, timeout=None):
146146
try:
147147
return wait.until(EC.alert_is_present())
148148
except TimeoutException as original_exception:
149-
raise AssertionError(f"Alert not found in {secs_to_timestr(timeout)}.") from original_exception
149+
raise AssertionError(
150+
f"Alert not found in {secs_to_timestr(timeout)}."
151+
) from original_exception
150152
except WebDriverException as err:
151-
raise AssertionError(f"An exception occurred waiting for alert: {err}") from err
153+
raise AssertionError(
154+
f"An exception occurred waiting for alert: {err}"
155+
) from err

src/SeleniumLibrary/keywords/browsermanagement.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,17 @@ def open_browser(
217217
self.go_to(url)
218218
return index
219219
if desired_capabilities:
220-
self.warn("desired_capabilities has been deprecated and removed. Please use options to configure browsers as per documentation.")
220+
self.warn(
221+
"desired_capabilities has been deprecated and removed. Please use options to configure browsers as per documentation."
222+
)
221223
if service_log_path:
222-
self.warn("service_log_path is being deprecated. Please use service to configure log_output or equivalent service attribute.")
224+
self.warn(
225+
"service_log_path is being deprecated. Please use service to configure log_output or equivalent service attribute."
226+
)
223227
if executable_path:
224-
self.warn("executable_path is being deprecated. Please use service to configure the driver's executable_path as per documentation.")
228+
self.warn(
229+
"executable_path is being deprecated. Please use service to configure the driver's executable_path as per documentation."
230+
)
225231
return self._make_new_browser(
226232
url,
227233
browser,
@@ -280,7 +286,11 @@ def _make_new_browser(
280286

281287
@keyword
282288
def create_webdriver(
283-
self, driver_name: str, alias: str | None = None, kwargs: dict | None = None, **init_kwargs
289+
self,
290+
driver_name: str,
291+
alias: str | None = None,
292+
kwargs: dict | None = None,
293+
**init_kwargs,
284294
) -> str:
285295
"""Creates an instance of Selenium WebDriver.
286296
@@ -320,7 +330,9 @@ def create_webdriver(
320330
try:
321331
creation_func = getattr(webdriver, driver_name)
322332
except AttributeError as original_exception:
323-
raise RuntimeError(f"'{driver_name}' is not a valid WebDriver name.") from original_exception
333+
raise RuntimeError(
334+
f"'{driver_name}' is not a valid WebDriver name."
335+
) from original_exception
324336
self.info(f"Creating an instance of the {driver_name} WebDriver.")
325337
driver = creation_func(**init_kwargs)
326338
self.debug(
@@ -659,8 +671,7 @@ def set_action_chain_delay(self, value: timedelta) -> str:
659671

660672
@keyword
661673
def get_action_chain_delay(self):
662-
"""Gets the currently stored value for chain_delay_value in timestr format.
663-
"""
674+
"""Gets the currently stored value for chain_delay_value in timestr format."""
664675
return timestr_to_secs(f"{self.ctx.action_chain_delay} milliseconds")
665676

666677
@keyword

src/SeleniumLibrary/keywords/element.py

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def page_should_not_contain_element(
224224
self.assert_page_not_contains(locator, message=message, loglevel=loglevel)
225225

226226
@keyword
227-
def assign_id_to_element(self, locator: Locator, id: str): # noqa: A002
227+
def assign_id_to_element(self, locator: Locator, id: str): # noqa: A002
228228
"""Assigns a temporary ``id`` to the element specified by ``locator``.
229229
230230
This is mainly useful if the locator is complicated and/or slow XPath
@@ -286,9 +286,7 @@ def element_should_be_focused(self, locator: Locator):
286286
raise AssertionError(f"Element '{locator}' does not have focus.")
287287

288288
@keyword
289-
def element_should_be_visible(
290-
self, locator: Locator, message: str | None = None
291-
):
289+
def element_should_be_visible(self, locator: Locator, message: str | None = None):
292290
"""Verifies that the element identified by ``locator`` is visible.
293291
294292
Herein, visible means that the element is logically visible, not
@@ -398,9 +396,7 @@ def element_text_should_not_be(
398396
raise AssertionError(message)
399397

400398
@keyword
401-
def get_element_attribute(
402-
self, locator: Locator, attribute: str
403-
) -> str:
399+
def get_element_attribute(self, locator: Locator, attribute: str) -> str:
404400
"""Returns the value of ``attribute`` from the element ``locator``.
405401
406402
See the `Locating elements` section for details about the locator
@@ -416,9 +412,7 @@ def get_element_attribute(
416412
return self.find_element(locator).get_attribute(attribute)
417413

418414
@keyword
419-
def get_dom_attribute(
420-
self, locator: Locator, attribute: str
421-
) -> str:
415+
def get_dom_attribute(self, locator: Locator, attribute: str) -> str:
422416
"""Returns the value of ``attribute`` from the element ``locator``. `Get DOM Attribute` keyword
423417
only returns attributes declared within the element's HTML markup. If the requested attribute
424418
is not there, the keyword returns ${None}.
@@ -434,7 +428,9 @@ def get_dom_attribute(
434428

435429
@keyword
436430
def get_property(
437-
self, locator: Locator, property: str # noqa: A002
431+
self,
432+
locator: Locator,
433+
property: str, # noqa: A002
438434
) -> str:
439435
"""Returns the value of ``property`` from the element ``locator``.
440436
@@ -581,9 +577,7 @@ def get_vertical_position(self, locator: Locator) -> int:
581577
return self.find_element(locator).location["y"]
582578

583579
@keyword
584-
def click_button(
585-
self, locator: Locator, modifier: bool | str = False
586-
):
580+
def click_button(self, locator: Locator, modifier: bool | str = False):
587581
"""Clicks the button identified by ``locator``.
588582
589583
See the `Locating elements` section for details about the locator
@@ -605,9 +599,7 @@ def click_button(
605599
self._click_with_modifier(locator, ["button", "input"], modifier)
606600

607601
@keyword
608-
def click_image(
609-
self, locator: Locator, modifier: bool | str = False
610-
):
602+
def click_image(self, locator: Locator, modifier: bool | str = False):
611603
"""Clicks an image identified by ``locator``.
612604
613605
See the `Locating elements` section for details about the locator
@@ -630,9 +622,7 @@ def click_image(
630622
self._click_with_modifier(locator, ["image", "input"], modifier)
631623

632624
@keyword
633-
def click_link(
634-
self, locator: Locator, modifier: bool | str = False
635-
):
625+
def click_link(self, locator: Locator, modifier: bool | str = False):
636626
"""Clicks a link identified by ``locator``.
637627
638628
See the `Locating elements` section for details about the locator
@@ -774,12 +764,12 @@ def scroll_element_into_view(self, locator: Locator):
774764
New in SeleniumLibrary 3.2.0
775765
"""
776766
element = self.find_element(locator)
777-
ActionChains(self.driver, duration=self.ctx.action_chain_delay).move_to_element(element).perform()
767+
ActionChains(self.driver, duration=self.ctx.action_chain_delay).move_to_element(
768+
element
769+
).perform()
778770

779771
@keyword
780-
def drag_and_drop(
781-
self, locator: Locator, target: Locator
782-
):
772+
def drag_and_drop(self, locator: Locator, target: Locator):
783773
"""Drags the element identified by ``locator`` into the ``target`` element.
784774
785775
The ``locator`` argument is the locator of the dragged element
@@ -795,9 +785,7 @@ def drag_and_drop(
795785
action.drag_and_drop(element, target).perform()
796786

797787
@keyword
798-
def drag_and_drop_by_offset(
799-
self, locator: Locator, xoffset: int, yoffset: int
800-
):
788+
def drag_and_drop_by_offset(self, locator: Locator, xoffset: int, yoffset: int):
801789
"""Drags the element identified with ``locator`` by ``xoffset/yoffset``.
802790
803791
See the `Locating elements` section for details about the locator
@@ -869,7 +857,9 @@ def mouse_up(self, locator: Locator):
869857
"""
870858
self.info(f"Simulating Mouse Up on element '{locator}'.")
871859
element = self.find_element(locator)
872-
ActionChains(self.driver, duration=self.ctx.action_chain_delay).release(element).perform()
860+
ActionChains(self.driver, duration=self.ctx.action_chain_delay).release(
861+
element
862+
).perform()
873863

874864
@keyword
875865
def open_context_menu(self, locator: Locator):
@@ -988,7 +978,9 @@ def press_keys(self, locator: Locator | None = None, *keys: str):
988978
if not is_noney(locator):
989979
self.info(f"Sending key(s) {keys} to {locator} element.")
990980
element = self.find_element(locator)
991-
ActionChains(self.driver, duration=self.ctx.action_chain_delay).click(element).perform()
981+
ActionChains(self.driver, duration=self.ctx.action_chain_delay).click(
982+
element
983+
).perform()
992984
else:
993985
self.info(f"Sending key(s) {keys} to page.")
994986
element = None
@@ -1228,7 +1220,9 @@ def parse_modifier(self, modifier):
12281220
if hasattr(Keys, modifier):
12291221
keys.append(getattr(Keys, modifier))
12301222
else:
1231-
raise ValueError(f"'{modifier}' modifier does not match to Selenium Keys")
1223+
raise ValueError(
1224+
f"'{modifier}' modifier does not match to Selenium Keys"
1225+
)
12321226
return keys
12331227

12341228
def _parse_keys(self, *keys):
@@ -1271,18 +1265,20 @@ def _convert_special_keys(self, keys):
12711265
for key in keys:
12721266
resolved_key = self._parse_aliases(key)
12731267
if self._selenium_keys_has_attr(resolved_key):
1274-
converted_keys.append(self.KeysRecord(getattr(Keys, resolved_key), resolved_key, True))
1268+
converted_keys.append(
1269+
self.KeysRecord(getattr(Keys, resolved_key), resolved_key, True)
1270+
)
12751271
else:
1276-
converted_keys.append(self.KeysRecord(resolved_key, resolved_key, False))
1272+
converted_keys.append(
1273+
self.KeysRecord(resolved_key, resolved_key, False)
1274+
)
12771275
return converted_keys
12781276

12791277
def _selenium_keys_has_attr(self, key):
12801278
return hasattr(Keys, key)
12811279

12821280
@keyword("Get CSS Property Value")
1283-
def get_css_property_value(
1284-
self, locator: Locator, css_property: str
1285-
) -> str:
1281+
def get_css_property_value(self, locator: Locator, css_property: str) -> str:
12861282
"""Returns the computed value of ``css_property`` from the element ``locator``.
12871283
12881284
See the `Locating elements` section for details about the locator syntax.

src/SeleniumLibrary/keywords/expectedconditions.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
class ExpectedConditionKeywords(LibraryComponent):
2424
@keyword
25-
def wait_for_expected_condition(self, condition: string, *args, timeout: float | None=10):
25+
def wait_for_expected_condition(
26+
self, condition: string, *args, timeout: float | None = 10
27+
):
2628
"""Waits until ``condition`` is true or ``timeout`` expires.
2729
2830
The condition must be one of selenium's expected condition which
@@ -54,8 +56,13 @@ def wait_for_expected_condition(self, condition: string, *args, timeout: float |
5456
try:
5557
condition_func = getattr(EC, condition)
5658
except AttributeError as original_exception:
57-
raise UnkownExpectedCondition(f"{condition} is an unknown expected condition") from original_exception
58-
return wait.until(condition_func(*args), message=f"Expected Condition not met within set timeout of {timeout}s")
59+
raise UnkownExpectedCondition(
60+
f"{condition} is an unknown expected condition"
61+
) from original_exception
62+
return wait.until(
63+
condition_func(*args),
64+
message=f"Expected Condition not met within set timeout of {timeout}s",
65+
)
5966

6067
def _parse_condition(self, condition: string):
61-
return condition.replace(' ','_').lower()
68+
return condition.replace(" ", "_").lower()

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,7 @@ def choose_file(self, locator: Locator, file_path: str):
238238
self.ctx._running_keyword = None
239239

240240
@keyword
241-
def input_password(
242-
self, locator: Locator, password: str, clear: bool = True
243-
):
241+
def input_password(self, locator: Locator, password: str, clear: bool = True):
244242
"""Types the given password into the text field identified by ``locator``.
245243
246244
See the `Locating elements` section for details about the locator
@@ -268,9 +266,7 @@ def input_password(
268266
self._input_text_into_text_field(locator, password, clear, disable_log=True)
269267

270268
@keyword
271-
def input_text(
272-
self, locator: Locator, text: str, clear: bool = True
273-
):
269+
def input_text(self, locator: Locator, text: str, clear: bool = True):
274270
"""Types the given ``text`` into the text field identified by ``locator``.
275271
276272
When ``clear`` is true, the input element is cleared before
@@ -489,8 +485,7 @@ def _get_radio_button_with_value(self, group_name, value):
489485
return self.find_element(xpath)
490486
except ElementNotFound as original_exception:
491487
raise ElementNotFound(
492-
f"No radio button with name '{group_name}' "
493-
f"and value '{value}' found."
488+
f"No radio button with name '{group_name}' and value '{value}' found."
494489
) from original_exception
495490

496491
def _get_value_from_radio_buttons(self, elements):

src/SeleniumLibrary/keywords/javascript.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424

2525
class JavaScriptKeywords(LibraryComponent):
26-
2726
js_marker = "JAVASCRIPT"
2827
arg_marker = "ARGUMENTS"
2928

src/SeleniumLibrary/keywords/runonfailure.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ def resolve_keyword(name):
6464
if name is None:
6565
return None
6666
if (
67-
(isinstance(name, str)
68-
and name.upper() == "NOTHING")
69-
or name.upper() == "NONE"
70-
):
67+
isinstance(name, str) and name.upper() == "NOTHING"
68+
) or name.upper() == "NONE":
7169
return None
7270
return name

0 commit comments

Comments
 (0)