1818 */
1919
2020import { cloneDeep } from 'lodash' ;
21- import { IKey , logging } from 'selenium-webdriver' ;
21+ import { logging , Key , Origin } from 'selenium-webdriver' ;
22+ // @ts -ignore internal modules are not typed
23+ import { LegacyActionSequence } from 'selenium-webdriver/lib/actions' ;
2224import { takeUntil } from 'rxjs/operators' ;
2325
24- import Jimp , { Bitmap } from 'jimp' ;
26+ import Jimp from 'jimp' ;
2527import { modifyUrl } from '../../../src/core/utils' ;
2628import { WebElementWrapper } from './lib/web_element_wrapper' ;
2729import { FtrProviderContext } from '../ftr_provider_context' ;
@@ -32,9 +34,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
3234 const log = getService ( 'log' ) ;
3335 const config = getService ( 'config' ) ;
3436 const lifecycle = getService ( 'lifecycle' ) ;
35- const { driver, Key, LegacyActionSequence, browserType } = await getService (
36- '__webdriver__'
37- ) . init ( ) ;
37+ const { driver, browserType } = await getService ( '__webdriver__' ) . init ( ) ;
3838
3939 const isW3CEnabled = ( driver as any ) . executor_ . w3c === true ;
4040
@@ -57,7 +57,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
5757 /**
5858 * Keyboard events
5959 */
60- public readonly keys : IKey = Key ;
60+ public readonly keys = Key ;
6161
6262 /**
6363 * Browser name
@@ -77,10 +77,8 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
7777 * Returns instance of Actions API based on driver w3c flag
7878 * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_WebDriver.html#actions
7979 */
80- public getActions ( ) : any {
81- return this . isW3CEnabled
82- ? ( driver as any ) . actions ( )
83- : ( driver as any ) . actions ( { bridge : true } ) ;
80+ public getActions ( ) {
81+ return this . isW3CEnabled ? driver . actions ( ) : driver . actions ( { bridge : true } ) ;
8482 }
8583
8684 /**
@@ -102,7 +100,10 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
102100 * @return {Promise<{height: number, width: number, x: number, y: number}> }
103101 */
104102 public async getWindowSize ( ) : Promise < { height : number ; width : number ; x : number ; y : number } > {
105- return await ( driver . manage ( ) . window ( ) as any ) . getRect ( ) ;
103+ return await driver
104+ . manage ( )
105+ . window ( )
106+ . getRect ( ) ;
106107 }
107108
108109 /**
@@ -113,18 +114,19 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
113114 * @param {number } height
114115 * @return {Promise<void> }
115116 */
116- public async setWindowSize ( width : number , height : number ) : Promise < void > ;
117- public async setWindowSize ( ...args : number [ ] ) : Promise < void > ;
118- public async setWindowSize ( ...args : unknown [ ] ) : Promise < void > {
119- await ( driver . manage ( ) . window ( ) as any ) . setRect ( { width : args [ 0 ] , height : args [ 1 ] } ) ;
117+ public async setWindowSize ( width : number , height : number ) {
118+ await driver
119+ . manage ( )
120+ . window ( )
121+ . setRect ( { width, height } ) ;
120122 }
121123
122124 /**
123125 * Gets a screenshot of the focused window and returns it as a Bitmap object
124126 */
125- public async getScreenshotAsBitmap ( ) : Promise < Bitmap > {
127+ public async getScreenshotAsBitmap ( ) {
126128 const screenshot = await this . takeScreenshot ( ) ;
127- const buffer = Buffer . from ( screenshot . toString ( ) , 'base64' ) ;
129+ const buffer = Buffer . from ( screenshot , 'base64' ) ;
128130 const session = ( await Jimp . read ( buffer ) ) . clone ( ) ;
129131 return session . bitmap ;
130132 }
@@ -136,7 +138,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
136138 * @param {number } height
137139 * @return {Promise<void> }
138140 */
139- public async setScreenshotSize ( width : number , height : number ) : Promise < void > {
141+ public async setScreenshotSize ( width : number , height : number ) {
140142 log . debug ( `======browser======== setWindowSize ${ width } ${ height } ` ) ;
141143 // We really want to set the Kibana app to a specific size without regard to the browser chrome (borders)
142144 // But that means we first need to figure out the display scaling factor.
@@ -179,7 +181,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
179181 *
180182 * @return {Promise<string> }
181183 */
182- public async getCurrentUrl ( ) : Promise < string > {
184+ public async getCurrentUrl ( ) {
183185 // strip _t=Date query param when url is read
184186 const current = await driver . getCurrentUrl ( ) ;
185187 const currentWithoutTime = modifyUrl ( current , parsed => {
@@ -197,7 +199,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
197199 * @param {boolean } insertTimestamp Optional
198200 * @return {Promise<void> }
199201 */
200- public async get ( url : string , insertTimestamp : boolean = true ) : Promise < void > {
202+ public async get ( url : string , insertTimestamp : boolean = true ) {
201203 if ( insertTimestamp ) {
202204 const urlWithTime = modifyUrl ( url , parsed => {
203205 ( parsed . query as any ) . _t = Date . now ( ) ;
@@ -223,12 +225,12 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
223225 . move ( { x : 0 , y : 0 } )
224226 . perform ( ) ;
225227 await this . getActions ( )
226- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
228+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
227229 . perform ( ) ;
228230 } else {
229231 await this . getActions ( )
230232 . pause ( this . getActions ( ) . mouse )
231- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
233+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
232234 . perform ( ) ;
233235 }
234236 }
@@ -253,7 +255,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
253255 }
254256 return data . location instanceof WebElementWrapper
255257 ? { x : data . offset . x || 0 , y : data . offset . y || 0 , origin : data . location . _webElement }
256- : { x : data . location . x , y : data . location . y , origin : 'pointer' } ;
258+ : { x : data . location . x , y : data . location . y , origin : Origin . POINTER } ;
257259 } ;
258260
259261 const startPoint = getW3CPoint ( from ) ;
@@ -278,7 +280,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
278280 return await this . getActions ( )
279281 . move ( { origin : from . location . _webElement } )
280282 . press ( )
281- . move ( { x : to . location . x , y : to . location . y , origin : 'pointer' } )
283+ . move ( { x : to . location . x , y : to . location . y , origin : Origin . POINTER } )
282284 . release ( )
283285 . perform ( ) ;
284286 } else {
@@ -298,7 +300,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
298300 *
299301 * @return {Promise<void> }
300302 */
301- public async refresh ( ) : Promise < void > {
303+ public async refresh ( ) {
302304 await driver . navigate ( ) . refresh ( ) ;
303305 }
304306
@@ -308,10 +310,18 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
308310 *
309311 * @return {Promise<void> }
310312 */
311- public async goBack ( ) : Promise < void > {
313+ public async goBack ( ) {
312314 await driver . navigate ( ) . back ( ) ;
313315 }
314316
317+ /**
318+ * Moves forwards in the browser history.
319+ * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Navigation.html#forward
320+ */
321+ public async goForward ( ) {
322+ await driver . navigate ( ) . forward ( ) ;
323+ }
324+
315325 /**
316326 * Sends a sequance of keyboard keys. For each key, this will record a pair of keyDown and keyUp actions
317327 * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/input_exports_Actions.html#sendKeys
@@ -337,19 +347,19 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
337347 * @param {x: number, y: number } point on browser page
338348 * @return {Promise<void> }
339349 */
340- public async clickMouseButton ( point : { x : number ; y : number } ) : Promise < void > {
350+ public async clickMouseButton ( point : { x : number ; y : number } ) {
341351 if ( this . isW3CEnabled ) {
342352 await this . getActions ( )
343353 . move ( { x : 0 , y : 0 } )
344354 . perform ( ) ;
345355 await this . getActions ( )
346- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
356+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
347357 . click ( )
348358 . perform ( ) ;
349359 } else {
350360 await this . getActions ( )
351361 . pause ( this . getActions ( ) . mouse )
352- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
362+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
353363 . click ( )
354364 . perform ( ) ;
355365 }
@@ -362,7 +372,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
362372 *
363373 * @return {Promise<string> }
364374 */
365- public async getPageSource ( ) : Promise < string > {
375+ public async getPageSource ( ) {
366376 return await driver . getPageSource ( ) ;
367377 }
368378
@@ -372,7 +382,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
372382 *
373383 * @return {Promise<Buffer> }
374384 */
375- public async takeScreenshot ( ) : Promise < string > {
385+ public async takeScreenshot ( ) {
376386 return await driver . takeScreenshot ( ) ;
377387 }
378388
@@ -382,7 +392,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
382392 * @param {WebElementWrapper } element
383393 * @return {Promise<void> }
384394 */
385- public async doubleClick ( ) : Promise < void > {
395+ public async doubleClick ( ) {
386396 await this . getActions ( )
387397 . doubleClick ( )
388398 . perform ( ) ;
@@ -396,10 +406,8 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
396406 * @param {string } handle
397407 * @return {Promise<void> }
398408 */
399- public async switchToWindow ( handle : string ) : Promise < void > ;
400- public async switchToWindow ( ...args : string [ ] ) : Promise < void > ;
401- public async switchToWindow ( ...args : string [ ] ) : Promise < void > {
402- await ( driver . switchTo ( ) as any ) . window ( ...args ) ;
409+ public async switchToWindow ( nameOrHandle : string ) {
410+ await driver . switchTo ( ) . window ( nameOrHandle ) ;
403411 }
404412
405413 /**
@@ -408,7 +416,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
408416 *
409417 * @return {Promise<string[]> }
410418 */
411- public async getAllWindowHandles ( ) : Promise < string [ ] > {
419+ public async getAllWindowHandles ( ) {
412420 return await driver . getAllWindowHandles ( ) ;
413421 }
414422
@@ -434,7 +442,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
434442 *
435443 * @return {Promise<void> }
436444 */
437- public async closeCurrentWindow ( ) : Promise < void > {
445+ public async closeCurrentWindow ( ) {
438446 await driver . close ( ) ;
439447 }
440448
@@ -473,18 +481,18 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
473481 ) ;
474482 }
475483
476- public async getScrollTop ( ) : Promise < number > {
484+ public async getScrollTop ( ) {
477485 const scrollSize = await driver . executeScript < string > ( 'return document.body.scrollTop' ) ;
478486 return parseInt ( scrollSize , 10 ) ;
479487 }
480488
481- public async getScrollLeft ( ) : Promise < number > {
489+ public async getScrollLeft ( ) {
482490 const scrollSize = await driver . executeScript < string > ( 'return document.body.scrollLeft' ) ;
483491 return parseInt ( scrollSize , 10 ) ;
484492 }
485493
486494 // return promise with REAL scroll position
487- public async setScrollTop ( scrollSize : number | string ) : Promise < number > {
495+ public async setScrollTop ( scrollSize : number | string ) {
488496 await driver . executeScript ( 'document.body.scrollTop = ' + scrollSize ) ;
489497 return this . getScrollTop ( ) ;
490498 }
0 commit comments