Skip to content

Commit

Permalink
add grid memo field to CheckResult and GetValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
renanllisboa committed Aug 4, 2021
1 parent e24fec5 commit 189c192
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 11 deletions.
18 changes: 12 additions & 6 deletions tir/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def ChangeUser(self, user, password, initial_program = "", date='', group='99',
"""
self.__webapp.ChangeUser(user, password, initial_program, date, group, branch)

def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name_attr=False, input_field=True, direction=None):
def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name_attr=False, input_field=True, direction=None, grid_memo_field=False):
"""
Checks if a field has the value the user expects.
Expand All @@ -136,6 +136,8 @@ def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name
:type input_field: bool
:param direction: Desired direction to search for the element, currently accepts right and down.
:type direction: str
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
Expand All @@ -155,7 +157,7 @@ def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name
>>> oHelper.LoadGrid()
"""
self.__webapp.CheckResult(field, user_value, grid, line, grid_number, name_attr, input_field, direction)
self.__webapp.CheckResult(field, user_value, grid, line, grid_number, name_attr, input_field, direction, grid_memo_field)

def CheckView(self, text, element_type="help"):
"""
Expand Down Expand Up @@ -306,7 +308,7 @@ def ClickLabel(self, label_name):
"""
self.__webapp.ClickLabel(label_name)

def GetValue(self, field, grid=False, line=1, grid_number=1):
def GetValue(self, field, grid=False, line=1, grid_number=1, grid_memo_field=False):
"""
Gets the current value or text of element.
Expand All @@ -318,13 +320,15 @@ def GetValue(self, field, grid=False, line=1, grid_number=1):
:type line: int
:param grid_number: Grid number of which grid should be checked when there are multiple grids on the same screen. - **Default:** 1
:type grid_number: int
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
>>> # Calling the method:
>>> current_value = oHelper.GetValue("A1_COD")
"""
return self.__webapp.GetValue(field, grid, line, grid_number)
return self.__webapp.GetValue(field, grid, line, grid_number, grid_memo_field)

def LoadGrid(self):
"""
Expand Down Expand Up @@ -708,7 +712,7 @@ def SetTabEDAPP(self, table_name):
"""
self.__webapp.SetTabEDAPP(table_name)

def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, row=None, name_attr=False, position = 1, check_value=None):
def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, row=None, name_attr=False, position = 1, check_value=None, grid_memo_field=False):
"""
Sets value of an input element.
Expand All @@ -733,6 +737,8 @@ def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, ro
:type name_attr: bool
:param position: Position which element is located. - **Default:** 1
:type position: int
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
Expand Down Expand Up @@ -761,7 +767,7 @@ def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, ro
>>> oHelper.SetValue("Order", "000001", grid=True, grid_number=2, check_value = False)
>>> oHelper.LoadGrid()
"""
self.__webapp.SetValue(field, value, grid, grid_number, ignore_case, row, name_attr, position, check_value)
self.__webapp.SetValue(field, value, grid, grid_number, ignore_case, row, name_attr, position, check_value, grid_memo_field)

def Setup(self, initial_program, date="", group="99", branch="01", module=""):
"""
Expand Down
48 changes: 43 additions & 5 deletions tir/technologies/webapp_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self, config_path="", autostart=True):
self.backup_parameters = []
self.tree_base_element = ()
self.tmenu_screen = None
self.grid_memo_field = False

if not self.config.smart_test and self.config.issue:
self.check_mot_exec()
Expand Down Expand Up @@ -1652,7 +1653,7 @@ def get_distance_by_direction(self, xy_label, position_list, direction):

return list(map(lambda x: (x[0], get_distance(xy_label, x[1])), position_list))

