Skip to content

Commit c07b719

Browse files
Add match_case parameter to ClickCombo and related methods for case-sensitive selection
1 parent 3c141ff commit c07b719

2 files changed

Lines changed: 28 additions & 15 deletions

File tree

tir/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,22 +1777,26 @@ def InputValue(self, field='', value='', position=1):
17771777
"""
17781778
self.__poui.InputValue(field, value, position)
17791779

1780-
def ClickCombo(self, field='', value='', position=1, second_value=''):
1780+
def ClickCombo(self, field='', value='', position=1, second_value='', match_case=True):
17811781
"""
17821782
Clicks on the Combo of POUI component.
17831783
https://po-ui.io/documentation/po-combo
17841784
17851785
:param field: Combo text title that you want to click.
17861786
:param value: Value that you want to select in Combo.
17871787
:param position: Position which element is located. - **Default:** 1
1788+
:param second_value: Secondary value displayed below the main value. - **Default:** "" (empty string)
1789+
:type second_value: str
1790+
:param match_case: If True, requires exact normalized match; if False, allows partial normalized match. - **Default:** True
1791+
:type match_case: bool
17881792
17891793
Usage:
17901794
17911795
>>> # Call the method:
17921796
>>> oHelper.ClickCombo('Visão', 'Compras')
17931797
:return:
17941798
"""
1795-
self.__poui.click_combo(field, value, position, second_value)
1799+
self.__poui.click_combo(field, value, position, second_value, match_case)
17961800

17971801
def ClickSelect(self, field='', value='', position=1):
17981802
"""

tir/technologies/poui_internal.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,7 +4736,7 @@ def click_checkbox(self, label):
47364736
self.log_error(f"CheckBox '{label}' doesn't found!")
47374737

47384738

4739-
def click_combo(self, field, value='', position=1, second_value=''):
4739+
def click_combo(self, field, value='', position=1, second_value='', match_case=True):
47404740
'''Select a value for list combo inputs.
47414741
47424742
:param field: label of field
@@ -4747,6 +4747,8 @@ def click_combo(self, field, value='', position=1, second_value=''):
47474747
:type : int
47484748
:param second_value: value below the principal value (after the ":")
47494749
:type : str
4750+
:param match_case: If True, requires exact normalized match; if False, allows partial normalized match.
4751+
:type : bool
47504752
:return:
47514753
'''
47524754

@@ -4773,27 +4775,29 @@ def click_combo(self, field, value='', position=1, second_value=''):
47734775
main_value = self.get_web_value(self.soup_to_selenium(po_input, twebview=True))
47744776
self.open_input_combo(po_combo_filtred)
47754777
self.send_keys(po_input_sel, value if value else second_value)
4776-
self.click_po_list_box(value, second_value)
4778+
self.click_po_list_box(value, second_value, match_case=match_case)
47774779
current_value = self.get_web_value(self.soup_to_selenium(po_input, twebview=True))
47784780
success = current_value.strip().lower() == main_value.strip().lower() if value else True
47794781

47804782
if not success:
47814783
self.log_error(f'Click on {value} of {field} Fail. Please Check')
47824784

4783-
def click_po_list_box(self, value="", second_value="", program_call=False) -> None:
4785+
def click_po_list_box(self, value="", second_value="", program_call=False, match_case=True) -> None:
47844786
'''
47854787
:param value: Value to select on po-list-box
47864788
:type str
47874789
:param second_value: value below the principal value (after the ":")
47884790
:type : str
4791+
:param match_case: If True, requires exact normalized match; if False, allows partial normalized match.
4792+
:type : bool
47894793
:return:
47904794
'''
47914795
orig_value = value
47924796
orig_second_value = second_value
47934797
value = value.strip().lower()
47944798
second_value = second_value.strip().lower()
47954799

4796-
po_item_list = self._get_po_item_list(value, second_value)
4800+
po_item_list = self._get_po_item_list(value, second_value, match_case=match_case)
47974801

