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.

how to append a variable to a static string ?

tsivatsiva Members
edited November -1 in Sahi - Open Source
I am logging into an application using username and password. I am using a function for the login by declaring variable for the username and password. After successful login i need to verify mouse over action on a string ("Welcome +username"). I was able to login successfully but failing when the mouseover action is done. There was no error If i don't use a variable. Here is the error that i was getting.
_setValue(_textbox("j_username"), $test);
_setValue(_password("j_password"), "password");
_click(_imageSubmitButton("loginbtn.gif"));
_mouseOver(_cell((Welcome, "test")));
--Stopped Playback: FAILURE--
Here is the sahi code that i have written for the above function

$usrname="test";
$pasword="password";

function login($usrname, $pasword)
{
_setValue(_textbox("j_username"), $usrname);
_setValue(_password("j_password"), $pasword);
_click(_imageSubmitButton("loginbtn.gif"));
}
login($usrname,$pasword);

_mouseOver(_cell((Welcome, $usrname)));

Comments

  • Hi tsiva,

    You can use it like

    _mouseOver(_cell(("Welcome, "+$usrname)));

    OR

    var $str = "Welcome, "+$usrname;

    _mouseOver(_cell($str ));
  • Thanks for your response, but still its failing with this error message.
    _mouseOver(_cell("Welcome,"+"test"));
    Error: The parameter passed to _mouseOver was not found on the browser at Oct 21, 2011 11:07:42 AM

    The quotes around the variable name is taking when adding the name to the Welcome message and hence its throwing the error. The actual value supposed to be Welcome, Test (no quotes around the message).The quotes should not be there. How can i do that? I have to give the quotes when assigning a string to the variable. Please advise me.
  • narayannarayan Administrators
    tsiva, it is not the quotes, it is the space after the comma.
    Use
    "Welcome, "+$usrname
    not
    "Welcome,"+$usrname
  • Thanks Narayan. Now it works fine. Actual problem was that the first letter in the username used was not capitalized. After correcting the first letter of the first name it worked fine. Thanks for all of your help. You may close this issue if no one has any other issues related to this.
This discussion has been closed.