Skip to content

Commit 9f7d75b

Browse files
author
Vasyl Vavrychuk
committed
extracted webdriver building logic to builder
1 parent 2d1c133 commit 9f7d75b

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

web/webdriver-app.js

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,25 @@ function getXPath(node) {
8080
return '/' + path.join('/');
8181
}
8282

83+
webdriver.FirstSessionBuilder = function() {
84+
webdriver.AbstractBuilder.call(this);
85+
}
86+
87+
webdriver.FirstSessionBuilder.prototype = new webdriver.AbstractBuilder();
88+
89+
webdriver.FirstSessionBuilder.prototype.build = function() {
90+
var self = this;
91+
var client = new webdriver.http.CorsClient(this.getServerUrl());
92+
var executor = new webdriver.http.Executor(client);
93+
var session = webdriver.Session.getSessions(executor).then(function(sessions) {
94+
if (sessions[0])
95+
return sessions[0];
96+
else
97+
return webdriver.WebDriver.createSession(executor, self.getCapabilities()).getSession();
98+
});
99+
return new webdriver.WebDriver(session, executor);
100+
};
101+
83102
webdriver.WebDriver.prototype.visualizerGetSource = function() {
84103
webdriver.http.Executor.COMMAND_MAP_['visualizerGetSource'] = {
85104
method: 'GET', path: '/session/:sessionId/-cisco-visualizer-source'};
@@ -96,6 +115,11 @@ webdriver.WebDriver.prototype.visualizerShowPoint = function() {
96115
'WebDriver.visualizerShowPoint()');
97116
}
98117

118+
window.onerror = function(errorMsg, url, lineNumber, columnNumber, error) {
119+
console.log(error.stack);
120+
return false;
121+
}
122+
99123
var Util = function() {}
100124
Util.WebDriverKeyFromJs = function(keyCode) {
101125
switch (keyCode) {
@@ -443,18 +467,10 @@ WebDriverJsController.prototype._constructWebDriver = function() {
443467
return;
444468

445469
if (this.webDriverUrlPort != webDriverUrlPort) {
446-
var capabilities = {'browserName': 'qtwebkit'};
447-
448-
var client = new webdriver.http.CorsClient(webDriverUrlPort);
449-
var executor = new webdriver.http.Executor(client);
450-
var session = webdriver.Session.getSessions(executor).then(function(sessions) {
451-
if (sessions[0])
452-
return sessions[0];
453-
else
454-
return webdriver.WebDriver.createSession(executor, capabilities).getSession();
455-
});
456-
457-
this._driver = this.visualizer.driver = new webdriver.WebDriver(session, executor);
470+
this._driver = this.visualizer.driver = new webdriver.FirstSessionBuilder().
471+
usingServer(webDriverUrlPort).
472+
withCapabilities({'browserName': 'qtwebkit'}).
473+
build();
458474

459475
this.webDriverUrlPort = webDriverUrlPort;
460476
if (localStorage)

web/webdriver.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4872,6 +4872,7 @@ webdriver.http.XhrClient.prototype.send = function(a, b) {
48724872
}
48734873
};
48744874
exports.ActionSequence = webdriver.ActionSequence;
4875+
exports.AbstractBuilder = webdriver.AbstractBuilder;
48754876
exports.Builder = webdriver.Builder;
48764877
exports.Button = webdriver.Button;
48774878
exports.By = webdriver.Locator.Strategy;

0 commit comments

Comments
 (0)