PaddyOB
PaddyOB

Reputation: 33

Robot Framework - Execute JavaScript command not working

I am currently try to run some JavaScript within my robot framework code that creates a new function, and then uses the newly created function to return a value upon calling it. However, when I log the result to the console, I do. It get my desired output. Please help!

The code:

${test}=  Execute Javascript  return function test(){return 1}; test();

Log To Console  ${test}

The console output:

{}

Upvotes: 1

Views: 1734

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 385940

Move the return statement after the function definition, otherwise the return happens before test() is called.

*** Settings ***
Library  Selenium2Library

*** Test Cases ***
Example
    [Setup]     open browser  about:blank   chrome
    [Teardown]  close all browsers

    ${test}=  execute javascript  function test() {return 1}; return test();
    should be equal as strings  ${test}  1

Upvotes: 4

Related Questions