Base

class tir.technologies.core.base.Base(config_path='', autostart=True)

Base class for any technology to implement Selenium Interface Tests.

This class instantiates the browser, reads the config file and prepares the log.

If no config_path is passed, it will read the config.json file that exists in the same folder as the file that would execute this module.

Parameters:
  • config_path (str) – The path to the config file. - Default: “” (empty string)

  • autostart – Sets whether TIR should open browser and execute from the start. - Default: True

Type:

bool

Usage:

The Base class must be inherited by every internal class of each technology that would exist in this module.

The classes must be declared under pwa/technologies/ folder.

>>> def WebappInternal(Base):
>>> def APWInternal(Base):
AssertFalse(expected, message)

Defines that the test case expects a False response to pass

Usage:

>>> #Calling the method
>>> oHelper.AssertFalse()
AssertTrue(expected, message)

Defines that the test case expects a True response to pass

Usage:

>>> #Calling the method
>>> oHelper.AssertTrue()
SetTIRConfig(config_name, value)

Changes a value of a TIR internal config during runtime.

This could be useful for TestCases that must use a different set of configs than the ones defined at config.json

Available configs:

  • Url - str

  • Environment - str

  • User - str

  • Password - str

  • Language - str

  • DebugLog - str

  • TimeOut - int

  • InitialProgram - str

  • Routine - str

  • Date - str

  • Group - str

  • Branch - str

  • Module - str

Parameters:
  • config_name (str) – The config to be changed.

  • value (str) – The value that would be set.

Usage:

>>> # Calling the method:
>>> oHelper.SetTIRConfig(config_name="date", value="30/10/2018")
Start()

Opens the browser maximized and goes to defined URL.

Usage:

>>> # Calling the method:
>>> oHelper.Start()
TearDown()

Closes the webdriver and ends the test case.

Usage:

>>> #Calling the method
>>> oHelper.TearDown()
assert_result(expected, script_message='')

[Internal]

Asserts the result based on the expected value.

Parameters:

expected (bool) – Expected value

Usage :

>>> #Calling the method:
>>> self.assert_result(True)
click(element, click_type=ClickType.JS, right_click=False)

[Internal]

Clicks on the Selenium element.

Supports three types of clicking: JavaScript, pure Selenium and Selenium’s ActionChains.

Default is JavaScript clicking.

Parameters:
  • element (Selenium object) – Selenium element

  • click_type (enum.ClickType) – ClickType enum. - Default: enum.ClickType.JS

  • right_click – Clicks with the right button of the mouse in the last element of the tree.

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.click(element(), click_type=enum.ClickType.JS)
compare_field_values(field, user_value, captured_value, message)

[Internal]

Validates and stores field in the self.errors array if the values are different.

Parameters:
  • field (str) – Field name

  • user_value (str) – User input value

  • captured_value (str) – Interface captured value

  • message (str) – Error message if comparison fails

Usage:

>>> #Calling the method
>>> self.compare_field_values("A1_NOME", "JOÃO", "JOOÃ", "Field A1_NOME has different values")
double_click(element, click_type=ClickType.SELENIUM)

[Internal]

Clicks two times on the Selenium element.

Parameters:

element (Selenium object) – Selenium element

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.double_click(element())
element_exists(term, scrap_type=ScrapType.TEXT, position=0, optional_term='', main_container='.tmodaldialog,.ui-dialog')

[Internal]

Returns a boolean if element exists on the screen.

Parameters:
  • term (str) – The first term to use on a search of element

  • scrap_type (enum.ScrapType) – Type of element search. - Default: enum.ScrapType.TEXT

  • position (int) – Position which element is located. - Default: 0

  • optional_term (str) – Second term to use on a search of element. Used in MIXED search. - Default: “” (empty string)

Returns:

True if element is present. False if element is not present.

Return type:

bool

Usage:

>>> element_is_present = element_exists(term=".ui-dialog", scrap_type=enum.ScrapType.CSS_SELECTOR)
>>> element_is_present = element_exists(term=".tmodaldialog.twidget", scrap_type=enum.ScrapType.CSS_SELECTOR, position=initial_layer+1)
>>> element_is_present = element_exists(term=text, scrap_type=enum.ScrapType.MIXED, optional_term=".tsay")
element_name(element_soup)

[internal]

execution_flow()

