From c9d9e5e876e629f9a6bbb42cca2cf6e5219fe522 Mon Sep 17 00:00:00 2001 From: Andreas Sekulski Date: Wed, 28 Dec 2022 04:02:51 +0100 Subject: [PATCH] #79 - New caching keywords --- CHANGELOG.md | 18 ++++++ appveyor.yml | 4 +- atests/Application.robot | 2 +- atests/Checkbox.robot | 2 +- atests/Combobox.robot | 2 +- atests/Configuration.robot | 35 ++++++++++++ atests/Debug.robot | 2 +- atests/Element.robot | 2 +- atests/ErrorHandling.robot | 2 +- atests/Grid.robot | 2 +- atests/Keyboard.robot | 2 +- atests/Listbox.robot | 2 +- atests/Mouse.robot | 2 +- atests/RadioButton.robot | 2 +- atests/Screenshot.robot | 2 +- atests/Tab.robot | 2 +- atests/Textbox.robot | 2 +- atests/Tree.robot | 2 +- atests/Window.robot | 2 +- keen.bat | 4 +- src/FlaUILibrary/__init__.py | 19 +++++-- src/FlaUILibrary/flaui/automation/uia.py | 39 ++++++++++--- src/FlaUILibrary/flaui/automation/uia2.py | 44 ++++++++++++--- src/FlaUILibrary/flaui/automation/uia3.py | 44 ++++++++++++--- .../interface/windowsautomationinterface.py | 41 +++++++++++--- src/FlaUILibrary/flaui/module/application.py | 6 +- src/FlaUILibrary/flaui/module/element.py | 11 ++-- src/FlaUILibrary/flaui/module/window.py | 8 --- src/FlaUILibrary/keywords/__init__.py | 1 + src/FlaUILibrary/keywords/configuration.py | 56 +++++++++++++++++++ src/FlaUILibrary/version.py | 2 +- 31 files changed, 290 insertions(+), 74 deletions(-) create mode 100644 atests/Configuration.robot create mode 100644 src/FlaUILibrary/keywords/configuration.py diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a4535..f38c38b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,24 @@ 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. + + New Keywords + ``` + Enable Caching + Disable Caching + ${RESULT} Is Cache Enabled + Refresh Cache + ``` + + New Library Parameter + ``` + Library FlaUILibrary use_cache=True/False + ``` + ## [Release][2.0.1] [2.0.1][2.0.0-2.0.1] - 2022-10-06 ### Updated diff --git a/appveyor.yml b/appveyor.yml index 5877b32..877e390 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -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)) diff --git a/atests/Application.robot b/atests/Application.robot index 6de8871..b78e387 100644 --- a/atests/Application.robot +++ b/atests/Application.robot @@ -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 diff --git a/atests/Checkbox.robot b/atests/Checkbox.robot index ad5ef37..1ba699e 100644 --- a/atests/Checkbox.robot +++ b/atests/Checkbox.robot @@ -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 diff --git a/atests/Combobox.robot b/atests/Combobox.robot index 547236c..d0a1898 100644 --- a/atests/Combobox.robot +++ b/atests/Combobox.robot @@ -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 diff --git a/atests/Configuration.robot b/atests/Configuration.robot new file mode 100644 index 0000000..07f6559 --- /dev/null +++ b/atests/Configuration.robot @@ -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} diff --git a/atests/Debug.robot b/atests/Debug.robot index 4e44c99..ee3af45 100644 --- a/atests/Debug.robot +++ b/atests/Debug.robot @@ -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 diff --git a/atests/Element.robot b/atests/Element.robot index 42f5972..09021ea 100644 --- a/atests/Element.robot +++ b/atests/Element.robot @@ -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 diff --git a/atests/ErrorHandling.robot b/atests/ErrorHandling.robot index f3b4412..8b9dcba 100644 --- a/atests/ErrorHandling.robot +++ b/atests/ErrorHandling.robot @@ -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 diff --git a/atests/Grid.robot b/atests/Grid.robot index de0b6c5..d9eed30 100644 --- a/atests/Grid.robot +++ b/atests/Grid.robot @@ -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 diff --git a/atests/Keyboard.robot b/atests/Keyboard.robot index 832a655..4995d2c 100644 --- a/atests/Keyboard.robot +++ b/atests/Keyboard.robot @@ -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 diff --git a/atests/Listbox.robot b/atests/Listbox.robot index 4c48a36..71e15f5 100644 --- a/atests/Listbox.robot +++ b/atests/Listbox.robot @@ -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 diff --git a/atests/Mouse.robot b/atests/Mouse.robot index 2c98f11..612d64b 100644 --- a/atests/Mouse.robot +++ b/atests/Mouse.robot @@ -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 diff --git a/atests/RadioButton.robot b/atests/RadioButton.robot index 7327184..b953236 100644 --- a/atests/RadioButton.robot +++ b/atests/RadioButton.robot @@ -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 diff --git a/atests/Screenshot.robot b/atests/Screenshot.robot index 5097af6..1eb5f58 100644 --- a/atests/Screenshot.robot +++ b/atests/Screenshot.robot @@ -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 diff --git a/atests/Tab.robot b/atests/Tab.robot index 8a5d98e..a2cb004 100644 --- a/atests/Tab.robot +++ b/atests/Tab.robot @@ -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 diff --git a/atests/Textbox.robot b/atests/Textbox.robot index 74878f5..6419c3c 100644 --- a/atests/Textbox.robot +++ b/atests/Textbox.robot @@ -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 diff --git a/atests/Tree.robot b/atests/Tree.robot index 37ca59a..2a80423 100644 --- a/atests/Tree.robot +++ b/atests/Tree.robot @@ -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 diff --git a/atests/Window.robot b/atests/Window.robot index 764338c..0e6a2a1 100644 --- a/atests/Window.robot +++ b/atests/Window.robot @@ -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 diff --git a/keen.bat b/keen.bat index f77b9d6..f7ebde4 100644 --- a/keen.bat +++ b/keen.bat @@ -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% diff --git a/src/FlaUILibrary/__init__.py b/src/FlaUILibrary/__init__.py index a2a0b76..eb90047 100644 --- a/src/FlaUILibrary/__init__.py +++ b/src/FlaUILibrary/__init__.py @@ -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 @@ -44,7 +45,7 @@ class FlaUILibrary(DynamicCore): Following settings could be used for library init. - Library screenshot_enabled= screenshot_dir= + Library screenshot_enabled= screenshot_dir= timeout= use_cache= == XPath locator == @@ -93,8 +94,9 @@ 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: @@ -102,6 +104,7 @@ def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None ``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,6 +114,11 @@ 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 @@ -118,9 +126,9 @@ def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None 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 +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 diff --git a/src/FlaUILibrary/flaui/automation/uia.py b/src/FlaUILibrary/flaui/automation/uia.py index 7df68f3..719f5df 100644 --- a/src/FlaUILibrary/flaui/automation/uia.py +++ b/src/FlaUILibrary/flaui/automation/uia.py @@ -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): """ diff --git a/src/FlaUILibrary/flaui/automation/uia2.py b/src/FlaUILibrary/flaui/automation/uia2.py index 1ffbf2f..3d6b10b 100644 --- a/src/FlaUILibrary/flaui/automation/uia2.py +++ b/src/FlaUILibrary/flaui/automation/uia2.py @@ -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 diff --git a/src/FlaUILibrary/flaui/automation/uia3.py b/src/FlaUILibrary/flaui/automation/uia3.py index 9da23d5..458188a 100644 --- a/src/FlaUILibrary/flaui/automation/uia3.py +++ b/src/FlaUILibrary/flaui/automation/uia3.py @@ -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 diff --git a/src/FlaUILibrary/flaui/interface/windowsautomationinterface.py b/src/FlaUILibrary/flaui/interface/windowsautomationinterface.py index 9a88bc5..261d651 100644 --- a/src/FlaUILibrary/flaui/interface/windowsautomationinterface.py +++ b/src/FlaUILibrary/flaui/interface/windowsautomationinterface.py @@ -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') diff --git a/src/FlaUILibrary/flaui/module/application.py b/src/FlaUILibrary/flaui/module/application.py index 8424c35..3356427 100644 --- a/src/FlaUILibrary/flaui/module/application.py +++ b/src/FlaUILibrary/flaui/module/application.py @@ -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): diff --git a/src/FlaUILibrary/flaui/module/element.py b/src/FlaUILibrary/flaui/module/element.py index f5ec7c6..fdac810 100644 --- a/src/FlaUILibrary/flaui/module/element.py +++ b/src/FlaUILibrary/flaui/module/element.py @@ -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): """ diff --git a/src/FlaUILibrary/flaui/module/window.py b/src/FlaUILibrary/flaui/module/window.py index 7d12394..2cf0ba8 100644 --- a/src/FlaUILibrary/flaui/module/window.py +++ b/src/FlaUILibrary/flaui/module/window.py @@ -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. diff --git a/src/FlaUILibrary/keywords/__init__.py b/src/FlaUILibrary/keywords/__init__.py index e62ecdd..3387155 100644 --- a/src/FlaUILibrary/keywords/__init__.py +++ b/src/FlaUILibrary/keywords/__init__.py @@ -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 diff --git a/src/FlaUILibrary/keywords/configuration.py b/src/FlaUILibrary/keywords/configuration.py new file mode 100644 index 0000000..2293d5d --- /dev/null +++ b/src/FlaUILibrary/keywords/configuration.py @@ -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() diff --git a/src/FlaUILibrary/version.py b/src/FlaUILibrary/version.py index b46c2e7..311aff2 100644 --- a/src/FlaUILibrary/version.py +++ b/src/FlaUILibrary/version.py @@ -1 +1 @@ -VERSION = "2.0.1" +VERSION = "2.0.2"