0

I'm using the Kantu web automation tool for the first time. Most of it is intuitive, but I'm now encountering an error when looping through a CSV. The relevant part of my script is:

{
  "Command": "echo",
  "Target": "Found customer with email ${emailAddress}",
  "Value": ""
},
{
  "Command": "echo",
  "Target": "Expected email name: ${!COL1}",
  "Value": ""
},
{
  "Command": "if",
  "Target": "${emailAddress} == \"${!COL1}@domain.com\"",
  "Value": ""
},

This produces the following log:

[info] Executing: | echo | Found customer with email ${emailAddress} | |

[echo] Found customer with email 70866223@domain.com

[info] Executing: | echo | Expected email name: ${!COL1} | |

[echo] Expected email name: 70866223

[info] Executing: | if | ${emailAddress} == "${!COL1}@domain.com" | |

[error] Error in runEval condition of if: Invalid or unexpected token

So you can see the variables ${emailAddress} and ${!COL1} are stored correctly, but my if condition is not evaluating correctly. I've also tried changing \"${!COL1}@domain.com\" to ${!COL1} + \"@domain.com\" with same result.

I assume this is something to do with escape characters or something, but I can't find anything related in the docs. Any pointers appreciated.

Community
  • 1
  • 1
Tom Troughton
  • 3,941
  • 2
  • 37
  • 77

1 Answers1

2

The if expression is handled like in storeEval. To quote from one of the storeEval examples in the docs :

x="${myvar}"; x.length;

Note that our variable ${myvar} is converted to a text string before the Javascript EVAL is executed. Therefore ${myvar} has to be inside "..." like any other text.

So I'd say the reason your code fails on the if is that your ${emailAddress} is not inside a String.

"${emailAddress}" == "${!COL1}@domain.com"

should work.

Community
  • 1
  • 1
Pinkie Pie
  • 688
  • 7
  • 15
  • Hey @PinkiePie, what is your gripe with my edits to this reply? The syntax I gave was 100% correct - so why did you decline it? – SilSur May 17 '19 at 12:23
  • @getsetcode - { "Command": "if", "Target": "\"${emailAddress}\" == \"${!COL1}@domain.com\"", "Value": "" } ... this is the correct code to your problem. – SilSur May 17 '19 at 12:24
  • Hey @SilSur, your suggested edit was peer reviewed. You can check out the status and the reasons for rejection here https://stackoverflow.com/review/suggested-edits/23034100 Hope that helps :) – Pinkie Pie May 22 '19 at 07:11