Method that is responsible to control log flow in an execution

Returns:

filter_displayed_elements(elements, reverse=False, twebview=False)

[Internal]

Receives a BeautifulSoup element list and filters only the displayed elements.

Parameters:
  • elements (List of BeautifulSoup objects) – BeautifulSoup element list

  • reverse (bool) – Boolean value if order should be reversed or not. - Default: False

Returns:

List of filtered BeautifulSoup elements

Return type:

List of BeautifulSoup objects

Usage:

>>> #Defining the element list:
>>> soup = self.get_current_DOM()
>>> elements = soup.select("div")
>>> #Calling the method
>>> self.filter_displayed_elements(elements, True)
find_first_div_parent(element)

[Internal]

Finds first div parent element of another BeautifulSoup element.

If element is already a div, it will return the element.

Parameters:

element (BeautifulSoup object) – BeautifulSoup element

Returns:

The first div parent of the element

Return type:

BeautifulSoup object

Usage:

>>> parent_element = self.find_first_div_parent(my_element)
find_first_wa_panel_parent(element)

[Internal]

Finds first div parent element of another BeautifulSoup element.

If element is already a div, it will return the element.

Parameters:

element (BeautifulSoup object) – BeautifulSoup element

Returns:

The first div parent of the element

Return type:

BeautifulSoup object

Usage:

>>> parent_element = self.find_first_div_parent(my_element)
find_label_element(label_text, container)

[Internal]

Find input element next to label containing the label_text parameter.

Parameters:
  • label_text (str) – The label text to be searched

  • container (BeautifulSoup object) – The main container object to be used

Returns:

A list containing a BeautifulSoup object next to the label

Return type:

List of BeautifulSoup objects

Usage:

>>> self.find_label_element("User:", container_object)
finish_testcase()

Method that is responsable to finish testcase and send the log and execution time of testcase.

Returns:

get_current_DOM(twebview=False)

[Internal]

Returns current HTML DOM parsed as a BeautifulSoup object

Returns:

BeautifulSoup parsed DOM

Return type:

BeautifulSoup object

Usage:

>>> #Calling the method
>>> soup = self.get_current_DOM()
get_element_text(element)

[Internal]

Gets element text.

Parameters:

element (Selenium object) – Selenium element

Returns:

Element text

Return type:

str

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> text = self.get_element_text(element())
get_element_value(element)

[Internal]

Gets element value.

Parameters:

element (Selenium object) – Selenium element

Returns:

Element value

Return type:

str

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> text = self.get_element_value(element())
log_error(message, new_log_line=True)

[Internal]

Finishes execution of test case with an error and creates the log information for that test.

Parameters:
  • message (str) – Message to be logged

  • new_log_line (bool) – Boolean value if Message should be logged as new line or not. - Default: True

Usage:

>>> #Calling the method:
>>> self.log_error("Element was not found")
move_to_element(element)

[Internal]

Move focus to element on the screen.

Parameters:

element (Selenium object) – Selenium element

Usage:

>>> #Defining an element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.scroll_to_element(element())
normalize_config_name(config_name)

[Internal]

Normalizes the config name string to respect the config object naming convention.

Parameters:

config_name (str) – The config name string to be normalized.

Returns:

The config name string normalized.

Return type:

str

Usage:

>>> # Calling the method:
>>> normalized_name = self.normalize_config_name("InitialProgram") # "initial_program"
return_combo_index(combo, option)
Parameters:
  • combo

  • option

Returns:

return_combo_object(element, shadow_root=True, locator=False)

[Internal]

return_iframe(selector)
return_selected_combo_value(element)

” [Internal]

scroll_into_view(element)

[Internal]

Scroll to element on the screen.

Parameters:

element (Selenium object) – Selenium element

Usage:

>>> #Defining an element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.scroll_to_element(element())
scroll_to_element(element)

[Internal]

Scroll to element on the screen.

Parameters:

element (Selenium object) – Selenium element

Usage:

>>> #Defining an element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> self.scroll_to_element(element())
search_stack(function)

Returns True if passed function is present in the call stack.

Parameters:

function (str) – Name of the function

Returns:

Boolean if passed function is present or not in the call stack.

Return type:

bool

Usage:

>>> # Calling the method:
>>> is_present = self.search_stack("MATA020")
search_zindex(element)

