Interview Questions

Type special chars in WinRuneer

Mercury WinRunner FAQ


(Continued from previous question...)

Type special chars in WinRuneer

type special chars as they are, instead of interpreting them
# data can be read from a data file and then typed into an app
#
# escape the following chars: <> - +
# in a string, quote " and backslash \ will already be escaped
#
# generally won't be a lot of special chars, so
# use index instead of looping through each character
#
function no_special(data )
{
auto esc_data, i, p;
esc_data = "";
while(1)
{
p=32000;
i=index(data,"-");
p=i?(i<p?i:p):p;
i=index(data,"+");
p=i?(i<p?i:p):p;
i=index(data,"<");
p=i?(i<p?i:p):p;
i=index(data,">");
p=i?(i<p?i:p):p;
if (p<32000)
{
esc_data = esc_data substr(data,1,p-1) "\\" substr(data,p,1);
data = substr(data,p+1);
}
else break;
}
esc_data = esc_data data;
return esc_data;
}
# trial run here
data = "This -- is +the+ <yobbo> new test sample";
win_activate("Untitled - Notepad");
win_type("Untitled - Notepad", no_special(data));

(Continued on next question...)

Other Interview Questions