Skip to content

Commit

Permalink
Press Key issue with combined keys #67
Browse files Browse the repository at this point in the history
Keyboard input example extended
Keyboard robot file adjusted
Unecessary documentation removed
  • Loading branch information
Nepitwin committed May 18, 2022
1 parent 427a512 commit aa0ae5b
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 52 deletions.
6 changes: 3 additions & 3 deletions TestApplications/src/Notifier/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
</configuration>
3 changes: 2 additions & 1 deletion TestApplications/src/Notifier/Notifier.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
<OutputType>WinExe</OutputType>
<RootNamespace>NotifierTest</RootNamespace>
<AssemblyName>Notifier</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TestApplications/src/WpfApplication/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
13 changes: 13 additions & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
mc:Ignorable="d"
Title="FlaUI WPF Test App"
Height="533.931" Width="629.303"
KeyDown="OnKeyDown"
KeyUp="OnKeyUp"
ResizeMode="CanResize">
<Window.Resources>
<ResourceDictionary>
Expand Down Expand Up @@ -177,6 +179,17 @@
</StackPanel>
</ScrollViewer>
</TabItem>
<TabItem Header="Keyboard Controls">
<StackPanel Orientation="Vertical">
<Button x:Name="ResetKeyboard" Content="Reset Keyboard Inputs" Click="ResetKeyboard_Click" AutomationProperties.AutomationId="ResetKeyboardInputs"/>
<Label Content="Keyboard Input Field"/>
<TextBox AutomationProperties.AutomationId="KeyboardInputField" Text="" Background="Black" Foreground="White"/>
<Label Content="Keyboard Down Events"/>
<Label Content="" Foreground="White" Background="Black" x:Name="lblKeyboardKeyDown"/>
<Label Content="Keyboard Up Events"/>
<Label Content="" Foreground="White" Background="Black" x:Name="lblKeyboardKeyUp"/>
</StackPanel>
</TabItem>
</TabControl>
</DockPanel>
</Window>
Expand Down
45 changes: 45 additions & 0 deletions TestApplications/src/WpfApplication/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Collections.Generic;

namespace WpfApplication
{
Expand All @@ -8,6 +10,10 @@ namespace WpfApplication
/// </summary>
public partial class MainWindow
{
private List<Key> _keysUp = new List<Key>();
private List<Key> _keysDown = new List<Key>();


public MainWindow()
{
InitializeComponent();
Expand Down Expand Up @@ -41,5 +47,44 @@ private void OnShowLabel(object sender, RoutedEventArgs e)
lblMenuChk.Visibility = Visibility.Hidden;
}
}

private void OnKeyDown(object sender, KeyEventArgs e)
{
_keysDown.Add(e.Key);
lblKeyboardKeyDown.Content = GenerateKeyboardOutput(_keysDown);
}

private void OnKeyUp(object sender, KeyEventArgs e)
{
_keysUp.Add(e.Key);
lblKeyboardKeyUp.Content = GenerateKeyboardOutput(_keysUp);
}

private string GenerateKeyboardOutput(List<Key> keys)
{
var output = "";

for (int i = 0; i < keys.Count; i++)
{
if (i == keys.Count - 1)
{
output += keys[i];
}
else
{
output += keys[i] + "+";
}
}

return output;
}

private void ResetKeyboard_Click(object sender, RoutedEventArgs e)
{
_keysDown.Clear();
_keysUp.Clear();
lblKeyboardKeyDown.Content = GenerateKeyboardOutput(_keysDown);
lblKeyboardKeyUp.Content = GenerateKeyboardOutput(_keysUp);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion TestApplications/src/WpfApplication/WpfApplication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>WpfApplication</RootNamespace>
<AssemblyName>WpfApplication</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down
86 changes: 46 additions & 40 deletions atests/Keyboard.robot
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ Resource util/Common.robot
Resource util/Error.robot
Resource util/XPath.robot

Suite Setup Init Main Application
Suite Setup Run Keywords Init Main Application
... AND Open Keyboard Tab
Suite Teardown Stop Application ${MAIN_PID}
Test Teardown Reset Textbox
Test Setup Wait Until Keyword Succeeds 5x 10ms Reset Textbox

*** Variables ***
${XPATH_COMBO_BOX_INPUT} ${MAIN_WINDOW_SIMPLE_CONTROLS}/ComboBox[@AutomationId='EditableCombo']
${XPATH_INPUT_FIELD} ${MAIN_WINDOW_KEYBOARD_CONTROLS}/Edit[@AutomationId='KeyboardInputField']
${XPATH_RESET} ${MAIN_WINDOW_KEYBOARD_CONTROLS}/Button[@AutomationId='ResetKeyboardInputs']
${XPATH_LABEL_INPUT_UP} ${MAIN_WINDOW_KEYBOARD_CONTROLS}/Text[@AutomationId='lblKeyboardKeyDown']

${EXP_VALUE_INPUT_TEXT} = Type text
${EXP_VALUE_OVERRIDE_INPUT_TEXT} = Override
Expand All @@ -48,86 +51,89 @@ ${KEYBOARD_INPUT_PASTE} s'CTRL+V'

*** Test Cases ***
Keyboard Type Text
Press Key ${KEYBOARD_INPUT_TEXT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_TEXT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Keyboard Type Text Multiple
Press Keys ${KEYBOARD_INPUT_TEXT_X2} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_TEXT_X2} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT_SHORTCUT} ${TEXT}

Keyboard Type Shortcut Select All
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}
Press Keys ${KEYBOARD_INPUT_OVERRIDE_TEXT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_OVERRIDE_TEXT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_OVERRIDE_INPUT_TEXT} ${TEXT}

