Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#79 - New caching keywords
Browse files Browse the repository at this point in the history
Nepitwin committed Dec 28, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent cd99a7a commit 1634d3f
Showing 29 changed files with 268 additions and 71 deletions.
2 changes: 1 addition & 1 deletion atests/Application.robot
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ Documentation Test suite for application keywords.
... Launch Application With Args Launch Application With Arguments
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library StringFormat
Resource util/Common.robot
2 changes: 1 addition & 1 deletion atests/Checkbox.robot
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ Documentation Test suite for checkbox keywords.
... Get Checkbox State Get Checkbox State
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library StringFormat
Resource util/Common.robot
2 changes: 1 addition & 1 deletion atests/Combobox.robot
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ Documentation Test suite for combobox keywords.
... Get Combobox Items Count Get Combobox Items Count
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
Library Collections
35 changes: 35 additions & 0 deletions atests/Configuration.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
*** Settings ***
Documentation Test suite for configuration keywords.
... Keyword Test Case Names
... Enable Caching Enable Caching
... Disable Caching Disable Caching
... Refresh Cache Refresh Cache
... Is Cache Enabled Is Cache Enabled
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}

*** Test Cases ***
Is Cache Enabled
${RESULT} Is Cache Enabled
${IDENTIFIER} Get Uia Identifier
IF '${IDENTIFIER}'=='UIA2'
Should Be Equal ${TRUE} ${RESULT}
ELSE
Should Be Equal ${FALSE} ${RESULT}
END

Enable Caching
Enable Caching
${RESULT} Is Cache Enabled
Should Be Equal ${TRUE} ${RESULT}

Disable Caching
Disable Caching
${RESULT} Is Cache Enabled
Should Be Equal ${FALSE} ${RESULT}

Refresh Cache
Fail TODO IMPLEMENT ME
${IDENTIFIER} Get Uia Identifier
Should Be Equal ${IDENTIFIER} ${UIA}
2 changes: 1 addition & 1 deletion atests/Debug.robot
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Documentation Test suite for debug keywords.
... Get UIA Identifier Get UIA Identifier
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
2 changes: 1 addition & 1 deletion atests/Element.robot
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ Documentation Test suite for element keywords.
... Wait Until Element Is Visible Timeout Is Reached By Wrong Number
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
Library DateTime
2 changes: 1 addition & 1 deletion atests/ErrorHandling.robot
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
Documentation Error handling test suite for all common flaui keywords.
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False timeout=0
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False timeout=0 use_cache=${USE_CACHE}
Library StringFormat

Resource util/Error.robot
2 changes: 1 addition & 1 deletion atests/Grid.robot
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ Documentation Test suite for grid ui keyword usage.
... Get Grid Rows Count Get Grid Rows Count
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat

2 changes: 1 addition & 1 deletion atests/Keyboard.robot
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ Documentation Test suite for keyboard keywords.
... False Argument Type
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat

2 changes: 1 addition & 1 deletion atests/Listbox.robot
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ Documentation Test suite for list box keywords.
... Get Listbox Items Count Get Listbox Items Count
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
Library Collections
2 changes: 1 addition & 1 deletion atests/Mouse.robot
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ Documentation Test suite for mouse keywords.
... Drag And Drop Drag And Drop
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library StringFormat
Resource util/Common.robot
2 changes: 1 addition & 1 deletion atests/RadioButton.robot
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Documentation Test suite for radio button keywords.
... Get Radiobutton State Get Radiobutton State
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat

2 changes: 1 addition & 1 deletion atests/Screenshot.robot
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ Documentation Test suite for screenshot keywords.
... Take Manual Screenshot By Keyword
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=True
Library FlaUILibrary uia=${UIA} screenshot_on_failure=True use_cache=${USE_CACHE}
Library StringFormat
Library Process
Library String
2 changes: 1 addition & 1 deletion atests/Tab.robot
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ Documentation Test suite for tab keywords.
...

Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library StringFormat
Library Collections

