Skip to content

Commit

Permalink
#79 - New caching keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
Nepitwin committed Dec 28, 2022
1 parent cd99a7a commit 1634d3f
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Checkbox.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Combobox.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Element.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/ErrorHandling.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Grid.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion atests/Keyboard.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion atests/Listbox.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Mouse.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/RadioButton.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion atests/Screenshot.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Tab.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion atests/Textbox.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion atests/Tree.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion atests/Window.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions keen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%

Expand Down
16 changes: 12 additions & 4 deletions src/FlaUILibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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')

Expand All @@ -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
Expand Down
39 changes: 32 additions & 7 deletions src/FlaUILibrary/flaui/automation/uia.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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):
"""
Expand Down
44 changes: 36 additions & 8 deletions src/FlaUILibrary/flaui/automation/uia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit 1634d3f

Please sign in to comment.