Javascript command does not work in executeScript_Sandbox

First i go to this link https://forum.ui.vision/t/using-an-if-to-check-that-a-string-contains-a-certain-substring/1741/4 and i try to run the script .Here it is but the script giving message “Undefined” that means not support the command ?

{
  "Name": "includes",
  "CreationDate": "2019-6-24",
  "Commands": [
    {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e"
    },
    {
      "Command": "if_v2",
      "Target": "${e}.includes (\"tim\") == true",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "yes, it contains this string",
      "Value": "blue"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}
Also i tried to run it with executeScript_Sandbox but then the command ignored and does not find the text in to variable. 
{
  "Name": "search",
  "CreationDate": "2022-10-6",
  "Commands": [
    {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "${e}.includes (\"tim\") == true",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "yes, it contains this string",
      "Value": "blue",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    }
  ]
}

And as i remember now also Trunc command didnt work .So what happening with javascript commands ?

Also i tried
${e}.includes (“tim”) == true
${e}.includes(“tim”) == true
${e}.includes(tim)
${e}.includes(“tim”)
(${e}.includes(tim))
and command indefOf also not work .

You have to return data in executescript and then do the check

or do conditional checks for true and false and do the echo

 {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e",
      "Description": ""
    },
    {
      "Command": "executeScript",
      "Target": "if (${e}.includes (\"tim\"))\n{\nreturn \"yes, it contains this string\";\n}\nelse\n{\nreturn \"no, it does not contains this string\";\n}",
      "Value": "Result",
      "Description": ""
    },
    {
      "Command": "echo",
      "Target": "${Result}",
      "Value": "blue",
      "Description": ""
    }

executeScript_Sandbox is giving error
[error] [Line 2]: undefined is not a function

1 Like

Thanks mate this woks for search .But if we want to tell to Executescript gotolabel A if contains the text or gotolabel B if not contains then how to do ?

then you need to return value with execute
and do conditional check with IF

1 Like

Thank you very much that worked .

My code is already returning value
you can add conditional check to the variable

This is because executeScript**_Sandbox** does not support the ES6 javascript command “.includes”. => The solution is to use .indexof instead of .includes.

So this version with .indexOf works in the sandbox:

{
  "Name": "include string test",
  "CreationDate": "2022-10-10",
  "Commands": [
    {
      "Command": "store",
      "Target": "test tim meyer",
      "Value": "e",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "if (${e}.indexOf (\"tim\") > -1)\n{\nreturn \"YES, it contains this string\";\n}\nelse\n{\nreturn \"NO, it does not contains this string\";\n}\n",
      "Value": "Result",
      "Description": "The ES5 alternative to .includes is .indexOf"
    },
    {
      "Command": "echo",
      "Target": "${Result}",
      "Value": "blue",
      "Description": ""
    }
  ]
}
1 Like

Thank you very much i will test it also later !