But please note: .includes
is ES6 level Javascript. It can not be used in executeScript_Sandbox and in IF_v2/While/RepeatIF. The ES5 alternative to ES6 .includes is to use .indexOf.
So there are two solutions:
-
Move your code into an executeScript statement and do the check there. Then your code will work without changes.
-
OR: Replace .includes with
.indexOf
Both options are shown in this example:
{
"Name": "indexOf",
"CreationDate": "2022-4-22",
"Commands": [
{
"Command": "executeScript",
"Target": "const a1 = [\"hello\",\"guten tag\",\"bonjour\"]; return a1;",
"Value": "mya1",
"Description": ""
},
{
"Command": "comment",
"Target": "To .includes, which is ES6 => we must use executeScript!",
"Value": "mya1",
"Description": ""
},
{
"Command": "executeScript",
"Target": "var b = false; if (${mya1}.includes(\"hello\") ) b = true; return b;",
"Value": "myb",
"Description": ""
},
{
"Command": "if_v2",
"Target": "${myb}",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "Test1: yes ",
"Value": "green",
"Description": ""
},
{
"Command": "else",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "test1: no",
"Value": "pink",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "comment",
"Target": "Or use use .indexOF - this can be done directly inside IF ",
"Value": "",
"Description": ""
},
{
"Command": "if_v2",
"Target": "${mya1}.indexOf(\"hello\") > -1 ",
"Value": "IF uses only ES5 Javascript, so we use indexOF instead of include",
"Description": ""
},
{
"Command": "echo",
"Target": "test2: yes ",
"Value": "yellow",
"Description": ""
},
{
"Command": "else",
"Target": "",
"Value": "",
"Description": ""
},
{
"Command": "echo",
"Target": "test2: no",
"Value": "brown",
"Description": ""
},
{
"Command": "end",
"Target": "",
"Value": "",
"Description": ""
}
]
}
PS: See How to replace includes with indexOf and How to replace startswith with indexOf