* Executes a script on the page: * * ```js * I.executeScript(() => window.alert('Hello world')); * ``` * * Additional parameters of the function can be passed as an object argument: * * ```js * I.executeScript(({x, y}) => x + y, {x, y}); * ``` * You can pass only one
(fn, arg)
| 2670 | * @returns {Promise<any>} |
| 2671 | */ |
| 2672 | async executeScript(fn, arg) { |
| 2673 | if (arg && typeof arg.getNativeElement === 'function') arg = arg.getNativeElement() |
| 2674 | if (arg && typeof arg.evaluate === 'function' && typeof arg.locator === 'function') { |
| 2675 | return arg.evaluate(fn) |
| 2676 | } |
| 2677 | if (this.context && typeof this.context.url !== 'function' && typeof this.context.innerText !== 'function') { |
| 2678 | return this.context.locator(':root').evaluate(fn, arg) |
| 2679 | } |
| 2680 | return this.page.evaluate.apply(this.page, [fn, arg]) |
| 2681 | } |
| 2682 | |
| 2683 | /** |
| 2684 | * Grab Locator if called within Context |
no test coverage detected