Skip to content

Commit 40af6ec

Browse files
committed
Implement testTyping testcase for wt.PasswordField
Change verification to match value in Data structure.
1 parent be70382 commit 40af6ec

File tree

1 file changed

+70
-22
lines changed

1 file changed

+70
-22
lines changed

test/+wt/+test/PasswordField.m

Lines changed: 70 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,81 @@ function testValue(testCase)
3434
% Change the value programmatically
3535
newValue = "AbC435!";
3636
testCase.verifySetProperty("Value", newValue);
37-
testCase.verifyMatches(passField.Data, newValue);
38-
39-
40-
%testCase.verifyTypeAction(passField, newValue, "Value");
41-
% Verify callback triggered
42-
%testCase.verifyEqual(testCase.CallbackCount, 1)
37+
testCase.verifyMatches(passField.Data.Value, newValue);
4338

4439
end %function
4540

4641

47-
%RAJ - Unfortunately, can't type in a uihtml
4842

49-
% function testTyping(testCase)
50-
%
51-
% % Get the password field
52-
% passField = testCase.Widget.PasswordControl;
53-
%
54-
% % Type a new value
55-
% newValue = "PasswordABC123";
56-
% testCase.verifyTypeAction(passField, newValue, "Value");
57-
% testCase.verifyMatches(passField.Data, newValue);
58-
%
59-
% % Verify callback triggered
60-
% testCase.verifyEqual(testCase.CallbackCount, 1)
61-
%
62-
% end %function
43+
function testTyping(testCase)
44+
45+
% Get the password field
46+
passField = testCase.Widget.PasswordControl;
47+
newValue = "AbC435!";
48+
testCase.verifySetProperty("Value", newValue);
49+
50+
% Allow for some time for the widget and HTML code to catch up
51+
pause(.5)
52+
focus(testCase.Widget)
53+
pause(.5)
54+
55+
% Type a new value
56+
newValue = "PasswordABC123";
57+
simulateTyping(newValue);
58+
simulateTyping('ENTER')
59+
60+
% Allow for some time for the widget to catch up
61+
pause(.5)
62+
testCase.verifyMatches(passField.Data.Value, newValue);
63+
64+
% Verify callback triggered
65+
testCase.verifyEqual(testCase.CallbackCount, 1)
66+
67+
end %function
6368

6469
end %methods (Test)
6570

66-
end %classdef
71+
end %classdef
72+
73+
function simulateTyping(S)
74+
% Simulate typing actions
75+
76+
% Convert to chars
77+
S = convertStringsToChars(S);
78+
79+
%Initialize the java engine
80+
import java.awt.*;
81+
import java.awt.event.*;
82+
83+
%Create a Robot-object to do the key-pressing
84+
rob = Robot;
85+
86+
% Request to press ENTER?
87+
if strcmpi(S, 'enter')
88+
rob.keyPress(KeyEvent.VK_ENTER);
89+
rob.keyRelease(KeyEvent.VK_ENTER);
90+
return
91+
end
92+
93+
% Execute each letter/number individually
94+
for idx = 1:strlength(S)
95+
96+
% Get key event ID
97+
p = ['VK_' upper(S(idx))];
98+
99+
% For capital letters, press SHIFT
100+
if ~strcmp(lower(S(idx)), S(idx))
101+
rob.keyPress(KeyEvent.VK_SHIFT);
102+
end
103+
104+
% Press/release key
105+
rob.keyPress(KeyEvent.(p))
106+
rob.keyRelease(KeyEvent.(p))
107+
108+
% For capital letters, release SHIFT
109+
if ~strcmp(lower(S(idx)), S(idx))
110+
rob.keyRelease(KeyEvent.VK_SHIFT);
111+
end
112+
end
113+
114+
end

0 commit comments

Comments
 (0)