If condition syntex issue

${browserName}= Get Lambda Mobile Value By Key windowsBrowserName
###Getting browser name from config####

            IF     '${browserName}'     ==      'Chrome'
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"Chrome","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END
            ELSE IF    '${browserName}'    ==     'Firefox'
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"pw-firefox","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END
            ELSE
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"MicrosoftEdge","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END

Getting syntex error at if condition. Can anyone tell what i am doing wrong here for if condition syntex?

Errror: Invalid IF condition: Evaluating expression ‘$browserName ==’ failed: SyntaxError: invalid syntax (, line 1)

Hi Pankaj,

Too many spaces (first time I’ve seen that)

From the documentation IF/ELSE syntax:

The IF marker requires exactly one value that is the condition to evaluate

So you just need a single space either side of the == in your condition:

            IF     '${browserName}' == 'Chrome'
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"Chrome","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END
            ELSE IF    '${browserName}' == 'Firefox'
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"pw-firefox","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END
            ELSE
                    ${REMOTE_URL}=      Set Variable        ${ws_url}{"browserName":"MicrosoftEdge","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END

Dave.

1 Like

The problem are the END before ELSE IF and ELSE (/and spacing). See the modified block:

            IF     '${browserName}' == 'Chrome'
                    ${REMOTE_URL}=    Set Variable    ${ws_url} 
   "browserName":"Chrome","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            ELSE IF    '${browserName}' == 'Firefox'
                    ${REMOTE_URL}=    Set Variable    ${ws_url}    {"browserName":"pw-firefox","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            ELSE
                    ${REMOTE_URL}=    Set Variable    ${ws_url} 
   {"browserName":"MicrosoftEdge","browserVersion":"${browserVersion}","LT:Options":{"platform":"${platform}","user":"${LT_USERNAME}","accessKey":"${LT_ACCESS_KEY}","build":"${buildName}","name":"${testName}","tunnel": true,"network":true,"video":true,"console":true}}
            END
3 Likes

I missed that, good catch @HelioGuilherme66 :+1:

1 Like