1

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:

{}

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.