2 changes: 1 addition & 1 deletion atests/Textbox.robot
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ Documentation Test suite for textbox keywords.
... Set Text To Textbox Set Text To Textbox
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
2 changes: 1 addition & 1 deletion atests/Tree.robot
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ Documentation Test suite for list box keywords.
... Selected TreeItem Should Be Selected TreeItem Should Be Item Not Exist
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat

2 changes: 1 addition & 1 deletion atests/Window.robot
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ Documentation Test suite for window keywords.
... Close Window Close Window
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library Process
Library StringFormat
4 changes: 2 additions & 2 deletions keen.bat
Original file line number Diff line number Diff line change
@@ -28,13 +28,13 @@ EXIT /B %ERRORLEVEL%

:test_uia2
call cd atests
call robot --name "UIA2" --variable UIA:UIA2 --outputdir ../result/uia2 .
call robot --name "UIA2" --variable UIA:UIA2 --variable USE_CACHE:True --outputdir ../result/uia2 Configuration.robot
call cd ..
EXIT /B %ERRORLEVEL%

:test_uia3
call cd atests
call robot --name "UIA3" --variable UIA:UIA3 --outputdir ../result/uia3 .
call robot --name "UIA3" --variable UIA:UIA3 --variable USE_CACHE:False --outputdir ../result/uia3 Configuration.robot
call cd ..
EXIT /B %ERRORLEVEL%

16 changes: 12 additions & 4 deletions src/FlaUILibrary/__init__.py
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
RadioButtonKeywords,
ListBoxKeywords,
TreeKeywords,
TabKeywords)
TabKeywords, ConfigurationKeywords)
from FlaUILibrary.flaui.interface.valuecontainer import ValueContainer
from FlaUILibrary.robotframework import robotlog
from FlaUILibrary.flaui.module import Screenshot
@@ -93,15 +93,17 @@ class KeywordModules(Enum):
LISTBOX = "Listbox"
TREE = "Tree"
TAB = "Tab"
CONFIGURATION = "CONFIGURATION"

def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None, timeout=1000):
def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None, timeout=1000, use_cache='True'):
"""
FlaUiLibrary can be imported by following optional arguments:
``uia`` Microsoft UI-Automation framework to use. UIA2 or UIA3
``screenshot_on_failure`` indicator to disable or enable screenshot feature.
``screenshot_dir`` is the directory where screenshots are saved.
``timeout`` maximum amount of waiting time in ms for an element find action. Default value is 1000ms.
``use_cache`` flag to use cached elements. Default value is True.
If the given directory does not already exist, it will be created when the first screenshot is taken.
If the argument is not given, the default location for screenshots is the output directory of the Robot run,
@@ -111,16 +113,21 @@ def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None
self.mode = FlaUILibrary.RobotMode.TEST_NOT_RUNNING
self.builtin = BuiltIn()

if use_cache == "False":
use_cache = False
else:
use_cache = True

try:
if timeout == "None" or int(timeout) <= 0:
timeout = 0
except ValueError:
timeout = 1000

if uia == "UIA2":
self.module = UIA2(timeout)
self.module = UIA2(timeout, use_cache)
else:
self.module = UIA3(timeout)
self.module = UIA3(timeout, use_cache)

self.screenshots = Screenshot(screenshot_dir, screenshot_on_failure == 'True')

@@ -140,6 +147,7 @@ def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None
FlaUILibrary.KeywordModules.LISTBOX: ListBoxKeywords(self.module),
FlaUILibrary.KeywordModules.TREE: TreeKeywords(self.module),
FlaUILibrary.KeywordModules.TAB: TabKeywords(self.module),
FlaUILibrary.KeywordModules.CONFIGURATION: ConfigurationKeywords(self.module)
}

# Robot init
39 changes: 32 additions & 7 deletions src/FlaUILibrary/flaui/automation/uia.py
Original file line number Diff line number Diff line change
@@ -14,11 +14,13 @@ class UIA(WindowsAutomationInterface, ABC):
Generic window automation module for a centralized communication handling between robot keywords.
"""

