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 29, 2022
1 parent cd99a7a commit a0de55a
Show file tree
Hide file tree
Showing 31 changed files with 286 additions and 74 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].

## [Unreleased][]

### Added
- FlaUI handles all Automation Interfaces (UIA2/UIA3) as one object. FlaUI contains a caching
feature which does not automatic refresh elements if an ui is changed by property values like automation ids.
Caching feature can be now disabled by Keywords or Library property if always elements should be refreshed.
```
Enable Caching
Disable Caching
${RESULT} Is Cache Enabled
Refresh Cache
```
```
Library FlaUILibrary use_cache=True/False
```

## [Release][2.0.1] [2.0.1][2.0.0-2.0.1] - 2022-10-06

### Updated
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ on_finish:
- ps: >-
$wc = New-Object 'System.Net.WebClient'
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\result\pylint.xml))
$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\result\xunit.xml))
#$wc.UploadFile("https://ci.appveyor.com/api/testresults/junit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\result\pylint.xml))
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 .
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 .
call cd ..
EXIT /B %ERRORLEVEL%

Expand Down
19 changes: 14 additions & 5 deletions src/FlaUILibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
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 All @@ -44,7 +45,7 @@ class FlaUILibrary(DynamicCore):
Following settings could be used for library init.
Library screenshot_enabled=<True/False> screenshot_dir=<PATH_TO_STORE_IMAGES>
Library screenshot_enabled=<True/False> screenshot_dir=<PATH_TO_STORE_IMAGES> timeout=<VALUE_IN_MS> use_cache=<True/False>
== XPath locator ==
Expand Down Expand Up @@ -93,15 +94,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 +114,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 +148,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
Loading

0 comments on commit a0de55a

Please sign in to comment.