1
- import { ActionSequence , Capabilities , Command as WdCommand , FileDetector , Options , promise as wdpromise , Session , TargetLocator , TouchSequence , until , WebDriver , WebElement } from 'selenium-webdriver' ;
1
+ import { ActionSequence , By , Capabilities , Command as WdCommand , FileDetector , ICommandName , Options , promise as wdpromise , Session , TargetLocator , TouchSequence , until , WebDriver , WebElement } from 'selenium-webdriver' ;
2
2
import * as url from 'url' ;
3
3
4
4
import { DebugHelper } from './debugger' ;
@@ -9,10 +9,11 @@ import {Locator, ProtractorBy} from './locators';
9
9
import { Logger } from './logger' ;
10
10
import { Plugins } from './plugins' ;
11
11
12
- let clientSideScripts = require ( './clientsidescripts' ) ;
13
- let webdriver = require ( 'selenium-webdriver' ) ;
14
- let Command = require ( 'selenium-webdriver/lib/command' ) . Command ;
15
- let CommandName = require ( 'selenium-webdriver/lib/command' ) . Name ;
12
+ const clientSideScripts = require ( './clientsidescripts' ) ;
13
+ const webdriver = require ( 'selenium-webdriver' ) ;
14
+ // TODO: fix the typings for selenium-webdriver/lib/command
15
+ const Command = require ( 'selenium-webdriver/lib/command' ) . Command as typeof WdCommand ;
16
+ const CommandName = require ( 'selenium-webdriver/lib/command' ) . Name as ICommandName ;
16
17
17
18
// jshint browser: true
18
19
@@ -244,7 +245,7 @@ export class ProtractorBrowser extends Webdriver {
244
245
* @type {Array<{name: string, script: function|string, args:
245
246
* Array.<string>}> }
246
247
*/
247
- mockModules_ : any [ ] ;
248
+ mockModules_ : { name : string , script : string | Function , args : any [ ] } [ ] ;
248
249
249
250
/**
250
251
* If specified, start a debugger server at specified port instead of repl
@@ -279,8 +280,8 @@ export class ProtractorBrowser extends Webdriver {
279
280
let methodsToSync = [ 'getCurrentUrl' , 'getPageSource' , 'getTitle' ] ;
280
281
281
282
// Mix all other driver functionality into Protractor.
282
- Object . getOwnPropertyNames ( webdriver . WebDriver . prototype ) . forEach ( ( method : string ) => {
283
- if ( ! this [ method ] && typeof ( webdriverInstance as any ) [ method ] == 'function' ) {
283
+ Object . getOwnPropertyNames ( WebDriver . prototype ) . forEach ( method => {
284
+ if ( ! this [ method ] && typeof ( webdriverInstance as any ) [ method ] === 'function' ) {
284
285
if ( methodsToSync . indexOf ( method ) !== - 1 ) {
285
286
ptorMixin ( this , webdriverInstance , method , this . waitForAngular . bind ( this ) ) ;
286
287
} else {
@@ -291,8 +292,8 @@ export class ProtractorBrowser extends Webdriver {
291
292
292
293
this . driver = webdriverInstance ;
293
294
this . element = buildElementHelper ( this ) ;
294
- this . $ = build$ ( this . element , webdriver . By ) ;
295
- this . $$ = build$$ ( this . element , webdriver . By ) ;
295
+ this . $ = build$ ( this . element , By ) ;
296
+ this . $$ = build$$ ( this . element , By ) ;
296
297
this . baseUrl = opt_baseUrl || '' ;
297
298
this . rootEl = opt_rootElement || 'body' ;
298
299
this . ignoreSynchronization = false ;
@@ -442,7 +443,7 @@ export class ProtractorBrowser extends Webdriver {
442
443
443
444
let runWaitForAngularScript : ( ) => wdpromise . Promise < any > = ( ) => {
444
445
if ( this . plugins_ . skipAngularStability ( ) ) {
445
- return webdriver . promise . fulfilled ( ) ;
446
+ return wdpromise . fulfilled ( ) ;
446
447
} else if ( this . rootEl ) {
447
448
return this . executeAsyncScript_ (
448
449
clientSideScripts . waitForAngular , 'Protractor.waitForAngular()' + description ,
@@ -472,9 +473,7 @@ export class ProtractorBrowser extends Webdriver {
472
473
. then ( ( ) => {
473
474
return this . driver . wait ( ( ) => {
474
475
return this . plugins_ . waitForCondition ( ) . then ( ( results : boolean [ ] ) => {
475
- return results . reduce ( ( x , y ) => {
476
- return x && y ;
477
- } , true ) ;
476
+ return results . reduce ( ( x , y ) => x && y , true ) ;
478
477
} ) ;
479
478
} , this . allScriptsTimeout , 'Plugins.waitForCondition()' ) ;
480
479
} ) ;
@@ -580,8 +579,7 @@ export class ProtractorBrowser extends Webdriver {
580
579
* Add a module to load before Angular whenever Protractor.get is called.
581
580
* Modules will be registered after existing modules already on the page,
582
581
* so any module registered here will override preexisting modules with the
583
- * same
584
- * name.
582
+ * same name.
585
583
*
586
584
* @example
587
585
* browser.addMockModule('modName', function() {
@@ -629,9 +627,7 @@ export class ProtractorBrowser extends Webdriver {
629
627
* @returns {Array.<!string|Function> } The list of mock modules.
630
628
*/
631
629
getRegisteredMockModules ( ) : Array < string | Function > {
632
- return this . mockModules_ . map ( ( module ) => {
633
- return module . script ;
634
- } ) ;
630
+ return this . mockModules_ . map ( module => module . script ) ;
635
631
} ;
636
632
637
633
/**
@@ -661,9 +657,7 @@ export class ProtractorBrowser extends Webdriver {
661
657
* @param {number= } opt_timeout Number of milliseconds to wait for Angular to
662
658
* start.
663
659
*/
664
- get ( destination : string , opt_timeout ?: number ) {
665
- let timeout = opt_timeout ? opt_timeout : this . getPageTimeout ;
666
-
660
+ get ( destination : string , timeout = this . getPageTimeout ) {
667
661
destination = this . baseUrl . indexOf ( 'file://' ) === 0 ? this . baseUrl + destination :
668
662
url . resolve ( this . baseUrl , destination ) ;
669
663
let msg = ( str : string ) => {
@@ -672,17 +666,14 @@ export class ProtractorBrowser extends Webdriver {
672
666
673
667
if ( this . ignoreSynchronization ) {
674
668
this . driver . get ( destination ) ;
675
- return this . driver . controlFlow ( ) . execute ( ( ) => {
676
- return this . plugins_ . onPageLoad ( ) ;
677
- } ) ;
669
+ return this . driver . controlFlow ( ) . execute ( ( ) => this . plugins_ . onPageLoad ( ) ) . then ( ( ) => { } ) ;
678
670
}
679
671
680
- let deferred = webdriver . promise . defer ( ) ;
672
+ let deferred = wdpromise . defer < void > ( ) ;
681
673
682
674
this . driver . get ( this . resetUrl ) . then ( null , deferred . reject ) ;
683
675
this . executeScriptWithDescription (
684
676
'window.name = "' + DEFER_LABEL + '" + window.name;' +
685
-
686
677
'window.location.replace("' + destination + '");' ,
687
678
msg ( 'reset url' ) )
688
679
. then ( null , deferred . reject ) ;
@@ -741,16 +732,11 @@ export class ProtractorBrowser extends Webdriver {
741
732
let self = this ;
742
733
function loadMocks ( angularVersion : number ) {
743
734
if ( angularVersion === 1 ) {
744
- // At this point, Angular will pause for us until
745
- // angular.resumeBootstrap
746
- // is called.
735
+ // At this point, Angular will pause for us until angular.resumeBootstrap is called.
747
736
let moduleNames : string [ ] = [ ] ;
748
- for ( let i = 0 ; i < self . mockModules_ . length ; ++ i ) {
749
- let mockModule = self . mockModules_ [ i ] ;
750
- let name = mockModule . name ;
737
+ for ( const { name, script, args} of self . mockModules_ ) {
751
738
moduleNames . push ( name ) ;
752
- let executeScriptArgs =
753
- [ mockModule . script , msg ( 'add mock module ' + name ) ] . concat ( mockModule . args ) ;
739
+ let executeScriptArgs = [ script , msg ( 'add mock module ' + name ) , ...args ] ;
754
740
self . executeScriptWithDescription . apply ( self , executeScriptArgs )
755
741
. then (
756
742
null ,
@@ -776,13 +762,9 @@ export class ProtractorBrowser extends Webdriver {
776
762
}
777
763
778
764
this . driver . controlFlow ( ) . execute ( ( ) => {
779
- return self . plugins_ . onPageStable ( ) . then (
780
- ( ) => {
781
- deferred . fulfill ( ) ;
782
- } ,
783
- ( error : Error ) => {
784
- deferred . reject ( error ) ;
785
- } ) ;
765
+ return this . plugins_ . onPageStable ( ) . then ( ( ) => {
766
+ deferred . fulfill ( ) ;
767
+ } , deferred . reject ) ;
786
768
} ) ;
787
769
788
770
return deferred . promise ;
@@ -885,7 +867,7 @@ export class ProtractorBrowser extends Webdriver {
885
867
debugger ( ) {
886
868
// jshint debug: true
887
869
this . driver . executeScript ( clientSideScripts . installInBrowser ) ;
888
- webdriver . promise . controlFlow ( ) . execute ( ( ) => {
870
+ wdpromise . controlFlow ( ) . execute ( ( ) => {
889
871
debugger ;
890
872
} , 'add breakpoint to control flow' ) ;
891
873
}
@@ -944,7 +926,7 @@ export class ProtractorBrowser extends Webdriver {
944
926
pause ( opt_debugPort ?: number ) : webdriver . promise . Promise < any > {
945
927
if ( this . debugHelper . isAttached ( ) ) {
946
928
logger . info ( 'Encountered browser.pause(), but debugger already attached.' ) ;
947
- return webdriver . promise . fulfilled ( true ) ;
929
+ return wdpromise . fulfilled ( true ) ;
948
930
}
949
931
let debuggerClientPath = __dirname + '/debugger/clients/wddebugger.js' ;
950
932
let onStartFn = ( firstTime : boolean ) => {
0 commit comments