Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Executejs arguments #780

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions doc/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,17 @@ call:
* `flick(offsets, speed, element)` — flick element with starting point at its
center by `offsets.x` and `offset.y` offsets.

* `executeJS(function(window))` — run specified function in a browser. The
argument of a function is the browser's `window` object:
* `executeJS(function(window, [args]), [args])` — run specified function in a browser. The
argument of a function is the browser's `window` object and optional arguments:

```js
actions.executeJS(function(window) {
window.alert('Hello!');
});
actions.executeJS(function(window, name) {
window.alert('Hello!', name);
}, name);
```

Note that function is executed in a browser context, so any references to
outer scope of callback won't work.
outer scope of callback won't work unless passed via args.

:warning: `window.scrollTo` does not work in [email protected] (see [details](https://github.com/operasoftware/operaprestodriver/issues/108)).

Expand Down
6 changes: 3 additions & 3 deletions lib/tests-api/actions-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,13 @@ module.exports = inherit({
return this;
},

executeJS: function(callback) {
executeJS: function(callback, args) {
if (typeof callback !== 'function') {
throw new TypeError('executeJS argument should be function');
}

this._pushAction(this.executeJS, function executeJS(browser) {
return browser.execute(serializeFunc(callback));
return browser.execute(serializeFunc(callback), args);
});
return this;
},
Expand Down Expand Up @@ -392,7 +392,7 @@ function replaceStack(error, stack) {
}

function serializeFunc(func) {
return '(' + func.toString() + '(window));';
return '(' + func.toString() + ').apply(null, [window].concat(Array.prototype.slice.call(arguments)));';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you use null instead of window?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. null should get replaced with the global object, which in the browser is window, so I believe they're equivalent. I can change it to window.

}

function findElement(element, browser) {
Expand Down