понедельник, 16 марта 2015 г.

GUI-testing 9. GUI-testing “in spoken style”. Introducing of the alphanumeric characters to the current control

Original in Russian: http://18delphi.blogspot.ru/2013/11/gui_2510.html

GUI-testing. Table of contents

There I have considered the possibility of inputting the string to the current controller and sending the command keys to the control.

Let’s consider one more word.

For introducing “alphanumeric” characters.

In Delphi it looks like this:

interface
 
 TkwEmitString = class(TscriptKeyWord)
  {* Allows to input the string.
The example:
[code]
PROCEDURE "Input the string" STRING IN aString
 aString EmitString
END //" Input the string"
[code] }
 protected
 // realized methods
   procedure DoIt(aContext: TscriptContext); override;
 end;//TkwEmitString
 
implementation
 
procedure TkwEmitString.DoIt(aContext: TscriptContext);
var
 l_Index : Integer;
 l_C     : Integer;
 l_H     : THandle;
 l_S     : String;
begin
 l_S := aContext.PopString;
 l_H := Windows.GetFocus;
 Assert(l_H <> 0);
 for l_Index := 1 to Length(l_S) do
 begin
  l_C := ORD(l_S[l_Index]);
  if (Windows.GetFocus <> l_H) then
   Windows.SetFocus(l_H);
  // - in some cases (for example, under debugger) focus “runs away” from control – that is why here patch is added
  SendMessage(l_H, WM_CHAR, l_C, 0);
 end;//for l_Index
end;//TkwEmitString.DoIt
 
initialization
 ScriptEngine.RegisterKeyWord(TkwEmitString, 'EmitString');

The example of using:

'Hello, world!' EmitString

And the “auxiliary” word:

PROCEDURE "Input the string" STRING IN aString
 aString EmitString
END //" Input the string"

Then the example is rewritten in this way:

"Input the string {('Hello, world!')}"

Taking into account the remark (http://18delphi.blogspot.ru/2013/11/gui_1949.html .) in this way:

'Hello, world!' "Input the string"

I think we’ll close here for now.

Комментариев нет:

Отправить комментарий