QWeb 3.0.1__tar.gz → 3.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. {QWeb-3.0.1 → QWeb-3.2.0}/PKG-INFO +1 -1
  2. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/__init__.py +2 -2
  3. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/__main__.py +1 -1
  4. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/_version.py +3 -3
  5. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/actions.py +43 -33
  6. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/bs_desktop.py +1 -1
  7. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/bs_mobile.py +1 -1
  8. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/config.py +7 -0
  9. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/decorators.py +1 -1
  10. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/download.py +1 -1
  11. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/element.py +22 -13
  12. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/frame.py +3 -3
  13. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/search_strategy.py +42 -17
  14. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/secrets.py +81 -3
  15. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/table.py +51 -15
  16. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/text.py +3 -2
  17. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/util.py +9 -1
  18. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/blocks.py +5 -5
  19. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/browser.py +1 -1
  20. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/config.py +38 -8
  21. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/cookies.py +10 -3
  22. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/element.py +6 -3
  23. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/input_.py +3 -3
  24. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/table.py +237 -12
  25. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/text.py +35 -2
  26. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/PKG-INFO +1 -1
  27. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/requires.txt +2 -2
  28. {QWeb-3.0.1 → QWeb-3.2.0}/setup.py +2 -2
  29. {QWeb-3.0.1 → QWeb-3.2.0}/LICENSE +0 -0
  30. {QWeb-3.0.1 → QWeb-3.2.0}/MANIFEST.in +0 -0
  31. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/custom_config.py +0 -0
  32. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/__init__.py +0 -0
  33. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/ajax.py +0 -0
  34. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/alert.py +0 -0
  35. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/blocks.py +0 -0
  36. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/__init__.py +0 -0
  37. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/android.py +0 -0
  38. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/chrome.py +0 -0
  39. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/edge.py +0 -0
  40. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/firefox.py +0 -0
  41. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/browser/safari.py +0 -0
  42. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/checkbox.py +0 -0
  43. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/config_defaults.py +0 -0
  44. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/cookies.py +0 -0
  45. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/dragdrop.py +0 -0
  46. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/dropdown.py +0 -0
  47. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/exceptions.py +0 -0
  48. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/file.py +0 -0
  49. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/frame_checker.py +0 -0
  50. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/icon.py +0 -0
  51. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/input_.py +0 -0
  52. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/input_handler.py +0 -0
  53. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/javascript.py +0 -0
  54. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/lists.py +0 -0
  55. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/meas.py +0 -0
  56. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/platform.py +0 -0
  57. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/screenshot.py +0 -0
  58. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/user.py +0 -0
  59. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/window.py +0 -0
  60. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/internal/xhr.py +0 -0
  61. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/__init__.py +0 -0
  62. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/ajax.py +0 -0
  63. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/alert.py +0 -0
  64. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/checkbox.py +0 -0
  65. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/debug.py +0 -0
  66. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/download.py +0 -0
  67. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/dragdrop.py +0 -0
  68. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/dropdown.py +0 -0
  69. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/file.py +0 -0
  70. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/frame.py +0 -0
  71. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/icon.py +0 -0
  72. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/javascript.py +0 -0
  73. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/lists.py +0 -0
  74. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/screenshot.py +0 -0
  75. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/search_strategy.py +0 -0
  76. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb/keywords/window.py +0 -0
  77. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/SOURCES.txt +0 -0
  78. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/dependency_links.txt +0 -0
  79. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/not-zip-safe +0 -0
  80. {QWeb-3.0.1 → QWeb-3.2.0}/QWeb.egg-info/top_level.txt +0 -0
  81. {QWeb-3.0.1 → QWeb-3.2.0}/README.md +0 -0
  82. {QWeb-3.0.1 → QWeb-3.2.0}/setup.cfg +0 -0
  83. {QWeb-3.0.1 → QWeb-3.2.0}/versioneer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: QWeb
3
- Version: 3.0.1
3
+ Version: 3.2.0
4
4
  Summary: Keyword driven automation for the web
5
5
  Home-page: https://github.com/qentinelqi/qweb/
6
6
  Author: Qentinel Group
@@ -316,8 +316,8 @@ class QWeb:
316
316
  eval(run_before) # pylint: disable=W0123
317
317
  else:
318
318
  BuiltIn().run_keyword(run_before)
319
- logger.trace(keyword_method)
320
- logger.trace(args, kwargs)
319
+ logger.trace(f"{keyword_method=}")
320
+ logger.trace(f"{args=}, {kwargs=}")
321
321
  return keyword_method(*args, **kwargs)
