Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibility to pass arguments to "Execute Javascript" and "Execute Async Javascript" #60

Open
Marco85Li opened this issue Jan 15, 2015 · 1 comment

Comments

@Marco85Li
Copy link

Hi,

currently it's seem not possible to pass not primitive arguments to javascript code. Example:

in .tsv file:

${Name} =   Set Variable    MyName
${Surname} =    Set Variable    MySurname
${Person} = Create List ${Name} ${Surname}

Execute Javascript  showPerson('Mr.', ${Person}); # This is wrong for sure

And in the html file opened in a browser the Javascript function

function showAlert(title, person) {
      alert('You are ' + title + ' ' + person[0] + ' ' + person[1] );
}

Obviously in this case we can change the array "person" with two distinct parameters and solve the problem, but in case of complex objects it is not possible.

A possible enhancement could be an additional keyword

Execute Javascript With Arguments   code *args

Where "code" is just a single line of code (previously joined at tsv level if needed) and args is variadic.

The implementation could be very similar:

@RobotKeyword
@ArgumentNames({ "js", "*args" })
public Object executeJavascriptWithArguments(String js, Object ... args) {
        String.format("Executing JavaScript:\n%s", js); //TODO log args
        JavascriptExecutor je = (JavascriptExecutor) browserManagement.getCurrentWebDriver();
        return je.executeScript(js, args);
}

Equivalent implementation for the Asynchronous version of the keyword.

What do you think?

@Tattoo
Copy link

Tattoo commented Jul 16, 2015

You can already achieve this by crafting the javascript you want to execute correctly:

Execute Javascript    showPerson('Mr.', ['${Name}', '${Surname}']);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants