Skip to content

Commit

Permalink
Merge pull request #836 from totvs/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
renanllisboa authored Jul 28, 2022
2 parents a6a088e + ebfb21e commit 2ce93cd
Show file tree
Hide file tree
Showing 9 changed files with 3,995 additions and 69 deletions.
2 changes: 1 addition & 1 deletion scripts/install_package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ taskkill /f /im chromedriver.exe
echo -------------------------
echo Installing project...
echo -------------------------
pip install -U dist/tir_framework-1.18.5.tar.gz
pip install -U dist/tir_framework-1.19.0.tar.gz
pause >nul | set/p = Press any key to exit ...
217 changes: 214 additions & 3 deletions tir/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from tir.technologies.webapp_internal import WebappInternal
from tir.technologies.apw_internal import ApwInternal
from tir.technologies.poui_internal import PouiInternal
from tir.technologies.core.config import ConfigLoader
from tir.technologies.core.base_database import BaseDatabase
"""
Expand Down Expand Up @@ -284,21 +285,23 @@ def ClickIcon(self, icon_text, position=1):
"""
self.__webapp.ClickIcon(icon_text, position)

def ClickCheckBox(self, label_box_name, position=1):
def ClickCheckBox(self, label_box_name, position=1, double_click=False):
"""
Clicks on a Label in box on the screen.
:param label_box_name: The label box name
:type label_box_name: str
:param position: index label box on interface
:type position: int
:param double_click: True if a double click in element is necessary.
:type double_click: bool
Usage:
>>> # Call the method:
>>> oHelper.ClickCheckBox("Search",1)
"""
self.__webapp.ClickCheckBox(label_box_name,position)
self.__webapp.ClickCheckBox(label_box_name,position, double_click)

def ClickLabel(self, label_name):
"""
Expand Down Expand Up @@ -1109,7 +1112,7 @@ def OpenCSV(self, csv_file='', delimiter=';', column=None, header=None, filter_c
This method return data as a string if necessary use some method to convert data like int().
>>> config.json
>>> "CSVPath" : "C:\\temp"
>>> '"CSVPath": "C:\\temp"'
:param csv_file: .csv file name
:type csv_file: str
Expand Down Expand Up @@ -1365,3 +1368,211 @@ def SetValue(self, campo, valor, grid=False, linha=0, chknewline=False, disabled

def WaitModal(self, text, opcao="title"):
self.__Apw.WaitModal(text, opcao)

class Poui():

def __init__(self, config_path="", autostart=True):
self.__poui = PouiInternal(config_path, autostart)
self.__database = BaseDatabase(config_path, autostart=False)
self.config = ConfigLoader()
self.coverage = self.config.coverage

def ClickMenu(self, menu_item):
"""
Clicks on the menu-item of the POUI component.
https://po-ui.io/documentation/po-menu
:param menu_item:Menu item name
:type menu_item: str
Usage:
>>> # Call the method:
>>> oHelper.ClickMenu("Contracts")
"""
self.__poui.ClickMenu(menu_item)

def InputValue(self, field='', value='', position=1):
"""
Fill the POUI input component.
https://po-ui.io/documentation/po-input
:param field: Input text title that you want to fill
:type field: str
:param value: Value that fill in input
:type value: str
:param position: Position which element is located. - **Default:** 1
:type position: int
Usage:
>>> # Call the method:
>>> oHelper.InputValue('Name', 'Test')
:return: None
"""
self.__poui.InputValue(field, value, position)

def ClickCombo(self, field='', value='', position=1):
"""
Clicks on the Combo of POUI component.
https://po-ui.io/documentation/po-combo
:param field: Combo text title that you want to click.
:param value: Value that you want to select in Combo.
:param position: Position which element is located. - **Default:** 1
Usage:
>>> # Call the method:
>>> oHelper.ClickCombo('Visão', 'Compras')
:return:
"""
self.__poui.click_poui_component(field, value, position, selector="div > po-combo", container=True)

def ClickSelect(self, field='', value='', position=1):
"""
Clicks on the Select of POUI component.
https://po-ui.io/documentation/po-select
:param field: Select text title that you want to click.
:param value: Value that you want to select in Select.
:param position: Position which element is located. - **Default:** 1
Usage:
>>> # Call the method:
>>> oHelper.ClickSelect('Espécie', 'Compra')
:return:
"""
self.__poui.click_poui_component(field, value, position, selector="div > po-select", container=True)

def ClickButton(self, button='', position=1):
"""
Clicks on the Button of POUI component.
https://po-ui.io/documentation/po-button
:param field: Button to be clicked.
:param position: Position which element is located. - **Default:** 1
Usage:
>>> # Call the method:
>>> oHelper.ClickButton('Cancelar')
:return:
"""
self.__poui.click_button(button, position, selector="div > po-button", container=False)

def AssertFalse(self, expected=False, script_message=''):
"""
Defines that the test case expects a False response to pass
Usage:
>>> #Instantiating the class
>>> inst.oHelper = Webapp()
>>> #Calling the method
>>> inst.oHelper.AssertFalse()
"""
self.__poui.AssertFalse(expected, script_message)

def AssertTrue(self, expected=True, script_message=''):
"""
Defines that the test case expects a True response to pass
Usage:
>>> #Calling the method
>>> inst.oHelper.AssertTrue()
"""
self.__poui.AssertTrue(expected, script_message)

def ClickWidget(self, title='', action='', position=1):
"""
Clicks on the Widget or Widget action of POUI component.
https://po-ui.io/documentation/po-widget
:param tittle: Widget text title that you want to click.
:param action: The name of action to be clicked
:param position: Position which element is located. - **Default:** 1
Usage:
>>> # Call the method:
>>> oHelper.ClickWidget(title='LEad Time SC x PC', action='Detalhes', position=1)
:return:
"""
self.__poui.ClickWidget(title, action, position)

def TearDown(self):
"""
Closes the webdriver and ends the test case.
Usage:
>>> #Calling the method
>>> inst.oHelper.TearDown()
"""
self.__poui.TearDown()

def POSearch(self, content=''):
"""
Fill the POUI Search component.
https://po-ui.io/documentation/po-page-dynamic-search
:param content: Content to be Search.
:type content: str
Usage:
>>> # Call the method:
>>> oHelper.POSearch(content='Content to be Search')
:return: None
"""
self.__poui.POSearch(content)

def ClickTable(self, first_column=None, second_column=None, first_content=None, second_content=None, table_number=0, itens=False, click_cell=None):
"""
Clicks on the Table of POUI component.
https://po-ui.io/documentation/po-table
:param first_column: Column name to be used as reference.
:type first_column: str
:param second_column: Column name to be used as reference.
:type second_column: str
:param first_content: Content of the column to be searched.
:type first_content: str
:param second_content: Content of the column to be searched.
:type second_content: str
:param table_number: Which grid should be used when there are multiple grids on the same screen. - **Default:** 1
:type table_number: int
:param itens: Bool parameter that click in all itens based in the field and content reference.
:type itens: bool
:param click_cell: Content to click based on a column position to close the axis
:type click_cell: str
>>> # Call the method:
>>> oHelper.ClickTable(first_column='Código', first_content='000003', click_cell='Editar')
:return: None
"""

self.__poui.ClickTable(first_column, second_column, first_content, second_content, table_number, itens, click_cell)

def CheckResult(self, field=None, user_value=None, po_component='po-input', position=1):
"""
Checks if a field has the value the user expects.
:param field: The field or label of a field that must be checked.
:type field: str
:param user_value: The value that the field is expected to contain.
:type user_value: str
:param po_component: POUI component name that you want to check content on screen
:type po_component: str
:param position: Position which element is located. - **Default:** 1
:type position: int
Usage:
>>> # Calling method to check a value of a field:
>>> oHelper.CheckResult("Código", "000001", 'po-input')
"""
self.__poui.CheckResult(field, user_value, po_component, position)
54 changes: 46 additions & 8 deletions tir/technologies/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class Base(unittest.TestCase):
>>> def WebappInternal(Base):
>>> def APWInternal(Base):
"""

