lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.0.3 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.1.0
- old
+ new
@@ -6,10 +6,12 @@
this.width = width || 1024;
this.height = height || 768;
this.state = 'default';
this.page_stack = [];
this.page_id = 0;
+ this.js_errors = true;
+ this._debug = false;
this.resetPage();
}
Browser.prototype.resetPage = function() {
var _this = this;
@@ -22,72 +24,88 @@
width: this.width,
height: this.height
});
this.page.onLoadStarted = function() {
if (_this.state === 'clicked') {
- return _this.state = 'loading';
+ return _this.setState('loading');
}
};
this.page.onNavigationRequested = function(url, navigation) {
if (_this.state === 'clicked' && navigation === 'FormSubmitted') {
- return _this.state = 'loading';
+ return _this.setState('loading');
}
};
this.page.onLoadFinished = function(status) {
if (_this.state === 'loading') {
_this.sendResponse({
status: status,
click: _this.last_click
});
- return _this.state = 'default';
+ return _this.setState('default');
} else if (_this.state === 'awaiting_frame_load') {
_this.sendResponse(true);
- return _this.state = 'default';
+ return _this.setState('default');
}
};
this.page.onInitialized = function() {
return _this.page_id += 1;
};
return this.page.onPageCreated = function(sub_page) {
var name;
if (_this.state === 'awaiting_sub_page') {
name = _this.page_name;
- _this.state = 'default';
_this.page_name = null;
+ _this.setState('default');
return setTimeout((function() {
return _this.push_window(name);
}), 0);
}
};
};
+ Browser.prototype.debug = function(message) {
+ if (this._debug) {
+ return console.log("poltergeist [" + (new Date().getTime()) + "] " + message);
+ }
+ };
+
+ Browser.prototype.setState = function(state) {
+ this.debug("state " + this.state + " -> " + state);
+ return this.state = state;
+ };
+
Browser.prototype.sendResponse = function(response) {
var errors;
errors = this.page.errors();
- if (errors.length > 0) {
- this.page.clearErrors();
+ this.page.clearErrors();
+ if (errors.length > 0 && this.js_errors) {
return this.owner.sendError(new Poltergeist.JavascriptError(errors));
} else {
return this.owner.sendResponse(response);
}
};
+ Browser.prototype.add_extension = function(extension) {
+ this.page.injectExtension(extension);
+ return this.sendResponse('success');
+ };
+
Browser.prototype.node = function(page_id, id) {
if (page_id === this.page_id) {
return this.page.get(id);
} else {
throw new Poltergeist.ObsoleteNode;
}
};
Browser.prototype.visit = function(url) {
var prev_url;
- this.state = 'loading';
+ this.setState('loading');
prev_url = this.page.currentUrl();
this.page.open(url);
if (/#/.test(url) && prev_url.split('#')[0] === url.split('#')[0]) {
- this.state = 'default';
+ this.setState('default');
return this.sendResponse('success');
}
};
Browser.prototype.current_url = function() {
@@ -135,13 +153,13 @@
};
Browser.prototype.select_file = function(page_id, id, value) {
var node;
node = this.node(page_id, id);
- node.setAttribute('_poltergeist_selected', '');
+ this.page.beforeUpload(node.id);
this.page.uploadFile('[_poltergeist_selected]', value);
- node.removeAttribute('_poltergeist_selected');
+ this.page.afterUpload(node.id);
return this.sendResponse(true);
};
Browser.prototype.select = function(page_id, id, value) {
return this.sendResponse(this.node(page_id, id).select(value));
@@ -166,11 +184,11 @@
Browser.prototype.push_frame = function(name) {
var _this = this;
if (this.page.pushFrame(name)) {
if (this.page.currentUrl() === 'about:blank') {
- return this.state = 'awaiting_frame_load';
+ return this.setState('awaiting_frame_load');
} else {
return this.sendResponse(true);
}
} else {
return setTimeout((function() {
@@ -199,11 +217,11 @@
this.page_id += 1;
return this.sendResponse(true);
}
} else {
this.page_name = name;
- return this.state = 'awaiting_sub_page';
+ return this.setState('awaiting_sub_page');
}
};
Browser.prototype.pop_window = function() {
var prev_page;
@@ -212,24 +230,41 @@
this.page = prev_page;
}
return this.sendResponse(true);
};
- Browser.prototype.click = function(page_id, id) {
+ Browser.prototype.click = function(page_id, id, event) {
var node,
_this = this;
+ if (event == null) {
+ event = 'click';
+ }
node = this.node(page_id, id);
- this.state = 'clicked';
- this.last_click = node.click();
+ this.setState('clicked');
+ this.last_click = node.click(event);
return setTimeout(function() {
if (_this.state !== 'loading') {
- _this.state = 'default';
+ _this.setState('default');
return _this.sendResponse(_this.last_click);
}
}, 5);
};
+ Browser.prototype.double_click = function(page_id, id) {
+ return this.click(page_id, id, 'doubleclick');
+ };
+
+ Browser.prototype.click_coordinates = function(x, y) {
+ this.page.sendEvent('click', x, y);
+ return this.sendResponse({
+ click: {
+ x: x,
+ y: y
+ }
+ });
+ };
+
Browser.prototype.drag = function(page_id, id, other_id) {
this.node(page_id, id).dragTo(this.node(page_id, other_id));
return this.sendResponse(true);
};
@@ -313,9 +348,19 @@
return this.sendResponse(true);
};
Browser.prototype.remove_cookie = function(name) {
this.page.deleteCookie(name);
+ return this.sendResponse(true);
+ };
+
+ Browser.prototype.set_js_errors = function(value) {
+ this.js_errors = value;
+ return this.sendResponse(true);
+ };
+
+ Browser.prototype.set_debug = function(value) {
+ this._debug = value;
return this.sendResponse(true);
};
Browser.prototype.exit = function() {
return phantom.exit();