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
2426import { modifyUrl } from '../../../src/core/utils' ;
@@ -31,9 +33,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
3133 const log = getService ( 'log' ) ;
3234 const config = getService ( 'config' ) ;
3335 const lifecycle = getService ( 'lifecycle' ) ;
34- const { driver, Key, LegacyActionSequence, browserType } = await getService (
35- '__webdriver__'
36- ) . init ( ) ;
36+ const { driver, browserType } = await getService ( '__webdriver__' ) . init ( ) ;
3737
3838 const isW3CEnabled = ( driver as any ) . executor_ . w3c === true ;
3939
@@ -56,7 +56,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
5656 /**
5757 * Keyboard events
5858 */
59- public readonly keys : IKey = Key ;
59+ public readonly keys = Key ;
6060
6161 /**
6262 * Browser name
@@ -76,10 +76,8 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
7676 * Returns instance of Actions API based on driver w3c flag
7777 * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_WebDriver.html#actions
7878 */
79- public getActions ( ) : any {
80- return this . isW3CEnabled
81- ? ( driver as any ) . actions ( )
82- : ( driver as any ) . actions ( { bridge : true } ) ;
79+ public getActions ( ) {
80+ return this . isW3CEnabled ? driver . actions ( ) : driver . actions ( { bridge : true } ) ;
8381 }
8482
8583 /**
@@ -101,7 +99,10 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
10199 * @return {Promise<{height: number, width: number, x: number, y: number}> }
102100 */
103101 public async getWindowSize ( ) : Promise < { height : number ; width : number ; x : number ; y : number } > {
104- return await ( driver . manage ( ) . window ( ) as any ) . getRect ( ) ;
102+ return await driver
103+ . manage ( )
104+ . window ( )
105+ . getRect ( ) ;
105106 }
106107
107108 /**
@@ -112,10 +113,11 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
112113 * @param {number } height
113114 * @return {Promise<void> }
114115 */
115- public async setWindowSize ( width : number , height : number ) : Promise < void > ;
116- public async setWindowSize ( ...args : number [ ] ) : Promise < void > ;
117- public async setWindowSize ( ...args : unknown [ ] ) : Promise < void > {
118- await ( driver . manage ( ) . window ( ) as any ) . setRect ( { width : args [ 0 ] , height : args [ 1 ] } ) ;
116+ public async setWindowSize ( width : number , height : number ) {
117+ await driver
118+ . manage ( )
119+ . window ( )
120+ . setRect ( { width, height } ) ;
119121 }
120122
121123 /**
@@ -124,7 +126,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
124126 *
125127 * @return {Promise<string> }
126128 */
127- public async getCurrentUrl ( ) : Promise < string > {
129+ public async getCurrentUrl ( ) {
128130 // strip _t=Date query param when url is read
129131 const current = await driver . getCurrentUrl ( ) ;
130132 const currentWithoutTime = modifyUrl ( current , parsed => {
@@ -142,7 +144,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
142144 * @param {boolean } insertTimestamp Optional
143145 * @return {Promise<void> }
144146 */
145- public async get ( url : string , insertTimestamp : boolean = true ) : Promise < void > {
147+ public async get ( url : string , insertTimestamp : boolean = true ) {
146148 if ( insertTimestamp ) {
147149 const urlWithTime = modifyUrl ( url , parsed => {
148150 ( parsed . query as any ) . _t = Date . now ( ) ;
@@ -168,12 +170,12 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
168170 . move ( { x : 0 , y : 0 } )
169171 . perform ( ) ;
170172 await this . getActions ( )
171- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
173+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
172174 . perform ( ) ;
173175 } else {
174176 await this . getActions ( )
175177 . pause ( this . getActions ( ) . mouse )
176- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
178+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
177179 . perform ( ) ;
178180 }
179181 }
@@ -198,7 +200,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
198200 }
199201 return data . location instanceof WebElementWrapper
200202 ? { x : data . offset . x || 0 , y : data . offset . y || 0 , origin : data . location . _webElement }
201- : { x : data . location . x , y : data . location . y , origin : 'pointer' } ;
203+ : { x : data . location . x , y : data . location . y , origin : Origin . POINTER } ;
202204 } ;
203205
204206 const startPoint = getW3CPoint ( from ) ;
@@ -223,7 +225,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
223225 return await this . getActions ( )
224226 . move ( { origin : from . location . _webElement } )
225227 . press ( )
226- . move ( { x : to . location . x , y : to . location . y , origin : 'pointer' } )
228+ . move ( { x : to . location . x , y : to . location . y , origin : Origin . POINTER } )
227229 . release ( )
228230 . perform ( ) ;
229231 } else {
@@ -243,7 +245,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
243245 *
244246 * @return {Promise<void> }
245247 */
246- public async refresh ( ) : Promise < void > {
248+ public async refresh ( ) {
247249 await driver . navigate ( ) . refresh ( ) ;
248250 }
249251
@@ -253,10 +255,18 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
253255 *
254256 * @return {Promise<void> }
255257 */
256- public async goBack ( ) : Promise < void > {
258+ public async goBack ( ) {
257259 await driver . navigate ( ) . back ( ) ;
258260 }
259261
262+ /**
263+ * Moves forwards in the browser history.
264+ * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Navigation.html#forward
265+ */
266+ public async goForward ( ) {
267+ await driver . navigate ( ) . forward ( ) ;
268+ }
269+
260270 /**
261271 * Sends a sequance of keyboard keys. For each key, this will record a pair of keyDown and keyUp actions
262272 * https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/input_exports_Actions.html#sendKeys
@@ -282,19 +292,19 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
282292 * @param {x: number, y: number } point on browser page
283293 * @return {Promise<void> }
284294 */
285- public async clickMouseButton ( point : { x : number ; y : number } ) : Promise < void > {
295+ public async clickMouseButton ( point : { x : number ; y : number } ) {
286296 if ( this . isW3CEnabled ) {
287297 await this . getActions ( )
288298 . move ( { x : 0 , y : 0 } )
289299 . perform ( ) ;
290300 await this . getActions ( )
291- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
301+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
292302 . click ( )
293303 . perform ( ) ;
294304 } else {
295305 await this . getActions ( )
296306 . pause ( this . getActions ( ) . mouse )
297- . move ( { x : point . x , y : point . y , origin : 'pointer' } )
307+ . move ( { x : point . x , y : point . y , origin : Origin . POINTER } )
298308 . click ( )
299309 . perform ( ) ;
300310 }
@@ -307,7 +317,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
307317 *
308318 * @return {Promise<string> }
309319 */
310- public async getPageSource ( ) : Promise < string > {
320+ public async getPageSource ( ) {
311321 return await driver . getPageSource ( ) ;
312322 }
313323
@@ -317,7 +327,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
317327 *
318328 * @return {Promise<Buffer> }
319329 */
320- public async takeScreenshot ( ) : Promise < string > {
330+ public async takeScreenshot ( ) {
321331 return await driver . takeScreenshot ( ) ;
322332 }
323333
@@ -327,7 +337,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
327337 * @param {WebElementWrapper } element
328338 * @return {Promise<void> }
329339 */
330- public async doubleClick ( ) : Promise < void > {
340+ public async doubleClick ( ) {
331341 await this . getActions ( )
332342 . doubleClick ( )
333343 . perform ( ) ;
@@ -341,10 +351,8 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
341351 * @param {string } handle
342352 * @return {Promise<void> }
343353 */
344- public async switchToWindow ( handle : string ) : Promise < void > ;
345- public async switchToWindow ( ...args : string [ ] ) : Promise < void > ;
346- public async switchToWindow ( ...args : string [ ] ) : Promise < void > {
347- await ( driver . switchTo ( ) as any ) . window ( ...args ) ;
354+ public async switchToWindow ( nameOrHandle : string ) {
355+ await driver . switchTo ( ) . window ( nameOrHandle ) ;
348356 }
349357
350358 /**
@@ -353,7 +361,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
353361 *
354362 * @return {Promise<string[]> }
355363 */
356- public async getAllWindowHandles ( ) : Promise < string [ ] > {
364+ public async getAllWindowHandles ( ) {
357365 return await driver . getAllWindowHandles ( ) ;
358366 }
359367
@@ -379,7 +387,7 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
379387 *
380388 * @return {Promise<void> }
381389 */
382- public async closeCurrentWindow ( ) : Promise < void > {
390+ public async closeCurrentWindow ( ) {
383391 await driver . close ( ) ;
384392 }
385393
@@ -418,18 +426,18 @@ export async function BrowserProvider({ getService }: FtrProviderContext) {
418426 ) ;
419427 }
420428
421- public async getScrollTop ( ) : Promise < number > {
429+ public async getScrollTop ( ) {
422430 const scrollSize = await driver . executeScript < string > ( 'return document.body.scrollTop' ) ;
423431 return parseInt ( scrollSize , 10 ) ;
424432 }
425433
426- public async getScrollLeft ( ) : Promise < number > {
434+ public async getScrollLeft ( ) {
427435 const scrollSize = await driver . executeScript < string > ( 'return document.body.scrollLeft' ) ;
428436 return parseInt ( scrollSize , 10 ) ;
429437 }
430438
431439 // return promise with REAL scroll position
432- public async setScrollTop ( scrollSize : number | string ) : Promise < number > {
440+ public async setScrollTop ( scrollSize : number | string ) {
433441 await driver . executeScript ( 'document.body.scrollTop = ' + scrollSize ) ;
434442 return this . getScrollTop ( ) ;
435443 }
0 commit comments