def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, row=None, name_attr=False, position = 1, check_value=None):
def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, row=None, name_attr=False, position = 1, check_value=None, grid_memo_field=False):
"""
Sets value of an input element.
Expand All @@ -1675,6 +1676,8 @@ def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, ro
:type row: int
:param name_attr: Boolean if search by Name attribute must be forced. - **Default:** False
:type name_attr: bool
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
Expand Down Expand Up @@ -1703,6 +1706,9 @@ def SetValue(self, field, value, grid=False, grid_number=1, ignore_case=True, ro

check_value = self.check_value(check_value)

if grid_memo_field:
self.grid_memo_field = True

if grid:
self.input_grid_appender(field, value, grid_number - 1, row = row, check_value = check_value)
elif isinstance(value, bool):
Expand Down Expand Up @@ -1957,7 +1963,7 @@ def get_web_value(self, element):

return web_value

def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name_attr=False, input_field=True, direction=None):
def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name_attr=False, input_field=True, direction=None, grid_memo_field=False):
"""
Checks if a field has the value the user expects.
Expand All @@ -1977,6 +1983,8 @@ def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name
:type bool
:param direction: Desired direction to search for the element, currently accepts right and down
:type str
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
Expand All @@ -1997,6 +2005,9 @@ def CheckResult(self, field, user_value, grid=False, line=1, grid_number=1, name
"""
self.wait_blocker()

if grid_memo_field:
self.grid_memo_field = True
if grid:
self.check_grid_appender(line - 1, field, user_value, grid_number - 1)
elif isinstance(user_value, bool):
Expand Down Expand Up @@ -2059,7 +2070,7 @@ def log_result(self, field, user_value, captured_value):

self.compare_field_values(field, user_value, captured_value, message)

def GetValue(self, field, grid=False, line=1, grid_number=1):
def GetValue(self, field, grid=False, line=1, grid_number=1, grid_memo_field=False):
"""
Gets the current value or text of element.
Expand All @@ -2071,6 +2082,8 @@ def GetValue(self, field, grid=False, line=1, grid_number=1):
:type line: int
:param grid_number: Grid number of which grid should be checked when there are multiple grids on the same screen. - **Default:** 1
:type grid_number: int
:param grid_memo_field: Boolean if this is a memo grid field. - **Default:** False
:type grid_memo_field: bool
Usage:
Expand All @@ -2080,6 +2093,9 @@ def GetValue(self, field, grid=False, line=1, grid_number=1):
endtime = time.time() + self.config.time_out
element = None

if grid_memo_field:
self.grid_memo_field = True

if not grid:
while ( (time.time() < endtime) and (not element) and (not hasattr(element, "name")) and (not hasattr(element, "parent"))):
element = self.get_field(field)
Expand Down Expand Up @@ -4303,8 +4319,10 @@ def fill_grid(self, field, x3_dictionaries, initial_layer):
bsoup_element = self.get_current_container().next
self.wait_until_to(expected_condition="element_to_be_clickable", element = bsoup_element, locator = By.XPATH, timeout=True)
self.try_send_keys(selenium_input, user_value, try_counter)
if self.element_exists(term=".ui-dialog", scrap_type=enum.ScrapType.CSS_SELECTOR, main_container='body'):
if self.grid_memo_field:
self.SetButton('Ok')
check_value = False
self.grid_memo_field = False

if try_counter < 2:
try_counter += 1
Expand Down Expand Up @@ -4519,7 +4537,11 @@ def check_grid(self, field, x3_dictionaries, get_value=False):

if column_name in headers[field[3]]:
column_number = headers[field[3]][column_name]
text = columns[column_number].text.strip()
if self.grid_memo_field:
text = self.check_grid_memo(columns[column_number])
self.grid_memo_field = False
else:
text = columns[column_number].text.strip()
success = True

if success and get_value and text:
Expand All @@ -4531,6 +4553,22 @@ def check_grid(self, field, x3_dictionaries, get_value=False):
if not success:
self.check_grid_error( grids, headers, column_name, rows, columns, field )

def check_grid_memo(self, element):
"""
[Internal]
:param element:
:return:
"""

self.soup_to_selenium(element).click()
ActionChains(self.driver).key_down(Keys.ENTER).perform()
container = self.get_current_container()
textarea = next(iter(container.select("textarea")), None)
content = self.driver.execute_script(f"return arguments[0].value",self.driver.find_element_by_xpath(xpath_soup(textarea))).strip()
self.SetButton('Ok')

return content

def check_grid_error(self, grid, headers, column_name, rows, columns, field):
"""
[Internal]
Expand Down

0 comments on commit 189c192

Please sign in to comment.