Keyboard Type Shortcut Cut and Paste Multiple
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Press Keys ${KEYBOARD_INPUT_OVERRIDE_TEXT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_OVERRIDE_TEXT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_OVERRIDE_INPUT_TEXT} ${TEXT}

Press Keys ${KEYBOARD_INPUT_SELECT_CUT_TEXT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EMPTY} ${TEXT}

Press Keys ${KEYBOARD_INPUT_PASTE_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_PASTE_ARRAY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_OVERRIDE_INPUT_TEXT} ${TEXT}

Keyboard Type Shortcut Copy and Paste Multiple
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Press Keys ${KEYBOARD_INPUT_COPY_PASTE_TEXT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_COPY_PASTE_TEXT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Press Keys ${KEYBOARD_INPUT_PASTE_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_PASTE_ARRAY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Keyboard Type Shortcut Copy and Paste
Press Key ${KEYBOARD_INPUT_TEXT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_TEXT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Press Key ${KEYBOARD_INPUT_SELECTALL} ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_COPY} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_SELECTALL} ${XPATH_INPUT_FIELD}
Press Key ${KEYBOARD_INPUT_COPY} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Press Key ${KEYBOARD_INPUT_PASTE} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_PASTE} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT} ${TEXT}

Keyboard Type Generic Key Combination
Press Keys ${KEYBOARD_INPUT_TEXT_SHORTCUT} ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
Press Keys ${KEYBOARD_INPUT_TEXT_SHORTCUT} ${XPATH_INPUT_FIELD}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${EXP_VALUE_INPUT_TEXT_SHORTCUT} ${TEXT}

Delete Text
${LENGTH} Get Length ${EXP_VALUE_INPUT_TEXT_SHORTCUT}
FOR ${i} IN RANGE 0 ${LENGTH}
Press Key ${KEYBOARD_INPUT_BACKSPACE} ${XPATH_COMBO_BOX_INPUT}
Press Key ${KEYBOARD_INPUT_BACKSPACE} ${XPATH_INPUT_FIELD}
END
${TEXT} Get Text From Textbox ${XPATH_COMBO_BOX_INPUT}
${TEXT} Get Text From Textbox ${XPATH_INPUT_FIELD}
Should Be Equal ${TEXT} ${EMPTY}

False Argument Type
Run Keyword and Expect Error ${EXP_ERR_MSG_ARGUMENT_ARRAY} Press Keys ${KEYBOARD_INPUT_TEXT} ${XPATH_COMBO_BOX_INPUT}
Run Keyword and Expect Error ${EXP_ERR_MSG_ARGUMENT_ARRAY} Press Keys ${KEYBOARD_INPUT_TEXT} ${XPATH_INPUT_FIELD}
${EXP_ERR_MSG} Format String ${EXP_INVALID_KEYBOARD_COMBINATION} ${KEYBOARD_INPUT_TEXT_ARRAY}
${ERR_MSG} Run Keyword and Expect Error * Press Key ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_COMBO_BOX_INPUT}
${ERR_MSG} Run Keyword and Expect Error * Press Key ${KEYBOARD_INPUT_TEXT_ARRAY} ${XPATH_INPUT_FIELD}
Should Be Equal As Strings ${EXP_ERR_MSG} ${ERR_MSG}

*** Keywords ***
Reset Textbox
Set Text To Textbox ${XPATH_COMBO_BOX_INPUT} ${EMPTY}
Click ${XPATH_RESET}
${TEXT} Get Name From Element ${XPATH_LABEL_INPUT_UP}
Should Be Empty ${TEXT}
Set Text To Textbox ${XPATH_INPUT_FIELD} ${EMPTY}
Binary file modified atests/apps/WpfApplication.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions atests/util/Common.robot
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,8 @@ Open Complex Tab
${XPATH_TAB} Set Variable ${MAIN_WINDOW}/Tab
${TAB_ITEM_LIST_CONTROLS} Set Variable Complex Controls
Select Tab Item By Name ${XPATH_TAB} ${TAB_ITEM_LIST_CONTROLS}
Open Keyboard Tab
${XPATH_TAB} Set Variable ${MAIN_WINDOW}/Tab
${TAB_ITEM_LIST_CONTROLS} Set Variable Keyboard Controls
Select Tab Item By Name ${XPATH_TAB} ${TAB_ITEM_LIST_CONTROLS}
1 change: 1 addition & 0 deletions atests/util/XPath.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ${MAIN_WINDOW_NOTIFIER} /Window[@AutomationId='Notifi
${XPATH_NOT_EXISTS} /NotExists
${MAIN_WINDOW_SIMPLE_CONTROLS} ${MAIN_WINDOW}/Tab/TabItem[@Name='Simple Controls']
${MAIN_WINDOW_COMPLEX_CONTROLS} ${MAIN_WINDOW}/Tab/TabItem[@Name='Complex Controls']
${MAIN_WINDOW_KEYBOARD_CONTROLS} ${MAIN_WINDOW}/Tab/TabItem[@Name='Keyboard Controls']
2 changes: 0 additions & 2 deletions src/FlaUILibrary/keywords/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ def __init__(self, module: UIA):
def press_key(self, key_combination, identifier=None, msg=None):
"""
Keyboard control to execute a user defined one shurcut or text.
If identifier set try to attach to given element if
operation was successfully old element will be reattached automatically.
Arguments:
| Argument | Type | Description |
Expand Down

0 comments on commit aa0ae5b

Please sign in to comment.