def __init__(self, timeout=1000):
def __init__(self, timeout: int = 1000, use_cache=True):
"""
Creates default UIA window automation module.
``timeout`` is the default waiting value to repeat element find action. Default value is 1000ms.
``use_cache`` flag to use caching feature from elements. Default value is True.
"""
self._use_cache = use_cache
self._actions = {}
self._timeout = timeout

@@ -45,15 +47,23 @@ def action(self, action: Enum, values: ValueContainer = None, msg: str = None):
except FlaUiError as error:
raise FlaUiError(msg) if msg is not None else error

def register_action(self, automation: Any):
def register_action(self):
"""
Register all supported core actions.
Args:
automation (Object) : Windows user automation object.
"""
modules = [Application(automation), Debug(), Element(automation, self._timeout), Keyboard(), Selector(),
Grid(), Mouse(), Textbox(), Tree(), ToggleButton(), Tab(), Window(automation), Combobox()]
modules = [Application(),
Combobox(),
Debug(),
Element(self, self._timeout),
Grid(),
Keyboard(),
Mouse(),
Selector(),
Tab(),
Textbox(),
ToggleButton(),
Tree(),
Window()]

for module in modules:
for value in module.Action:
@@ -77,6 +87,21 @@ def get_element(self, identifier: str, ui_type: InterfaceType = None, msg: str =

return self.cast_element_to_type(element, ui_type)

def set_caching(self, enable: bool):
"""
Enable or disable caching feature from windows automation interface.
Args:
enable : Boolean to enable or disable caching feature.
"""
self._use_cache = enable

def is_cache_enabled(self):
"""
Returns flag if cache is enabled or not.
"""
return self._use_cache

@staticmethod
def cast_element_to_type(element: Any, ui_type: InterfaceType):
"""
44 changes: 36 additions & 8 deletions src/FlaUILibrary/flaui/automation/uia2.py
Original file line number Diff line number Diff line change
@@ -5,27 +5,55 @@
class UIA2(UIA):
"""UIA2 window automation module for a centralized communication handling between robot keywords and Flaui. """

def __init__(self, timeout=1000):
def __init__(self, timeout=1000, use_cache=True):
"""
Creates UIA2 window automation module.
``timeout`` is the default waiting value to repeat element find action. Default value is 1000ms.
``use_cache`` flag to use caching feature from elements. Default value is True.
"""
super().__init__(timeout)
super().__init__(timeout, use_cache)
self._uia2 = UIA2Automation()
super().register_action(self._uia2) # pylint: disable=maybe-no-member
super().register_action() # pylint: disable=maybe-no-member

def __del__(self):
"""
Destructor to clean up all C# interfaces
"""
try:
# C# --> class UIA2Automation : AutomationBase --> abstract class AutomationBase : IDisposable
self._uia2.Dispose()
except TypeError:
pass
self.dispose()

def identifier(self):
"""
Returns identifier which windows automation interface is in usage.
"""
return "UIA2"

def get_desktop_element(self):
"""
Returns desktop element from automation interface.
"""
if self._use_cache:
return self._uia2.GetDesktop()

self.refresh_cache()
return self._uia2.GetDesktop()

def refresh_cache(self):
"""
Refresh all desktop elements from windows automation interface.
"""
self.dispose()
self._uia2 = UIA2Automation()

def dispose(self):
"""
Dispose method to release user automation interface from FlaUI
"""
if self._uia2 is None:
return

try:
# C# --> class UIA3Automation : AutomationBase --> abstract class AutomationBase : IDisposable
self._uia2.Dispose()
self._uia2 = None
except TypeError:
pass
44 changes: 36 additions & 8 deletions src/FlaUILibrary/flaui/automation/uia3.py
Original file line number Diff line number Diff line change
@@ -5,27 +5,55 @@
class UIA3(UIA):
"""UIA3 window automation module for a centralized communication handling between robot keywords and Flaui. """

def __init__(self, timeout=1000):
def __init__(self, timeout=1000, use_cache=True):
"""
Creates UIA3 window automation module.
``timeout`` is the default waiting value to repeat element find action. Default value is 1000ms.
``use_cache`` flag to use caching feature from elements. Default value is True.
"""
super().__init__(timeout)
super().__init__(timeout, use_cache)
self._uia3 = UIA3Automation()
super().register_action(self._uia3) # pylint: disable=maybe-no-member
super().register_action() # pylint: disable=maybe-no-member

def __del__(self):
"""
Destructor to clean up all C# interfaces
"""
try:
# C# --> class UIA3Automation : AutomationBase --> abstract class AutomationBase : IDisposable
self._uia3.Dispose()
except TypeError:
pass
self.dispose()

def identifier(self):
"""
Returns identifier which windows automation interface is in usage.
"""
return "UIA3"

def get_desktop_element(self):
"""
Returns desktop element from automation interface.
"""
if self._use_cache:
return self._uia3.GetDesktop()

self.refresh_cache()
return self._uia3.GetDesktop()

def refresh_cache(self):
"""
Refresh all desktop elements from windows automation interface.
"""
self.dispose()
self._uia3 = UIA3Automation()

def dispose(self):
"""
Dispose method to release user automation interface from FlaUI
"""
if self._uia3 is None:
return

try:
# C# --> class UIA3Automation : AutomationBase --> abstract class AutomationBase : IDisposable
self._uia3.Dispose()
self._uia3 = None
except TypeError:
pass
41 changes: 34 additions & 7 deletions src/FlaUILibrary/flaui/interface/windowsautomationinterface.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC, abstractmethod
from typing import Any
from enum import Enum
from FlaUILibrary.flaui.interface.valuecontainer import ValueContainer

@@ -22,18 +21,46 @@ def action(self, action: Enum, values: ValueContainer, msg: str = None):
raise NotImplementedError('Subclass must override action method')

@abstractmethod
def register_action(self, automation: Any):
def register_action(self):
"""
Register all supported core actions.
Args:
automation (Object) : Windows user automation object.
"""
raise NotImplementedError('Subclass must override action method')
raise NotImplementedError('Subclass must override register_action method')

@abstractmethod
def identifier(self):
"""
Returns identifier which windows automation interface is in usage.
"""
raise NotImplementedError('Subclass must override action method')
raise NotImplementedError('Subclass must override identifier method')

@abstractmethod
def get_desktop_element(self):
"""
Returns desktop element from automation interface.
"""
raise NotImplementedError('Subclass must override get_desktop_element method')

@abstractmethod
def set_caching(self, enable: bool):
"""
Enable or disable caching from windows automation interface.
Args:
enable : Boolean to enable or disable caching feature.
"""
raise NotImplementedError('Subclass must override set_caching method')

@abstractmethod
def refresh_cache(self):
"""
Refresh all desktop elements from windows automation interface.
"""
raise NotImplementedError('Subclass must override refresh_cache method')

@abstractmethod
def is_cache_enabled(self):
"""
Returns flag if cache is enabled or not.
"""
raise NotImplementedError('Subclass must override is_cache_enabled method')
6 changes: 1 addition & 5 deletions src/FlaUILibrary/flaui/module/application.py
Original file line number Diff line number Diff line change
@@ -49,15 +49,11 @@ class Action(Enum):
LAUNCH_APPLICATION_WITH_ARGS = "LAUNCH_APPLICATION_WITH_ARGS"
EXIT_APPLICATION = "EXIT_APPLICATION"

def __init__(self, automation: Any):
def __init__(self):
"""
Application module wrapper for FlaUI usage.
Args:
automation (Object): UIA3/UIA2 automation object from FlaUI.
"""
self._applications = []
self._automation = automation

@staticmethod
def create_value_container(name=None, pid=None, args=None, msg=None):
11 changes: 6 additions & 5 deletions src/FlaUILibrary/flaui/module/element.py
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
from FlaUILibrary.flaui.util.converter import Converter
from FlaUILibrary.flaui.exception import FlaUiError
from FlaUILibrary.flaui.interface import (ModuleInterface, ValueContainer)
from FlaUILibrary.flaui.interface import WindowsAutomationInterface


class Element(ModuleInterface):
@@ -41,20 +42,20 @@ class Action(Enum):
WAIT_UNTIL_ELEMENT_IS_HIDDEN = "WAIT_UNTIL_ELEMENT_IS_HIDDEN"
WAIT_UNTIL_ELEMENT_IS_VISIBLE = "WAIT_UNTIL_ELEMENT_IS_VISIBLE"

def __init__(self, automation: Any, timeout: int = 1000):
def __init__(self, uia: WindowsAutomationInterface, timeout: int = 1000):
"""
Element module wrapper for FlaUI usage.
Args:
automation (Object): UIA3/UIA2 automation object from FlaUI.
uia (WindowsAutomationInterface): Windows automation object wrapper.
timeout (Integer): Timeout handler for element wait if not found.
"""
self._element = None
self._automation = automation
self._uia = uia
self._timeout = timeout

@staticmethod
def create_value_container(name=None, xpath=None, retries=None, use_exception=None, msg=None):
def create_value_container(name=None, xpath=None, retries=None, use_exception=None, msg=None):
"""
Helper to create container object.
@@ -260,7 +261,7 @@ def _get_element_by_xpath(self, xpath: str):
Args:
xpath (string): XPath identifier from element.
"""
return self._automation.GetDesktop().FindFirstByXPath(xpath)
return self._uia.get_desktop_element().FindFirstByXPath(xpath)

def _element_should_exist(self, xpath: str, use_exception: bool):
"""
8 changes: 0 additions & 8 deletions src/FlaUILibrary/flaui/module/window.py
Original file line number Diff line number Diff line change
@@ -23,14 +23,6 @@ class Action(Enum):
"""
CLOSE_WINDOW = "CLOSE_WINDOW"

def __init__(self, automation):
"""Window module wrapper for FlaUI usage.
Args:
automation (Object): UIA3/UIA2 automation object from FlaUI.
"""
self._automation = automation

def execute_action(self, action: Action, values: Container):
"""If action is not supported an ActionNotSupported error will be raised.
1 change: 1 addition & 0 deletions src/FlaUILibrary/keywords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .application import ApplicationKeywords
from .checkbox import CheckBoxKeywords
from .combobox import ComboBoxKeywords
from .configuration import ConfigurationKeywords
from .debug import DebugKeywords
from .element import ElementKeywords
from .mouse import MouseKeywords
56 changes: 56 additions & 0 deletions src/FlaUILibrary/keywords/configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from robotlibcore import keyword
from FlaUILibrary.flaui.automation.uia import UIA


class ConfigurationKeywords:
"""
Interface implementation from specific configuration keywords for robotframework-flaui controlling.
"""

def __init__(self, module: UIA):
"""
Constructor for configuration keywords.
``module`` Automation framework module like UIA3 to handle element interaction.
"""
self._module = module

@keyword
def enable_caching(self):
"""
Enable caching from all desktop elements. All desktop elements will be tracked once.
Examples:
| Enable Caching |
"""
self._module.set_caching(True)

@keyword
def disable_caching(self):
"""
Disable caching from all desktop elements. Each call will update all desktop elements.
Examples:
| Disable Caching |
"""
self._module.set_caching(False)

@keyword
def refresh_cache(self):
"""
Refresh once cache from all desktop elements.
Examples:
| Refresh Cache |
"""
self._module.refresh_cache()

@keyword
def is_cache_enabled(self):
"""
Returns if cache is enabled True or not False.
Examples:
| ${RESULT} Is Cache Enabled |
"""
return self._module.is_cache_enabled()
2 changes: 1 addition & 1 deletion src/FlaUILibrary/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = "2.0.1"
VERSION = "2.0.2"

0 comments on commit 1634d3f

Please sign in to comment.