-
-
Notifications
You must be signed in to change notification settings - Fork 750
Expand file tree
/
Copy pathexecuteScript.mustache
More file actions
26 lines (22 loc) · 794 Bytes
/
executeScript.mustache
File metadata and controls
26 lines (22 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Executes sync script on a page.
Pass arguments to function as additional parameters.
Will return execution result to a test.
In this case you should use async function and await to receive results.
Example with jQuery DatePicker:
```js
// change date of jQuery DatePicker
I.executeScript(function() {
// now we are inside browser context
$('date').datetimepicker('setDate', new Date());
});
```
Can return values. Don't forget to use `await` to get them.
```js
let date = await I.executeScript(function(el) {
// only basic types can be returned
return $(el).datetimepicker('getDate').toString();
}, '#date'); // passing jquery selector
```
@param {string|function} fn function to be executed in browser context.
@param {...any} args to be passed to function.
@return {Promise<any>}