322
322
  except Exception as e: # pylint: disable=W0703
323
323
  logger.debug(traceback.format_exc())
@@ -17,7 +17,7 @@
17
17
  import argparse
18
18
  import sys
19
19
  from ._version import get_versions # pylint: disable-msg=E0611
20
- from robot import libdoc
20
+ from robot import libdoc # type: ignore
21
21
 
22
22
 
23
23
  def cli() -> None:
@@ -8,11 +8,11 @@ import json
8
8
 
9
9
  version_json = '''
10
10
  {
11
- "date": "2023-12-21T09:48:25+0200",
11
+ "date": "2024-03-08T14:03:57+0200",
12
12
  "dirty": false,
13
13
  "error": null,
14
- "full-revisionid": "0d2fc1192cb3a86df20921256ec7c00d6f694a56",
15
- "version": "v3.0.1"
14
+ "full-revisionid": "a1077ceb7dc7393d4a0a502db68bae57f5983409",
15
+ "version": "v3.2.0"
16
16
  }
17
17
  ''' # END VERSION_JSON
18
18
 
@@ -74,7 +74,7 @@ def write(
74
74
  logger.debug("Could not send line break key to input")
75
75
  else:
76
76
  input_handler.write(input_element, input_text, **kwargs)
77
- logger.debug('Preferred text: "{}"'.format(input_text))
77
+ logger.debug(f'Preferred text: "{input_text}"')
78
78
 
79
79
 
80
80
  @decorators.timeout_decorator_for_actions
@@ -91,11 +91,12 @@ def compare_input_values(
91
91
  expected_value = str(util.get_substring(expected_value, **kwargs))
92
92
  except QWebValueError:
93
93
  real_value = ""
94
- logger.debug('Real value: {}, expected value {}'.format(real_value, expected_value))
94
+ logger.debug(f'Real value: {real_value}, expected value {expected_value}')
95
95
  if fnmatch.fnmatch(str(real_value).strip(), expected_value):
96
96
  return True
97
- raise QWebValueMismatchError('Expected value "{}" didn\'t match to real value "{}"'.format(
98
- expected_value, real_value))
97
+ raise QWebValueMismatchError(
98
+ f"""Expected value "{expected_value}" didn\'t match to real value "{real_value}\""""
99
+ )
99
100
 
100
101
 
101
102
  @decorators.timeout_decorator_for_actions
@@ -111,7 +112,7 @@ def input_value(input_element: WebElement, timeout: int, **kwargs: Any) -> str:
111
112
  return value.strip()
112
113
  if blind:
113
114
  return ''
114
- raise QWebValueError('No Value found after {} sec'.format(timeout))
115
+ raise QWebValueError(f'No Value found after {timeout} sec')
115
116
 
116
117
 
117
118
  @decorators.timeout_decorator_for_actions
@@ -146,7 +147,7 @@ def execute_click_and_verify_condition(web_element: WebElement,
146
147
  wd_click(web_element, **kwargs)
147
148
  logger.debug('element clicked')
148
149
  except WebDriverException as e:
149
- logger.info('Got {} when tried to click.'.format(e))
150
+ logger.info(f'Got {e} when tried to click.')
150
151
  if 'text' not in kwargs:
151
152
  raise e
152
153
  if 'text' in kwargs:
@@ -195,7 +196,7 @@ def wd_click(web_element: WebElement, **kwargs: Any) -> None:
195
196
  try:
196
197
  web_element.click()
197
198
  except WebDriverException as e:
198
- logger.debug(e)
199
+ logger.debug(str(e))
199
200
  js_click_on_failure = util.par2bool(kwargs.get('js_click', True))
200
201
  if js_click_on_failure:
201
202
  js_click(web_element)
@@ -287,8 +288,9 @@ def is_not_in_dropdown(select: Select, option: str, **kwargs: Any) -> bool:
287
288
  """"Verifies that the selected option is not in the dropdown list"""
288
289
  option_list = get_select_options(select, **kwargs)
289
290
  if option in option_list:
290
- raise QWebValueError("Found the value {} from the dropdown menu: {}.".format(
291
- option, option_list))
291
+ raise QWebValueError(
292
+ f"Found the value {option} from the dropdown menu: {option_list}."
293
+ )
292
294
  return True
293
295
 
294
296
 
@@ -314,8 +316,9 @@ def get_selected_value(
314
316
  if expected:
315
317
  if expected in selected:
316
318
  return True
317
- raise QWebValueMismatchError('Expected value "{}" didn\'t match to real value "{}".'.format(
318
- expected, txt_selected))
319
+ raise QWebValueMismatchError(
320
+ f"""Expected value "{expected}" didn\'t match to real value "{txt_selected}"."""
321
+ )
319
322
  return txt_selected
320
323
 
321
324
 
@@ -331,7 +334,7 @@ def get_select_options(
331
334
  if fnmatch.fnmatch(expected, option.text):
332
335
  return True
333
336
  raise QWebValueMismatchError(
334
- 'Expected value "{}" not found from selectable options'.format(expected))
337
+ f'Expected value "{expected}" not found from selectable options')
335
338
  # parse all options to a list and return it
336
339
  option_list = []
337
340
  for option in options:
@@ -390,7 +393,7 @@ def get_element_text(web_element: WebElement, expected=None, timeout: int = 0) -
390
393
  try:
391
394
  return _compare_texts(real_text, expected.strip(), timeout)
392
395
  except QWebValueMismatchError as e:
393
- raise QWebValueError('Expected {}, found {}'.format(expected, real_text)) from e
396
+ raise QWebValueError(f'Expected {expected}, found {real_text}') from e
394
397
  if real_text is not None:
395
398
  return real_text
396
399
  raise QWebValueMismatchError('Text not found')
@@ -398,7 +401,7 @@ def get_element_text(web_element: WebElement, expected=None, timeout: int = 0) -
398
401
 
399
402
  def _compare_texts(text_to_compare: str, expected: str, timeout: int) -> bool: # pylint: disable=unused-argument
400
403
  if fnmatch.fnmatch(text_to_compare, expected) is False:
401
- raise QWebValueMismatchError('Expected {0}, found {1}'.format(expected, text_to_compare))
404
+ raise QWebValueMismatchError(f'Expected {expected}, found {text_to_compare}')
402
405
  return True
403
406
 
404
407
 
@@ -447,7 +450,7 @@ def scroll_first_scrollable_parent_element(locator: str, anchor: str, text_to_fi
447
450
  return getScrollParent(arguments[0]);
448
451
  """
449
452
  js_element_position = "return arguments[0].scrollTop;"
450
- js_element_scroll = "arguments[0].scrollBy(0, {})".format(scroll_length or '1000')
453
+ js_element_scroll = f"arguments[0].scrollBy(0, {scroll_length or '1000'})"
451
454
  web_element = internal_text.get_element_by_locator_text(locator, anchor)
452
455
  scrollable_element = javascript.execute_javascript(js_get_parent_element, web_element)
453
456
  current_pos = javascript.execute_javascript(js_element_position, scrollable_element)
@@ -461,22 +464,25 @@ def scroll_first_scrollable_parent_element(locator: str, anchor: str, text_to_fi
461
464
  current_pos = javascript.execute_javascript(js_element_position, scrollable_element)
462
465
  visible = internal_text.get_element_by_locator_text(text_to_find,
463
466
  allow_non_existent=True)
464
- logger.info('Old pos: {}\nNew pos: {}\nVisible: {}'.format(
465
- old_pos, current_pos, visible),
466
- also_console=True)
467
+ logger.info(
468
+ f'Old pos: {old_pos}\nNew pos: {current_pos}\nVisible: {visible}',
469
+ also_console=True,
470
+ )
467
471
  else:
468
- logger.info('\nSlow mode is on, execution will only stop if the text "{}" is found or if '
469
- 'the timeout is reached.'.format(text_to_find),
470
- also_console=True)
472
+ logger.info(
473
+ f'\nSlow mode is on, execution will only stop if the text "{text_to_find}" '
474
+ ' is found or if the timeout is reached.',
475
+ also_console=True,
476
+ )
471
477
  while not visible and time.time() < float(timeout) + start:
472
478
  javascript.execute_javascript(js_element_scroll, scrollable_element)
473
479
  time.sleep(.5)
474
480
  visible = internal_text.get_element_by_locator_text(text_to_find,
475
481
  allow_non_existent=True)
476
- logger.info('\nVisible: {}'.format(visible), also_console=True)
482
+ logger.info(f'\nVisible: {visible}', also_console=True)
477
483
  if visible:
478
484
  return
479
- raise QWebTextNotFoundError('Text {} not found.'.format(text_to_find))
485
+ raise QWebTextNotFoundError(f'Text {text_to_find} not found.')
480
486
 
481
487
 
482
488
  def scroll_dynamic_web_page(text_to_find: str, scroll_length: Optional[Union[int, str]],
@@ -485,7 +491,7 @@ def scroll_dynamic_web_page(text_to_find: str, scroll_length: Optional[Union[int
485
491
  js_browser_height = "return window.innerHeight"
486
492
  height = javascript.execute_javascript(js_browser_height) # Length of one scroll
487
493
  js_current_pos = "return window.pageYOffset;"
488
- js_scroll = 'window.scrollBy(0,{})'.format(scroll_length or height)
494
+ js_scroll = f'window.scrollBy(0,{scroll_length or height})'
489
495
  current_pos = javascript.execute_javascript(js_current_pos)
490
496
  old_pos = None
491
497
  start = time.time()
@@ -497,21 +503,25 @@ def scroll_dynamic_web_page(text_to_find: str, scroll_length: Optional[Union[int
497
503
  current_pos = javascript.execute_javascript(js_current_pos)
498
504
  visible = internal_text.get_element_by_locator_text(text_to_find,
499
505
  allow_non_existent=True)
500
- logger.info('\nOld pos: {}\nCurrent pos: {}\nVisible: {}'.format(
501
- old_pos, current_pos, visible),
502
- also_console=True)
506
+ logger.info(
507
+ f'\nOld pos: {old_pos}\nCurrent pos: {current_pos}\nVisible: {visible}',
508
+ also_console=True,
509
+ )
503
510
  else:
504
- logger.info('\nSlow mode is on, execution will only stop if the text "{}" is found or if '
505
- 'the timeout is reached.'.format(text_to_find),
506
- also_console=True)
511
+ logger.info(
512
+ '\nSlow mode is on, execution will only stop if '
513
+ f'the text "{text_to_find}" is found or if the timeout is reached.',
514
+ also_console=True,
515
+ )
507
516
  while not visible and time.time() < float(timeout) + start:
508
517
  javascript.execute_javascript(js_scroll)
509
518
  time.sleep(.5)
510
519
  visible = internal_text.get_element_by_locator_text(text_to_find,
511
520
  allow_non_existent=True)
512
- logger.info('\nVisible: {}'.format(visible), also_console=True)
521
+ logger.info(f'\nVisible: {visible}', also_console=True)
513
522
 
514
523
  if visible:
515
524
  return True
516
- raise QWebTextNotFoundError('Could not find text "{}" after scrolling for {} pixels.'.format(
517
- text_to_find, current_pos))
525
+ raise QWebTextNotFoundError(
526
+ f'Could not find text "{text_to_find}" after scrolling for {current_pos} pixels.'
527
+ )
@@ -72,7 +72,7 @@ def open_browser(bs_browser: str, project_name: str, run_id: str, **kwargs: Any)
72
72
  driver = webdriver.Remote(command_executor=executor_url, options=options)
73
73
  logger.info(f'BrowserStack session ID: {driver.session_id}', also_console=True)
74
74
  except WebDriverException as e:
75
- logger.error(e)
75
+ logger.error(str(e))
76
76
  raise exceptions.QWebException('Incorrect Browserstack capabilities.')
77
77
  browser.cache_browser(driver)
78
78
  return driver
@@ -48,7 +48,7 @@ def open_browser(bs_device: str, project_name: str, run_id: str, **kwargs: Any)
48
48
 
49
49
  logger.info(f'BrowserStack session ID: {driver.session_id}', also_console=True)
50
50
  except WebDriverException as e:
51
- logger.error(e)
51
+ logger.error(str(e))
52
52
  raise exceptions.QWebException('Incorrect Browserstack capabilities.')
53
53
  browser.cache_browser(driver)
54
54
  return driver
@@ -102,3 +102,10 @@ class Config:
102
102
  trans_table = str.maketrans(dropped_chars_dict)
103
103
  _string_value = string_value.lower().translate(trans_table)
104
104
  return _string_value
105
+
106
+ def enforce_direction(self) -> bool:
107
+ search_direction = self.get_value("SearchDirection")
108
+ if search_direction:
109
+ return search_direction.endswith("!")
110
+
111
+ return False
@@ -79,7 +79,7 @@ def timeout_decorator(fn: Callable[..., Any]) -> Callable[..., Any]:
79
79
  CONFIG.set_value("OSScreenshots", True)
80
80
  raise QWebBrowserError(e) # pylint: disable=W0707
81
81
  logger.debug('From timeout decorator: Webdriver exception. Retrying..')
82
- logger.debug(e)
82
+ logger.debug(str(e))
83
83
  time.sleep(SHORT_DELAY)
84
84
  err = QWebDriverError
85
85
  msg = e
@@ -128,7 +128,7 @@ def get_path(filename: str) -> Path:
128
128
  paths = [downloads, files, images, files_exec_dir, images_exec_dir]
129
129
 
130
130
  for path in paths:
131
- logger.debug(path)
131
+ logger.debug(f"{path=}")
132
132
  if path.exists():
133
133
  logger.debug(f"Path exists: {path}")
134
134
  return path
@@ -31,6 +31,7 @@ from QWeb.internal import browser, javascript, util
31
31
  from QWeb.internal.config_defaults import CONFIG
32
32
 
33
33
  ACTIVE_AREA_FUNCTION: Optional[Callable[..., Any]] = None
34
+ DEFAULT_DISTANCE = 1000000.0 # Just some large number
34
35
 
35
36
 
36
37
  def is_enabled(element: WebElement) -> bool:
@@ -103,7 +104,7 @@ def get_closest_element(locator_element: WebElement,
103
104
  if not candidate_elements:
104
105
  raise QWebElementNotFoundError('No elements visible')
105
106
  closest_element_list = []
106
- closest_distance = 1000000.0 # Just some large number
107
+ closest_distance = DEFAULT_DISTANCE
107
108
  for candidate_element in candidate_elements:
108
109
  element_info = _list_info(candidate_element)
109
110
  logger.debug("Measuring distance for: {}".format(element_info))
@@ -119,11 +120,17 @@ def get_closest_element(locator_element: WebElement,
119
120
  elif distance < closest_distance:
120
121
  closest_distance = distance
121
122
  closest_element_list = [candidate_element]
123
+ # if search direction is "forced" and closest distance is in default value
124
+ # then we don't have the element on correct direction from the anchor
125
+ enforce_direction = CONFIG.enforce_direction()
126
+ if enforce_direction and closest_distance == DEFAULT_DISTANCE:
127
+ logger.debug(f'No elements in expected direction {CONFIG.get_value("SearchDirection")}')
128
+ raise QWebElementNotFoundError("No elements found in enforced direction")
122
129
 
123
130
  closest_element = _get_closest_ortho_element(locator_element, closest_element_list)
124
131
 
125
- logger.debug("Closest distance found is {}".format(closest_distance))
126
- logger.debug("Closest element is: {}".format(_list_info(closest_element)))
132
+ logger.debug(f"Closest distance found is {closest_distance}")
133
+ logger.debug(f"Closest element is: {_list_info(closest_element)}")
127
134
  return closest_element
128
135
 
129
136
 
@@ -360,7 +367,7 @@ def _calculate_closest_distance(element1: WebElement, element2: WebElement) -> f
360
367
  search_direction = CONFIG["SearchDirection"]
361
368
  corners_locations1 = _get_corners_locations(element1)
362
369
  corners_locations2 = _get_corners_locations(element2)
363
- closest_distance = 1000000.0 # Some large number
370
+ closest_distance = DEFAULT_DISTANCE
364
371
  for corner1 in corners_locations1:
365
372
  for corner2 in corners_locations2:
366
373
  distance = _manhattan_distance(corner1['x'], corner1['y'], corner2['x'], corner2['y'])
@@ -369,26 +376,28 @@ def _calculate_closest_distance(element1: WebElement, element2: WebElement) -> f
369
376
  # small y is above
370
377
  angle = math.degrees(
371
378
  math.atan2(corner2['y'] - corner1['y'], corner2['x'] - corner1['x']))
372
- if search_direction == 'down':
379
+
380
+ if search_direction in ('down', 'down!'):
373
381
  if not 5 < angle < 175:
374
382
  logger.debug(
375
383
  'Search direction is {} and element is not in arc'.format(search_direction))
376
- distance = 1000000.0
377
- elif search_direction == 'up':
384
+ distance = DEFAULT_DISTANCE
385
+ elif search_direction in ('up', 'up!'):
378
386
  if not -175 < angle < -5:
379
387
  logger.debug(
380
388
  'Search direction is {} and element is not in arc'.format(search_direction))
381
- distance = 1000000.0
382
- elif search_direction == 'left':
389
+ distance = DEFAULT_DISTANCE
390
+ elif search_direction in ('left', 'left!'):
383
391
  if not abs(angle) > 95:
384
392
  logger.debug(
385
393
  'Search direction is {} and element is not in arc'.format(search_direction))
386
- distance = 1000000.0
387
- elif search_direction == 'right':
394
+ distance = DEFAULT_DISTANCE
395
+ elif search_direction in ('right', 'right!'):
388
396
  if not -85 < angle < 85:
389
397
  logger.debug(
390
398
  'Search direction is {} and element is not in arc'.format(search_direction))
391
- distance = 1000000.0
399
+ distance = DEFAULT_DISTANCE
400
+
392
401
  if closest_distance > distance > 0:
393
402
  closest_distance = distance
394
403
  return closest_distance
@@ -517,7 +526,7 @@ def _get_closest_ortho_element(locator_element: WebElement,
517
526
  elif list_len == 0:
518
527
  raise IndexError
519
528
 
520
- closest_distance = 1000000.0
529
+ closest_distance = DEFAULT_DISTANCE
521
530
  for candidate_element in element_list:
522
531
  distance = _calculate_closest_ortho_distance(locator_element, candidate_element)
523
532
  logger.debug("Candidate {}: horizontal distance: {}".format(candidate_element, distance))
@@ -75,7 +75,7 @@ def wait_page_loaded() -> None:
75
75
  try:
76
76
  xhr.wait_xhr(timestr_to_secs(timeout))
77
77
  except (WebDriverException, QWebDriverError) as e:
78
- logger.info('Unable to check AJAX requests due error: {}'.format(e))
78
+ logger.debug(f'Unable to check AJAX requests due error: {e}')
79
79
 
80
80
 
81
81
  def get_raw_html() -> str:
@@ -187,7 +187,7 @@ def all_frames(fn: Callable[..., Any]) -> Callable[..., Any]:
187
187
  driver.switch_to.frame(current_frame)
188
188
  logger.debug('switching to childframe {}'.format(str(fn)))
189
189
  except (StaleElementReferenceException, WebDriverException) as e:
190
- logger.debug(e)
190
+ logger.debug(str(e))
191
191
  driver.switch_to.default_content()
192
192
  raise e
193
193
  try:
@@ -235,7 +235,7 @@ def all_frames(fn: Callable[..., Any]) -> Callable[..., Any]:
235
235
  driver.switch_to.frame(current_frame)
236
236
  logger.debug('switching to childframe {}'.format(str(fn)))
237
237
  except (StaleElementReferenceException, WebDriverException) as e:
238
- logger.debug(e)
238
+ logger.debug(str(e))
239
239
  driver.switch_to.default_content()
240
240
  raise e
241
241
  try:
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
  # ---------------------------
17
17
  from typing import Any
18
+
18
19
  # pylint: disable=line-too-long
19
20
  import re
20
21
  import string
@@ -26,7 +27,7 @@ class SearchStrategies:
26
27
  MATCHING_INPUT_ELEMENT: str = '//*[(self::input or self::textarea) and (normalize-space(@placeholder)="{0}" or normalize-space(@value)="{0}")]'
27
28
  CONTAINING_INPUT_ELEMENT: str = '//*[(self::input or self::textarea) and (contains(normalize-space(@placeholder),"{0}") or contains(normalize-space(@value),"{0}"))]'
28
29
 
29
- ACTIVE_AREA_XPATH: str = '//body'
30
+ ACTIVE_AREA_XPATH: str = "//body"
30
31
 
31
32
  TEXT_MATCH: str = '//*[not(self::script) and normalize-space(translate(., "\u00a0", " "))="{0}" and not(descendant::*[normalize-space(translate(., "\u00a0", " "))="{0}"])]|//input[(@type="button" or @type="reset" or @type="submit" or @type="checkbox") and normalize-space(translate(@value, "\u00a0", " "))="{0}"]'
32
33
 
@@ -46,7 +47,7 @@ class SearchStrategies:
46
47
  "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÅ", "abcdefghijklmnopqrstuvwxyzäöå"), \
47
48
  translate("{0}", "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÅ", "abcdefghijklmnopqrstuvwxyzäöå"))]'
48
49
 
49
- IS_MODAL_XPATH = '//body'
50
+ IS_MODAL_XPATH = "//body"
50
51
 
51
52
  @staticmethod
52
53
  def active_area_xpath_validation(xpath: str) -> str:
@@ -58,7 +59,7 @@ class SearchStrategies:
58
59
 
59
60
  @staticmethod
60
61
  def matching_input_element_validation(xpath: str) -> str:
61
- if xpath == 'containing input element':
62
+ if xpath == "containing input element":
62
63
  xpath = SearchStrategies.CONTAINING_INPUT_ELEMENT
63
64
  SearchStrategies.verify_format_string(xpath, 1)
64
65
  return SearchStrategies.clear_xpath(xpath)
@@ -74,13 +75,23 @@ class SearchStrategies:
74
75
  @staticmethod
75
76
  def clear_xpath(xpath: str) -> str:
76
77
  if re.match("xpath *=", xpath, re.IGNORECASE):
77
- return ''.join(xpath.split('=')[1:])
78
+ return "".join(xpath.split("=")[1:])
78
79
  return xpath
79
80
 
80
81
  @staticmethod
81
82
  def search_direction_validation(direction: str) -> str:
82
- """ Validates the search direction configuration """
83
- valid_directions = ["up", "down", "left", "right", "closest"]
83
+ """Validates the search direction configuration"""
84
+ valid_directions = [
85
+ "up",
86
+ "down",
87
+ "left",
88
+ "right",
89
+ "closest",
90
+ "up!",
91
+ "down!",
92
+ "left!",
93
+ "right!",
94
+ ]
84
95
  direction = direction.lower()
85
96
  if direction not in valid_directions:
86
97
  raise ValueError("Wrong search direction")
@@ -89,8 +100,8 @@ class SearchStrategies:
89
100
  @staticmethod
90
101
  def _continuous_set(s: set, num: int) -> bool:
91
102
  """Verifies that a set has given number of continous values
92
- starting from 0. E.g. 0,1,2,3 is 4 continuous values whereas
93
- 0,1,3,4 is not.
103
+ starting from 0. E.g. 0,1,2,3 is 4 continuous values whereas
104
+ 0,1,3,4 is not.
94
105
  """
95
106
 
96
107
  return set.intersection(s, set(range(num))) == set(range(num))
@@ -120,7 +131,7 @@ class SearchStrategies:
120
131
  continuous = False
121
132
  for elem in parsed:
122
133
  # field_name '' matches {}
123
- if elem[1] == '':
134
+ if elem[1] == "":
124
135
  empty_placeholders += 1
125
136
  # field_name '0' matches {0} etc.
126
137
  elif elem[1] and elem[1].isnumeric():
@@ -129,15 +140,29 @@ class SearchStrategies:
129
140
  # Position placeholders are in a set. They must start from zero
130
141
  # so that we have {0}'s, {1}'s etc.
131
142
  if index_placeholders:
132
- continuous = SearchStrategies._continuous_set(index_placeholders, placeholder_num)
143
+ continuous = SearchStrategies._continuous_set(
144
+ index_placeholders, placeholder_num
145
+ )
133
146
 
134
147
  if placeholder_num != (empty_placeholders + len(index_placeholders)):
135
- raise ValueError("xpath has invalid number of placeholders, got {}, {}".format(
136
- empty_placeholders, len(index_placeholders)))
137
-
138
- if empty_placeholders == placeholder_num or \
139
- len(index_placeholders) == placeholder_num and continuous:
148
+ raise ValueError(
149
+ "xpath has invalid number of placeholders, got {}, {}".format(
150
+ empty_placeholders, len(index_placeholders)
151
+ )
152
+ )
153
+
154
+ if (
155
+ empty_placeholders == placeholder_num
156
+ or len(index_placeholders) == placeholder_num
157
+ and continuous
158
+ ):
140
159
  pass
141
160
  else:
142
- raise ValueError("xpath should contain {} placeholders, got {}, {}, {}".format(
143
- placeholder_num, empty_placeholders, len(index_placeholders), continuous))
161
+ raise ValueError(
162
+ "xpath should contain {} placeholders, got {}, {}, {}".format(
163
+ placeholder_num,
164
+ empty_placeholders,
165
+ len(index_placeholders),
166
+ continuous,
167
+ )
168
+ )
@@ -62,7 +62,15 @@ def _replace_keyword_args(keyword: Keyword, args: tuple) -> None:
62
62
 
63
63
 
64
64
  def _hide_keyword_arg_values(keyword: Keyword) -> list[str]:
65
- par_index, secret = filtered_keywords[keyword.kwname]
65
+ if hasattr(keyword, 'kwname'):
66
+ par_index, secret = filtered_keywords[keyword.kwname]
67
+ else: # rfw 7
68
+ # name is in different format
69
+ kw_name = ''.join(
70
+ f' {char}' if char.isupper() else char.strip()
71
+ for char in keyword.name
72
+ ).strip()
73
+ par_index, secret = filtered_keywords[kw_name]
66
74
  censored_args = list(keyword.args)
67
75
  if secret == 'hint':
68
76
  censored_args[par_index] = 'SECRET'
@@ -101,6 +109,39 @@ def _filtered_start_keyword(keyword: Keyword) -> None:
101
109
  LOGGER._other_loggers[0].log_message = lambda x: None
102
110
 
103
111
 
112
+ def _filtered_start_library_keyword(data: Keyword, implementation: Keyword, result: Keyword):
113
+ """Modify Robot FW 7+ internal function "start_library_keyword".
114
+
115
+ This function removes secret data from "start library keyword"
116
+ logs and disables logging during the keyword.
117
+ """
118
+ # pylint: disable=protected-access, global-statement
119
+ global log_level
120
+ # using implementation.name as data.name is in slightly different format
121
+ apply_filter = implementation.name in filtered_keywords
122
+ original_args = data.args
123
+
124
+ if apply_filter:
125
+ censored_args = _hide_keyword_arg_values(data)
126
+ _hide_keyword_arg_values(result)
127
+ _replace_keyword_args(data, tuple(censored_args))
128
+ _replace_keyword_args(result, tuple(censored_args))
129
+
130
+ LOGGER._started_keywords += 1
131
+ LOGGER.log_message = LOGGER._log_message
132
+ for start_logger in LOGGER.start_loggers:
133
+ start_logger.start_library_keyword(data, implementation, result)
134
+
135
+ if apply_filter:
136
+ _replace_keyword_args(data, tuple(original_args))
137
+ b = BuiltIn()
138
+ # Disable logging and store previous log level
139
+ if 'INFO' not in b.get_variables()['${LOG_LEVEL}']:
140
+ log_level = b.set_log_level("INFO")
141
+ if debugfile_log:
142
+ LOGGER._other_loggers[0].log_message = lambda x: None
143
+
144
+
104
145
  def _filtered_end_keyword(keyword: Keyword) -> None:
105
146
  """Modify Robot FW internal function "end_keyword".
106
147
 
@@ -130,6 +171,37 @@ def _filtered_end_keyword(keyword: Keyword) -> None:
130
171
  LOGGER._other_loggers[0].log_message = debugfile_log
131
172
 
132
173
 
174
+ def _filtered_end_library_keyword(data: Keyword, implementation: Keyword, result: Keyword) -> None:
175
+ """Modify Robot FW 7+ internal function "end_library_keyword".
176
+
177
+ This function removes secret data from "end library keyword"
178
+ logs and returns previous log level.
179
+ """
180
+ # pylint: disable=protected-access, global-statement
181
+ apply_filter = result.name in filtered_keywords
182
+ original_args = result.args
183
+ if apply_filter:
184
+ censored_args = _hide_keyword_arg_values(result)
185
+ _hide_keyword_arg_values(data)
186
+ _replace_keyword_args(result, tuple(censored_args))
187
+ _replace_keyword_args(data, tuple(censored_args))
188
+
189
+ LOGGER._started_keywords -= 1
190
+ for end_logger in LOGGER.end_loggers:
191
+ end_logger.end_library_keyword(data, implementation, result)
192
+
193
+ if not LOGGER._started_keywords:
194
+ LOGGER.log_message = LOGGER.message
195
+
196
+ if apply_filter:
197
+ _replace_keyword_args(result, tuple(original_args))
198
+ b = BuiltIn()
199
+ # Return previous log level
200
+ b.set_log_level(log_level)
201
+ if debugfile_log:
202
+ LOGGER._other_loggers[0].log_message = debugfile_log
203
+
204
+
133
205
  def add_filter(keyword_name: str, par_index: int, secret: Optional[str]) -> None:
134
206
  """Add keyword to secrets filtering.
135
207
 
@@ -152,5 +224,11 @@ except IndexError:
152
224
  debugfile_log = False
153
225
 
154
226
  # Monkey patch Robot FW methods
155
- LOGGER.start_keyword = _filtered_start_keyword
156
- LOGGER.end_keyword = _filtered_end_keyword
227
+ rfw_major_version, *_ = BuiltIn.ROBOT_LIBRARY_VERSION.split('.', maxsplit=1)
228
+ rfw_major_version = int(rfw_major_version)
229
+ if rfw_major_version < 7:
230
+ LOGGER.start_keyword = _filtered_start_keyword
231
+ LOGGER.end_keyword = _filtered_end_keyword
232
+ else:
233
+ LOGGER.start_library_keyword = _filtered_start_library_keyword
234
+ LOGGER.end_library_keyword = _filtered_end_library_keyword