[Internal]

Returns zindex value of Beautifulget_so object.

Internal function created to be used inside lambda of zindex_sort method.

Only works if element has Style attribute.

Parameters:

element (BeautifulSoup object) – BeautifulSoup element

Returns:

z-index value

Return type:

int

Usage:

>>> #Line extracted from zindex_sort method:
>>> elements.sort(key=lambda x: self.search_zindex(x), reverse=reverse)
select_combo(element, option, index=False, shadow_root=True, locator=False)

Selects the option on the combobox.

Parameters:
  • element (Beautiful Soup object) – Combobox element

  • option (str) – Option to be selected

  • index (bool) – True if option is an integer value

  • shadow_root (bool) – Internal control for shadow root objects

  • locator (bool) – bool value for locator True or False

Usage:

>>> #Calling the method:
>>> self.select_combo(element, "Chosen option")
send_keys(element, arg)

[Internal]

Clicks two times on the Selenium element.

Parameters:
  • element (Selenium object) – Selenium element

  • arg (str or selenium.webdriver.common.keys) – Text or Keys to be sent to the element

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method with a string
>>> self.send_keys(element(), "Text")
>>> #Calling the method with a Key
>>> self.send_keys(element(), Keys.ENTER)
set_element_focus(element)

[Internal]

Sets focus on element.

Parameters:

element (Selenium object) – Selenium element

Usage:

>>> #Defining the element:
>>> element = lambda: self.driver.find_element_by_id("example_id")
>>> #Calling the method
>>> text = self.set_element_focus(element())
soup_to_selenium(soup_object=None, twebview=False)

[Internal]

An abstraction of the Selenium call to simplify the conversion of elements.

Parameters:

soup_object (BeautifulSoup object) – The BeautifulSoup object to be converted.

Returns:

The object converted to a Selenium object.

Return type:

Selenium object

Usage:

>>> # Calling the method:
>>> selenium_obj = lambda: self.soup_to_selenium(bs_obj)
start_testcase()

Method that starts testcase time and testcase info.

Returns:

switch_to_iframe()

[Internal] :return:

take_screenshot(filename)

[Internal]

Takes a screenshot and saves on the screenshot folder defined in config.

Parameters:

filename – The name of the screenshot file.

Type:

str

Usage:

>>> # Calling the method:
>>> self.take_screenshot(filename="myscreenshot")
web_scrap(term, scrap_type=ScrapType.TEXT, optional_term=None, label=False, main_container=None)

[Internal]

Returns a BeautifulSoup object list based on the search parameters.

Does not support ScrapType.XPATH as scrap_type parameter value.

Parameters:
  • term (str) – The first search term. A text or a selector

  • scrap_type (enum.ScrapType.) – The type of webscraping. - Default: enum.ScrapType.TEXT

  • optional_term (str) – The second search term. A selector used in MIXED webscraping. - Default: None

  • label (bool) – If the search is based on a label near the element. - Default: False

  • main_container (str) – The selector of a container element that has all other elements. - Default: None

Returns:

List of BeautifulSoup4 elements based on search parameters.

Return type:

List of BeautifulSoup4 objects

Usage:

>>> #All buttons
>>> buttons = self.web_scrap(term="button", scrap_type=enum.ScrapType.CSS_SELECTOR)
>>> #----------------#
>>> #Elements that contain the text "Example"
>>> example_elements = self.web_scrap(term="Example")
>>> #----------------#
>>> #Elements with class "my_class" and text "my_text"
>>> elements = self.web_scrap(term="my_text", scrap_type=ScrapType.MIXED, optional_term=".my_class")
webapp_shadowroot(shadow_root=True)

[Internal]

zindex_sort(elements, reverse=False, active_tab=True)

[Internal]

Sorts list of BeautifulSoup elements based on z-index style attribute.

Only works if elements have Style attribute.

Parameters:
  • elements (List of BeautifulSoup objects) – BeautifulSoup element list

  • reverse (bool) – Boolean value if order should be reversed or not. - Default: False

Returns:

List of sorted BeautifulSoup elements based on zindex.

Return type:

List of BeautifulSoup objects

Usage:

>>> #Defining the element list:
>>> soup = self.get_current_DOM()
>>> elements = soup.select("div")
>>> #Calling the method
>>> self.zindex_sort(elements, True)