@@ -25,13 +25,13 @@ if (!String.prototype.endsWith) {
2525 } ) ;
2626}
2727
28- webdriver . FirstSessionBuilder = function ( ) {
28+ webdriver . ExistingSessionBuilder = function ( ) {
2929 webdriver . AbstractBuilder . call ( this ) ;
3030} ;
3131
32- webdriver . FirstSessionBuilder . prototype = new webdriver . AbstractBuilder ( ) ;
32+ webdriver . ExistingSessionBuilder . prototype = Object . create ( webdriver . AbstractBuilder . prototype ) ;
3333
34- webdriver . FirstSessionBuilder . prototype . build = function ( ) {
34+ webdriver . ExistingSessionBuilder . prototype . build = function ( ) {
3535 var self = this ;
3636 var client = new webdriver . http . CorsClient ( this . getServerUrl ( ) ) ;
3737 var executor = new webdriver . http . Executor ( client ) ;
@@ -60,6 +60,31 @@ webdriver.WebDriver.prototype.visualizerShowPoint = function() {
6060 'WebDriver.visualizerShowPoint()' ) ;
6161} ;
6262
63+ function WebDriverProxy ( ) {
64+ }
65+
66+ WebDriverProxy . prototype . setServerUrl = function ( serverUrl ) {
67+ var self = this ;
68+ this . driver_ = new webdriver . ExistingSessionBuilder ( ) .
69+ usingServer ( serverUrl ) .
70+ withCapabilities ( { 'browserName' : 'qtwebkit' } ) .
71+ build ( ) ;
72+
73+ for ( var propertyName in this . driver_ ) {
74+ var property = this . driver_ [ propertyName ] ;
75+ if ( typeof property === 'function' ) {
76+ this [ propertyName ] = function ( impl ) {
77+ return function ( ) {
78+ return impl . apply ( self . driver_ , arguments ) ;
79+ } ;
80+ } ( property ) ;
81+ }
82+ }
83+ } ;
84+
85+ WebDriverProxy . prototype . quit = function ( ) {
86+ } ;
87+
6388window . onerror = function ( errorMsg , url , lineNumber , columnNumber , error ) {
6489 console . log ( error . stack ) ;
6590 return false ;
@@ -192,8 +217,8 @@ Util.webDriverKeyFromJs = function(keyCode) {
192217} ;
193218
194219function VisualizerXsltProcessors ( ) {
195- this . widget = this . _create ( 'widget_view_visualizer.xsl' ) ;
196- this . qml = this . _create ( 'qml_view_visualizer.xsl' ) ;
220+ this . widget = this . create_ ( 'widget_view_visualizer.xsl' ) ;
221+ this . qml = this . create_ ( 'qml_view_visualizer.xsl' ) ;
197222}
198223
199224VisualizerXsltProcessors . prototype . get = function ( webPage ) {
@@ -203,7 +228,7 @@ VisualizerXsltProcessors.prototype.get = function(webPage) {
203228 return this . qml ;
204229} ;
205230
206- VisualizerXsltProcessors . prototype . _create = function ( name ) {
231+ VisualizerXsltProcessors . prototype . create_ = function ( name ) {
207232 var stylesheet = Util . loadFile ( name ) ;
208233 stylesheet = ( new DOMParser ( ) ) . parseFromString ( stylesheet , 'application/xml' ) ;
209234 var processor = new XSLTProcessor ( ) ;
@@ -215,7 +240,8 @@ VisualizerXsltProcessors.prototype._create = function(name) {
215240 }
216241} ;
217242
218- function VisualizerController ( ) {
243+ function VisualizerController ( driver ) {
244+ this . driver = driver ;
219245 this . xsltProcessors = new VisualizerXsltProcessors ( ) ;
220246}
221247
@@ -458,67 +484,63 @@ VisualizerController.prototype.showVisualizationWindow = function(source, size)
458484} ;
459485
460486function WebDriverJsController ( ) {
461- this . visualizer = new VisualizerController ( ) ;
487+ this . driver = new WebDriverProxy ( ) ;
488+ this . visualizer = new VisualizerController ( this . driver ) ;
462489}
463490
464- WebDriverJsController . prototype . _constructWebDriver = function ( ) {
465- var webDriverUrlPort = document . getElementsByName ( 'webDriverUrlPort' ) [ 0 ] . value ;
466- var webPage = document . getElementsByName ( 'webPage' ) [ 0 ] . value ;
467-
468- if ( this . webDriverUrlPort == webDriverUrlPort &&
469- this . webPage == webPage )
470- return ;
491+ WebDriverJsController . prototype . setServerUrl = function ( serverUrl ) {
492+ this . driver . setServerUrl ( serverUrl ) ;
471493
472- if ( this . webDriverUrlPort != webDriverUrlPort ) {
473- this . _driver = this . visualizer . driver = new webdriver . FirstSessionBuilder ( ) .
474- usingServer ( webDriverUrlPort ) .
475- withCapabilities ( { 'browserName' : 'qtwebkit' } ) .
476- build ( ) ;
494+ this . serverUrl = serverUrl ;
495+ if ( localStorage )
496+ localStorage . serverUrl = serverUrl ;
497+ }
477498
478- this . webDriverUrlPort = webDriverUrlPort ;
479- if ( localStorage )
480- localStorage . webDriverUrlPort = webDriverUrlPort ;
481- }
499+ WebDriverJsController . prototype . setWebPage = function ( webPage ) {
500+ this . element = null ;
482501
483- if ( this . webPage != webPage ) {
484- this . _driver . get ( webPage ) ;
485- this . element = null ;
502+ this . driver . get ( webPage ) ;
486503
487- this . webPage = webPage ;
488- if ( localStorage )
489- localStorage . webPage = webPage ;
490- }
504+ this . webPage = webPage ;
505+ if ( localStorage )
506+ localStorage . webPage = webPage ;
491507} ;
492508
493- WebDriverJsController . prototype . driver = function ( ) {
494- if ( this . _driver === null )
495- this . _constructWebDriver ( ) ;
496- return this . _driver ;
509+ WebDriverJsController . prototype . updateDriver = function ( ) {
510+ var webDriverUrlPort = document . getElementsByName ( 'webDriverUrlPort' ) [ 0 ] . value ;
511+ if ( webDriverUrlPort !== this . webDriverUrlPort )
512+ this . setServerUrl ( webDriverUrlPort ) ;
513+
514+ var webPage = document . getElementsByName ( 'webPage' ) [ 0 ] . value ;
515+ if ( webPage !== this . webPage )
516+ this . setWebPage ( webPage ) ;
497517} ;
498518
499- WebDriverJsController . prototype . get = function ( ) {
519+ WebDriverJsController . prototype . onGet = function ( ) {
500520 this . webPage = null ;
501- this . _constructWebDriver ( ) ;
521+ this . updateDriver ( ) ;
502522} ;
503523
504- WebDriverJsController . prototype . source = function ( ) {
505- this . _constructWebDriver ( ) ;
524+ WebDriverJsController . prototype . onSource = function ( ) {
525+ this . updateDriver ( ) ;
506526 this . visualizer . updateSource ( this . webPage ) ;
507527} ;
508528
509- WebDriverJsController . prototype . screenshot = function ( ) {
510- this . driver ( ) . takeScreenshot ( ) . then ( function ( data ) {
529+ WebDriverJsController . prototype . onScreenshot = function ( ) {
530+ this . updateDriver ( ) ;
531+ this . driver . takeScreenshot ( ) . then ( function ( data ) {
511532 data = base64_arraybuffer . decode ( data ) ;
512533 data = new Blob ( [ data ] , { type : 'image/png' } ) ;
513534 saveAs ( data , 'screenshot.png' ) ;
514535 } )
515536} ;
516537
517- WebDriverJsController . prototype . logs = function ( type ) {
538+ WebDriverJsController . prototype . onLogs = function ( type ) {
518539 if ( type === 'Logs' )
519540 return ;
520541
521- this . driver ( ) . manage ( ) . logs ( ) . get ( type ) . then ( function ( entries ) {
542+ this . updateDriver ( ) ;
543+ this . driver . manage ( ) . logs ( ) . get ( type ) . then ( function ( entries ) {
522544 var lines = [ ] ;
523545 for ( var entryIndex in entries ) {
524546 var entry = entries [ entryIndex ] ;
@@ -530,34 +552,34 @@ WebDriverJsController.prototype.logs = function(type) {
530552 } )
531553} ;
532554
533- WebDriverJsController . prototype . findElement = function ( ) {
555+ WebDriverJsController . prototype . onFindElement = function ( ) {
534556 var criteria = document . getElementsByName ( 'findElementCriteria' ) [ 0 ] . value ;
535557 var key = document . getElementsByName ( 'findElementKey' ) [ 0 ] . value ;
536558 if ( criteria === 'id' )
537- this . element = this . driver ( ) . findElement ( webdriver . By . id ( key ) ) ;
559+ this . element = this . driver . findElement ( webdriver . By . id ( key ) ) ;
538560 else if ( criteria === 'name' )
539- this . element = this . driver ( ) . findElement ( webdriver . By . name ( key ) ) ;
561+ this . element = this . driver . findElement ( webdriver . By . name ( key ) ) ;
540562 else if ( criteria === 'tagName' )
541- this . element = this . driver ( ) . findElement ( webdriver . By . tagName ( key ) ) ;
563+ this . element = this . driver . findElement ( webdriver . By . tagName ( key ) ) ;
542564 else if ( criteria === 'xpath' )
543- this . element = this . driver ( ) . findElement ( webdriver . By . xpath ( key ) ) ;
565+ this . element = this . driver . findElement ( webdriver . By . xpath ( key ) ) ;
544566} ;
545567
546- WebDriverJsController . prototype . sendKeys = function ( key ) {
568+ WebDriverJsController . prototype . onSendKeys = function ( key ) {
547569 if ( this . element ) {
548570 this . element . sendKeys ( key ) ;
549571 } else {
550- this . driver ( ) . actions ( ) . sendKeys ( key ) . perform ( ) ;
572+ this . driver . actions ( ) . sendKeys ( key ) . perform ( ) ;
551573 }
552574} ;
553575
554- WebDriverJsController . prototype . click = function ( ) {
576+ WebDriverJsController . prototype . onClick = function ( ) {
555577 this . element . click ( ) ;
556578} ;
557579
558- WebDriverJsController . prototype . listWindowHandles = function ( ) {
580+ WebDriverJsController . prototype . onListWindowHandles = function ( ) {
559581 var select = document . getElementById ( 'windowList' ) ;
560- this . driver ( ) . getAllWindowHandles ( ) . then ( function ( handles ) {
582+ this . driver . getAllWindowHandles ( ) . then ( function ( handles ) {
561583 select . innerHTML = '' ;
562584 for ( var handle in handles ) {
563585 var item = document . createElement ( 'option' ) ;
@@ -569,24 +591,21 @@ WebDriverJsController.prototype.listWindowHandles = function() {
569591 } ) ;
570592} ;
571593
572- WebDriverJsController . prototype . chooseWindow = function ( ) {
594+ WebDriverJsController . prototype . onChooseWindow = function ( ) {
573595 var handle = document . getElementById ( 'windowList' ) . value ;
574- this . driver ( ) . switchTo ( ) . window ( handle ) ;
596+ this . driver . switchTo ( ) . window ( handle ) ;
575597} ;
576598
577- WebDriverJsController . prototype . setWindowSize = function ( ) {
599+ WebDriverJsController . prototype . onSetWindowSize = function ( ) {
578600 var width = document . getElementsByName ( 'windowSizeWidth' ) [ 0 ] . value ;
579601 var height = document . getElementsByName ( 'windowSizeHeight' ) [ 0 ] . value ;
580602 width = parseInt ( width ) ;
581603 height = parseInt ( height ) ;
582- this . driver ( ) . manage ( ) . window ( ) . setSize ( width , height ) ;
604+ this . driver . manage ( ) . window ( ) . setSize ( width , height ) ;
583605} ;
584606
585- WebDriverJsController . prototype . quit = function ( ) {
586- if ( ! this . _driver )
587- return ;
588-
589- this . _driver . quit ( ) ;
607+ WebDriverJsController . prototype . onQuit = function ( ) {
608+ this . driver . quit ( ) ;
590609 this . visualizer . quit ( ) ;
591610 this . webDriverUrlPort = null ;
592611 this . webPage = null ;
0 commit comments