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 c13cbd9 commit 423f50f
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 165 deletions.
1 change: 1 addition & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
PlacementTarget="{Binding ElementName=PopupToggleButton2}"
StaysOpen="False" />
<Button x:Name="DisabledButton" Content="Disabled Button" AutomationProperties.AutomationId="DisabledButton" IsEnabled="False"/>
<Button x:Name="ChangeAutomationIdButton" Content="Change Automation ID" AutomationProperties.AutomationId="ChangeAutomationId" Click="ChangeAutomationId" />
<TextBlock x:Name="Offscreen_Textblock" TextWrapping="Wrap" Text="Offscreen TextBlock" AutomationProperties.IsOffscreenBehavior="Offscreen" AutomationProperties.AutomationId="OffscreenTextBlock"/>
<Label Content="Menu Item Checked" Foreground="Red" x:Name="lblMenuChk"/>
</StackPanel>
Expand Down
9 changes: 9 additions & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.Generic;
using System.Windows.Automation;

namespace WpfApplication
{
Expand Down Expand Up @@ -104,5 +105,13 @@ private void ResetKeyboard_Click(object sender, RoutedEventArgs e)
lblKeyboardKeyDown.Content = GenerateKeyboardOutput(_keysDown);
lblKeyboardKeyUp.Content = GenerateKeyboardOutput(_keysUp);
}

private void ChangeAutomationId(object sender, RoutedEventArgs e)
{
if (sender is Button button)
{
button.SetValue(AutomationProperties.AutomationIdProperty, "ChangeAutomationIdUpdate");
}
}
}
}
42 changes: 19 additions & 23 deletions atests/Configuration.robot
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,25 @@ Documentation Test suite for configuration keywords.
... Is Cache Enabled Is Cache Enabled
...
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False

*** 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}
Resource util/Common.robot
Resource util/XPath.robot

Disable Caching
Disable Caching
${RESULT} Is Cache Enabled
Should Be Equal ${FALSE} ${RESULT}
*** Variables ***
${XPATH_BUTTON_ELEMENT_ORIGIN} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Button[@AutomationId='ChangeAutomationId']
${XPATH_BUTTON_ELEMENT_CHANGED} ${MAIN_WINDOW_SIMPLE_CONTROLS}/Button[@AutomationId='ChangeAutomationIdUpdate']

Refresh Cache
Fail TODO IMPLEMENT ME
${IDENTIFIER} Get Uia Identifier
Should Be Equal ${IDENTIFIER} ${UIA}
*** Test Cases ***
Element Should Be Updated If Property Is Changed
[Setup] Init Main Application
[Teardown] Stop Application ${MAIN_PID}
Element Should Exist ${XPATH_BUTTON_ELEMENT_ORIGIN}
Element Should Not Exist ${XPATH_BUTTON_ELEMENT_CHANGED}
${CHILDS} Get Childs From Element ${MAIN_WINDOW_SIMPLE_CONTROLS}
Log ${CHILDS}
Click ${XPATH_BUTTON_ELEMENT_ORIGIN}
${CHILDS} Get Childs From Element ${MAIN_WINDOW_SIMPLE_CONTROLS}
Log ${CHILDS}
Element Should Not Exist ${XPATH_BUTTON_ELEMENT_ORIGIN}
Element Should Exist ${XPATH_BUTTON_ELEMENT_CHANGED}
Binary file modified atests/apps/WpfApplication.exe
Binary file not shown.
18 changes: 5 additions & 13 deletions src/FlaUILibrary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
RadioButtonKeywords,
ListBoxKeywords,
TreeKeywords,
TabKeywords,
ConfigurationKeywords)
TabKeywords)
from FlaUILibrary.flaui.interface.valuecontainer import ValueContainer
from FlaUILibrary.robotframework import robotlog
from FlaUILibrary.flaui.module import Screenshot
Expand All @@ -45,7 +44,7 @@ class FlaUILibrary(DynamicCore):
Following settings could be used for library init.
Library screenshot_enabled=<True/False> screenshot_dir=<PATH_TO_STORE_IMAGES> timeout=<VALUE_IN_MS> use_cache=<True/False>
Library screenshot_enabled=<True/False> screenshot_dir=<PATH_TO_STORE_IMAGES> timeout=<VALUE_IN_MS>
== XPath locator ==
Expand Down Expand Up @@ -94,9 +93,8 @@ 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, use_cache='True'):
def __init__(self, uia='UIA3', screenshot_on_failure='True', screenshot_dir=None, timeout=1000):
"""
FlaUiLibrary can be imported by following optional arguments:
Expand All @@ -114,21 +112,16 @@ 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, use_cache)
self.module = UIA2(timeout)
else:
self.module = UIA3(timeout, use_cache)
self.module = UIA3(timeout)

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

Expand All @@ -148,7 +141,6 @@ 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
21 changes: 2 additions & 19 deletions src/FlaUILibrary/flaui/automation/uia.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ class UIA(WindowsAutomationInterface, ABC):
Generic window automation module for a centralized communication handling between robot keywords.
"""

def __init__(self, timeout: int = 1000, use_cache=True):
def __init__(self, timeout: int = 1000):
"""
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 Down Expand Up @@ -79,29 +77,14 @@ def get_element(self, identifier: str, ui_type: InterfaceType = None, msg: str =
msg (String) : Custom error message
"""
element = self.action(Element.Action.GET_ELEMENT,
Element.Container(xpath=identifier, retries=None, name=None),
Element.Container(xpath=identifier, retries=None, name=None, use_exception=None),
msg)

if not ui_type:
return element

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
18 changes: 3 additions & 15 deletions src/FlaUILibrary/flaui/automation/uia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
class UIA2(UIA):
"""UIA2 window automation module for a centralized communication handling between robot keywords and Flaui. """

def __init__(self, timeout=1000, use_cache=True):
def __init__(self, timeout=1000):
"""
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, use_cache)
super().__init__(timeout)
self._uia2 = UIA2Automation()
super().register_action() # pylint: disable=maybe-no-member

Expand All @@ -31,19 +30,8 @@ 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
Expand All @@ -52,7 +40,7 @@ def dispose(self):
return

try:
# C# --> class UIA3Automation : AutomationBase --> abstract class AutomationBase : IDisposable
# C# --> class UIA2Automation : AutomationBase --> abstract class AutomationBase : IDisposable
self._uia2.Dispose()
self._uia2 = None
except TypeError:
Expand Down
16 changes: 2 additions & 14 deletions src/FlaUILibrary/flaui/automation/uia3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
class UIA3(UIA):
"""UIA3 window automation module for a centralized communication handling between robot keywords and Flaui. """

def __init__(self, timeout=1000, use_cache=True):
def __init__(self, timeout=1000):
"""
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, use_cache)
super().__init__(timeout)
self._uia3 = UIA3Automation()
super().register_action() # pylint: disable=maybe-no-member

Expand All @@ -31,19 +30,8 @@ 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
Expand Down
24 changes: 0 additions & 24 deletions src/FlaUILibrary/flaui/interface/windowsautomationinterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,27 +40,3 @@ 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')
1 change: 0 additions & 1 deletion src/FlaUILibrary/keywords/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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
Expand Down
56 changes: 0 additions & 56 deletions src/FlaUILibrary/keywords/configuration.py

This file was deleted.

0 comments on commit 423f50f

Please sign in to comment.