SyntaxError: Unexpected token '{' when if command is run

Hi everyone :slight_smile:
I am using Katalon recorder and I need to write an if-else condition so that a checkbox will be selected only if it is not already selected. I have used the variable “StateChx” to store the value True/False of the checkbox state.

Everything seems working fine but I get the error: SyntaxError: Unexpected token ‘{’ when Katalon runs the if command.

Can you please help with this?

Thanks.

here are the steps:

storeChecked | id=internalColor0 | StateChx
echo | | ${StateChx}
if | $ {StateChx} |
click | //*[@data-validationcode=“optionals”] |
else | |
click | id=internalColor0 |

Here the log:

[info] Executing: | storeChecked | id=internalColor0 | StateChx |

[info] Store ‘false’ into ‘StateChx’

[info] Executing: | echo | | ${StateChx} |

[info] Expand variable ‘${StateChx}’ into ‘false’

[info] Executing: | if | $ {StateChx} | |

[error] SyntaxError: Unexpected token ‘{’

[info] Test case failed

On the screenshot on the below page, there is an if…else sample that you can review.

Thank you very much for the article which I found really useful.

Unfortunately, the steps of the test case shown in the article do not
show an example of an If Else statement. The highlighted test case does but I cannot
see the steps as it shown in the screenshot.

example

You have unnecessary " " between “$” and “{”. You can see this in your log that when You use echo command it’s expand variable (which is change variable name into value itself)

If You want to check samples visit: https://docs.katalon.com/katalon-recorder/docs/samples.html#sample-project

1 Like