@@ -454,15 +454,15 @@ WebDriverJsController.prototype._constructWebDriver = function() {
454454 return webdriver . WebDriver . createSession ( executor , capabilities ) . getSession ( ) ;
455455 } ) ;
456456
457- this . driver = this . visualizer . driver = new webdriver . WebDriver ( session , executor ) ;
457+ this . _driver = this . visualizer . driver = new webdriver . WebDriver ( session , executor ) ;
458458
459459 this . webDriverUrlPort = webDriverUrlPort ;
460460 if ( localStorage )
461461 localStorage . webDriverUrlPort = webDriverUrlPort ;
462462 }
463463
464464 if ( this . webPage != webPage ) {
465- this . driver . get ( webPage ) ;
465+ this . _driver . get ( webPage ) ;
466466 this . element = null ;
467467
468468 this . webPage = webPage ;
@@ -471,6 +471,12 @@ WebDriverJsController.prototype._constructWebDriver = function() {
471471 }
472472}
473473
474+ WebDriverJsController . prototype . driver = function ( ) {
475+ if ( this . _driver === null )
476+ this . _constructWebDriver ( ) ;
477+ return this . _driver ;
478+ }
479+
474480WebDriverJsController . prototype . get = function ( ) {
475481 this . webPage = null ;
476482 this . _constructWebDriver ( ) ;
@@ -482,8 +488,7 @@ WebDriverJsController.prototype.source = function() {
482488}
483489
484490WebDriverJsController . prototype . screenshot = function ( ) {
485- this . _constructWebDriver ( ) ;
486- this . driver . takeScreenshot ( ) . then ( function ( data ) {
491+ this . driver ( ) . takeScreenshot ( ) . then ( function ( data ) {
487492 data = base64_arraybuffer . decode ( data ) ;
488493 data = new Blob ( [ data ] , { type : 'image/png' } ) ;
489494 saveAs ( data , 'screenshot.png' ) ;
@@ -494,8 +499,7 @@ WebDriverJsController.prototype.logs = function(type) {
494499 if ( type === 'Logs' )
495500 return ;
496501
497- this . _constructWebDriver ( ) ;
498- this . driver . manage ( ) . logs ( ) . get ( type ) . then ( function ( entries ) {
502+ this . driver ( ) . manage ( ) . logs ( ) . get ( type ) . then ( function ( entries ) {
499503 var lines = [ ] ;
500504 for ( var entryIndex in entries ) {
501505 var entry = entries [ entryIndex ] ;
@@ -508,38 +512,33 @@ WebDriverJsController.prototype.logs = function(type) {
508512}
509513
510514WebDriverJsController . prototype . findElement = function ( ) {
511- this . _constructWebDriver ( ) ;
512515 var criteria = document . getElementsByName ( 'findElementCriteria' ) [ 0 ] . value ;
513516 var key = document . getElementsByName ( 'findElementKey' ) [ 0 ] . value ;
514517 if ( criteria === 'id' )
515- this . element = this . driver . findElement ( webdriver . By . id ( key ) ) ;
518+ this . element = this . driver ( ) . findElement ( webdriver . By . id ( key ) ) ;
516519 else if ( criteria === 'name' )
517- this . element = this . driver . findElement ( webdriver . By . name ( key ) ) ;
520+ this . element = this . driver ( ) . findElement ( webdriver . By . name ( key ) ) ;
518521 else if ( criteria === 'tagName' )
519- this . element = this . driver . findElement ( webdriver . By . tagName ( key ) ) ;
522+ this . element = this . driver ( ) . findElement ( webdriver . By . tagName ( key ) ) ;
520523 else if ( criteria === 'xpath' )
521- this . element = this . driver . findElement ( webdriver . By . xpath ( key ) ) ;
524+ this . element = this . driver ( ) . findElement ( webdriver . By . xpath ( key ) ) ;
522525}
523526
524527WebDriverJsController . prototype . sendKeys = function ( key ) {
525- this . _constructWebDriver ( ) ;
526528 if ( this . element ) {
527529 this . element . sendKeys ( key ) ;
528530 } else {
529- this . driver . actions ( ) . sendKeys ( key ) . perform ( ) ;
531+ this . driver ( ) . actions ( ) . sendKeys ( key ) . perform ( ) ;
530532 }
531533}
532534
533535WebDriverJsController . prototype . click = function ( ) {
534- this . _constructWebDriver ( ) ;
535536 this . element . click ( ) ;
536537}
537538
538539WebDriverJsController . prototype . listWindowHandles = function ( ) {
539- this . _constructWebDriver ( ) ;
540-
541540 var select = document . getElementById ( 'windowList' ) ;
542- this . driver . getAllWindowHandles ( ) . then ( function ( handles ) {
541+ this . driver ( ) . getAllWindowHandles ( ) . then ( function ( handles ) {
543542 select . innerHTML = '' ;
544543 for ( var handle in handles ) {
545544 var item = document . createElement ( 'option' ) ;
@@ -552,25 +551,23 @@ WebDriverJsController.prototype.listWindowHandles = function() {
552551}
553552
554553WebDriverJsController . prototype . chooseWindow = function ( ) {
555- this . _constructWebDriver ( ) ;
556554 var handle = document . getElementById ( 'windowList' ) . value ;
557- this . driver . switchTo ( ) . window ( handle ) ;
555+ this . driver ( ) . switchTo ( ) . window ( handle ) ;
558556}
559557
560558WebDriverJsController . prototype . setWindowSize = function ( ) {
561- this . _constructWebDriver ( ) ;
562559 var width = document . getElementsByName ( 'windowSizeWidth' ) [ 0 ] . value ;
563560 var height = document . getElementsByName ( 'windowSizeHeight' ) [ 0 ] . value ;
564561 width = parseInt ( width ) ;
565562 height = parseInt ( height ) ;
566- this . driver . manage ( ) . window ( ) . setSize ( width , height ) ;
563+ this . driver ( ) . manage ( ) . window ( ) . setSize ( width , height ) ;
567564}
568565
569566WebDriverJsController . prototype . quit = function ( ) {
570- if ( ! this . driver )
567+ if ( ! this . _driver )
571568 return ;
572569
573- this . driver . quit ( ) ;
570+ this . _driver . quit ( ) ;
574571 this . visualizer . quit ( ) ;
575572 this . webDriverUrlPort = null ;
576573 this . webPage = null ;
0 commit comments