47984802
if not po_item_list:
47994803
message = f"Item list '{orig_value or orig_second_value}' not found"
@@ -4807,7 +4811,7 @@ def click_po_list_box(self, value="", second_value="", program_call=False) -> No
48074811
self.click(self.soup_to_selenium(po_item_list_div, twebview=True))
48084812

48094813

4810-
def _get_po_item_list(self, value="", second_value="") -> Tag:
4814+
def _get_po_item_list(self, value="", second_value="", match_case=True) -> Tag:
48114815
"""
48124816
[Internal]
48134817
@@ -4817,18 +4821,20 @@ def _get_po_item_list(self, value="", second_value="") -> Tag:
48174821
:type value: str
48184822
:param second_value: Secondary value to search for (value field). - **Default:** ""
48194823
:type second_value: str
4824+
:param match_case: If True, requires exact normalized match; if False, allows partial normalized match. - **Default:** True
4825+
:type match_case: bool
48204826
:return: The BeautifulSoup Tag object of the matching list item, or None if not found
48214827
:rtype: Tag or None
48224828
"""
48234829
try:
48244830
self.wait_element(term='po-listbox')
48254831
po_items_list = self.web_scrap(term='po-item-list', scrap_type=enum.ScrapType.CSS_SELECTOR, main_container='body')
4826-
return next(iter(list(filter(lambda x: self.find_po_item_list(x, value, second_value), po_items_list))), None)
4832+
return next(iter(list(filter(lambda x: self.find_po_item_list(x, value, second_value, match_case=match_case), po_items_list))), None)
48274833

48284834
except Exception as e:
48294835
return None
48304836

4831-
def find_po_item_list(self, po_item_list, param_label, param_value):
4837+
def find_po_item_list(self, po_item_list, param_label, param_value, match_case=True):
48324838
'''This method is used to filter the po-item-list elements based on the label and value match.
48334839
48344840
@@ -4845,14 +4851,16 @@ def find_po_item_list(self, po_item_list, param_label, param_value):
48454851
elem_label = item_list_data.get('label')
48464852
elem_value = item_list_data.get('value')
48474853

4854+
compare = lambda expected, current: expected == current if match_case else expected in current
4855+
48484856
if param_label and param_value:
4849-
return param_label == elem_label and param_value == elem_value
4857+
return compare(param_label, elem_label) and compare(param_value, elem_value)
48504858

48514859
elif param_label and not param_value:
4852-
return param_label == elem_label
4860+
return compare(param_label, elem_label)
48534861

48544862
elif not param_label and param_value:
4855-
return param_value == elem_value
4863+
return compare(param_value, elem_value)
48564864

48574865
def _get_item_list_data(self, po_item_list) -> dict:
48584866
"""
@@ -5343,6 +5351,7 @@ def set_program(self, program_name: str = "", program_desc: str = ""):
53435351

53445352
success = False
53455353
search_term = "[class*='card-wrapper']"
5354+
confirm_term = f"wa-button[caption='{self.language.confirm}']"
53465355
attempts = 1
53475356

53485357
self.escape_to_main_menu()
@@ -5370,11 +5379,11 @@ def set_program(self, program_name: str = "", program_desc: str = ""):
53705379
self._po_loading()
53715380
if not program_name and program_desc:
53725381
self.config.routine = self._get_program_by_desc(program_desc)
5373-
self.click_po_list_box(value=program_desc, second_value=program_name, program_call=True)
5382+
self.click_po_list_box(value=program_desc, second_value=program_name, program_call=True, match_case=False)
53745383

53755384
# -- Trecho de código temporário --
5376-
time.sleep(1)
5377-
btn_confirmar = lambda: self.get_current_DOM().select("wa-button[caption='Confirmar']")
5385+
self.wait_element_timeout(term=confirm_term, scrap_type=enum.ScrapType.CSS_SELECTOR, main_container='body')
5386+
btn_confirmar = lambda: self.get_current_DOM().select(confirm_term)
53785387
if btn_confirmar():
53795388
btn_confirmar_sel = lambda: self.soup_to_selenium(next(iter(btn_confirmar())))
53805389
self.click(btn_confirmar_sel())

0 commit comments

Comments
 (0)