18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
Checking if a variable is defined within a script
Hi there,
I've tried many variations on this but with no success.
Checking if variable doesn't exist (works):
Checking if variable exists (does not work):
Given
I've tried many variations on this but with no success.
Checking if variable doesn't exist (works):
if(!$myVar)
{
//do stuff, works!
}
Checking if variable exists (does not work):
if($myVar)
{
//do stuff, does not run this code at all
}
if(typeof $myVar === "string")
{
//do stuff, doesnt work with variables set to a string
}
if((typeof $myVar === "string")==true)
{
//do stuff, still doesn't work
}
Given
$myVar = {street_one: "My street"}
if($myVar.hasOwnProperty('street_one'))
{
//do stuff, still doesn't work
}
Comments
Here is a sample code:
Check if this solves your issue.
Regards
Sumitra
Actual lines:
skips the if statement.
log:
http://sahi.co.in/forums/viewtopic.php?id=1502
EDIT:
Found out what the problem is, I have to put the code to run on a new line otherwise it is skipped, as follows:
This fails:
This works: