18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Problem setting a variable with _prompt()

BruceRBruceR Members
edited November -1 in Sahi - Open Source
Here is the part of my sah script that is having problems (note: to be able to post, I changed the 'at' char to '-at-'):
var $tPrefix;
_set($tPrefix, _prompt("EMail prefix"));
var $tEMail = $tPrefix + "-at-yahoo.com";
_setValue(_textbox("email"), $tEMail);
_setValue(_textbox("email"), _prompt("EMail"));

When run:
The first _textbox("email") is set to: "null-at-yahoo.com"
The second _textbox("email") is correctly set to what I type in
the prompt box.

This is what I see in the log window:
setServerVar('\$tPrefix', _prompt("EMail prefix"));
_setValue(_textbox("email"), "null-at-yahoo.com");
_setValue(_textbox("email"), _prompt("EMail"));

This what is in the parsed log:
var $tPrefix;
_sahi.schedule("_sahi.setServerVar('\\$tPrefix', _sahi._prompt(\"EMail prefix\"));", "/mnt/rel.package/archive/qa/sahi/userdata/scripts/tmp/idsafe1.sah&n=5");
$tPrefix = _sahi.getServerVar('\$tPrefix');
var $tEMail = $tPrefix + "-at-yahoo.com";
_sahi.schedule("_sahi._setValue(_sahi._textbox(\"email\"), "+s_v($tEMail)+");", "/mnt/rel.package/archive/qa/sahi/userdata/scripts/tmp/idsafe1.sah&n=8");
_sahi.schedule("_sahi._setValue(_sahi._textbox(\"email\"), _sahi._prompt(\"EMail\"));", "/mnt/rel.package/archive/qa/sahi/userdata/scripts/tmp/idsafe1.sah&n=9");


Could it be the '\\$tPrefix' is the problem?
I'm using version 2010-08-20 running on Debian Linux.

Thanks for this easy to setup and use tool, while still allowing for more advanced uses--that's a hard balance to get right.

Comments

  • narayannarayan Administrators
    Hi Bruce,

    We will test out this scenario and get back to you. There may be some problem in the _prompt + _set combination in Sahi.

    Regards,
    Narayan
  • // Workaround for the example problem code
    var $tPrefix = null;
    var $tEMail = null;
    _setValue(_textbox("email"), _prompt("EMail prefix"));
    _set($tPrefix, _textbox("email").value);
    $tEMail = $tPrefix + "-at-yahoo.com";
    _setValue(_textbox("email"), $tEMail);
  • narayannarayan Administrators
    Hi Bruce,

    Glad you found a work around. There is a bug using _prompt from _set. Btw, did you add _prompt to scheduler_functions.txt or normal_functions.txt? Other wise this code would not have worked.

    Also note that _prompt will cause playback to stop, so you may not be able to run the script without user interaction. (User interaction will prevent unattended automation.)

    Regards,
    Narayan
  • Hi Narayan,

    Yes I added _prompt to normal_functions.txt; it works great. I'm initially using sahi as a big macro tool. As I get the scripts tuned, the _prompt calls will be replaced with values from csv files or from generated data.

    Best regards,

    _BruceR
Sign In or Register to comment.