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 d37929f
Show file tree
Hide file tree
Showing 29 changed files with 75 additions and 188 deletions.
3 changes: 2 additions & 1 deletion TestApplications/src/WpfApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
xmlns:local="clr-namespace:WpfApplication"
mc:Ignorable="d"
Title="FlaUI WPF Test App"
Height="533.931" Width="629.303"
Height="545.931" Width="629.303"
KeyDown="OnKeyDown"
KeyUp="OnKeyUp"
ResizeMode="CanResize">
Expand Down 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");
}
}
}
}
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ on_finish:
$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))
$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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library Process
Library StringFormat
Library Collections
Expand Down
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}
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False timeout=0
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=True
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
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 use_cache=${USE_CACHE}
Library FlaUILibrary uia=${UIA} screenshot_on_failure=False
Library Process
Library StringFormat
Expand Down
Binary file modified atests/apps/WpfApplication.exe
Binary file not shown.
20 changes: 16 additions & 4 deletions keen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,19 @@ EXIT /B %ERRORLEVEL%
call pip install .
EXIT /B %ERRORLEVEL%

:install_release
call pip install --upgrade --force-reinstall robotframework-flaui
EXIT /B %ERRORLEVEL%

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

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

Expand All @@ -45,8 +49,16 @@ EXIT /B %ERRORLEVEL%
set /A result = %ERRORLEVEL%
call:test_uia3
if %result%==0 set /A result = %ERRORLEVEL%
call rebot --name ATests --outputdir result -x rebot_xunit.xml result/uia2/output.xml result/uia3/output.xml
call python parsly.py
call rebot --name ATests --outputdir result -x xunit.xml result/uia2/output.xml result/uia3/output.xml
EXIT /B %result%

:test_release
call:install_release
call:test_uia2
set /A result = %ERRORLEVEL%
call:test_uia3
if %result%==0 set /A result = %ERRORLEVEL%
call rebot --name ATests --outputdir result -x xunit.xml result/uia2/output.xml result/uia3/output.xml
EXIT /B %result%

:pylint
Expand Down
19 changes: 5 additions & 14 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,17 +93,15 @@ 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:
``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 @@ -114,21 +111,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 +140,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
Loading

0 comments on commit d37929f

Please sign in to comment.