driver = None
wait = None
errors = []

def __init__(self, config_path="", autostart=True):
"""
Definition of each global variable:
Expand Down Expand Up @@ -94,7 +99,6 @@ def __init__(self, config_path="", autostart=True):
self.log.user = getpass.getuser()

self.base_container = "body"
self.errors = []
self.config.log_file = False
self.tmenu_out_iframe = False
self.twebview_context = False
Expand Down Expand Up @@ -332,7 +336,7 @@ def element_exists(self, term, scrap_type=enum.ScrapType.TEXT, position=0, optio
else:
return len(element_list) >= position

def filter_displayed_elements(self, elements, reverse=False):
def filter_displayed_elements(self, elements, reverse=False, twebview=False):
"""
[Internal]
Expand All @@ -354,6 +358,9 @@ def filter_displayed_elements(self, elements, reverse=False):
>>> #Calling the method
>>> self.filter_displayed_elements(elements, True)
"""

if twebview:
self.switch_to_iframe()
#0 - elements filtered
elements = list(filter(lambda x: self.soup_to_selenium(x) is not None ,elements ))
if not elements:
Expand Down Expand Up @@ -432,7 +439,7 @@ def find_label_element(self, label_text, container):
else:
return []

def get_current_DOM(self):
def get_current_DOM(self, twebview=False):
"""
[Internal]
Expand All @@ -447,18 +454,21 @@ def get_current_DOM(self):
>>> soup = self.get_current_DOM()
"""

self.twebview_context = twebview

self.driver.switch_to.default_content()

if self.config.new_log:
self.execution_flow()


try:

if self.twebview_context:
self.wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="COMP3010"]')))
self.driver.switch_to.frame(self.driver.find_element(By.XPATH, '//*[@id="COMP3010"]'))
self.switch_to_iframe()
self.twebview_context = False
return BeautifulSoup(self.driver.page_source, "html.parser")


soup = BeautifulSoup(self.driver.page_source,"html.parser")

if self.tmenu_out_iframe:
Expand Down Expand Up @@ -490,6 +500,25 @@ def get_current_DOM(self):
soup = BeautifulSoup(self.driver.page_source,"html.parser")
return soup

def switch_to_iframe(self):
"""
[Internal]
:return:
"""
iframes = None
iframe_displayed = None
endtime = time.time() + self.config.time_out
while time.time() < endtime and not iframes:
iframes = self.driver.find_elements_by_css_selector('[class*="twebview"]')

if iframes:
iframe_displayed = next(iter(list(filter(lambda x: x.is_displayed(), iframes))), None)
else:
self.driver.switch_to.default_content()

if iframe_displayed:
self.driver.switch_to.frame(iframe_displayed)

def get_element_text(self, element):
"""
[Internal]
Expand Down Expand Up @@ -797,7 +826,7 @@ def set_element_focus(self, element):
pass


def soup_to_selenium(self, soup_object):
def soup_to_selenium(self, soup_object=None, twebview=False):
"""
[Internal]
Expand All @@ -814,6 +843,9 @@ def soup_to_selenium(self, soup_object):
>>> # Calling the method:
>>> selenium_obj = lambda: self.soup_to_selenium(bs_obj)
"""
if twebview:
self.switch_to_iframe()

if soup_object is None:
raise AttributeError
return next(iter(self.driver.find_elements_by_xpath(xpath_soup(soup_object))), None)
Expand Down Expand Up @@ -1106,3 +1138,9 @@ def return_combo_index(self, combo, option):
for i, j in enumerate(combo.options):
if j.text.lower() in option:
return i

def return_iframe(self, selector):
"""
"""
self.driver.switch_to_default_content()
return self.driver.find_elements_by_css_selector(selector)
Loading

0 comments on commit 2ce93cd

Please sign in to comment.