lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.6.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-1.7.0
- old
+ new
@@ -7,10 +7,13 @@
this.height = height || 768;
this.pages = [];
this.js_errors = true;
this._debug = false;
this._counter = 0;
+ this.processed_modal_messages = [];
+ this.confirm_processes = [];
+ this.prompt_responses = [];
this.resetPage();
}
Browser.prototype.resetPage = function() {
var _ref,
@@ -30,10 +33,34 @@
width: this.width,
height: this.height
});
this.page.handle = "" + (this._counter++);
this.pages.push(this.page);
+ this.processed_modal_messages = [];
+ this.confirm_processes = [];
+ this.prompt_responses = [];
+ this.page["native"]().onAlert = function(msg) {
+ _this.setModalMessage(msg);
+ };
+ this.page["native"]().onConfirm = function(msg) {
+ var process;
+ process = _this.confirm_processes.pop();
+ if (process === void 0) {
+ process = true;
+ }
+ _this.setModalMessage(msg);
+ return process;
+ };
+ this.page["native"]().onPrompt = function(msg, defaultVal) {
+ var response;
+ response = _this.prompt_responses.pop();
+ if (response === void 0 || response === false) {
+ response = defaultVal;
+ }
+ _this.setModalMessage(msg);
+ return response;
+ };
return this.page.onPageCreated = function(newPage) {
var page;
page = new Poltergeist.WebPage(newPage);
page.handle = "" + (_this._counter++);
return _this.pages.push(page);
@@ -55,10 +82,14 @@
if (this._debug) {
return console.log("poltergeist [" + (new Date().getTime()) + "] " + message);
}
};
+ Browser.prototype.setModalMessage = function(msg) {
+ return this.processed_modal_messages.push(msg);
+ };
+
Browser.prototype.sendResponse = function(response) {
var errors;
errors = this.currentPage.errors;
this.currentPage.clearErrors();
if (errors.length > 0 && this.js_errors) {
@@ -83,10 +114,13 @@
Browser.prototype.visit = function(url) {
var prevUrl,
_this = this;
this.currentPage.state = 'loading';
+ this.processed_modal_messages = [];
+ this.confirm_processes = [];
+ this.prompt_responses = [];
prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
this.currentPage.open(url);
if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
this.currentPage.state = 'default';
return this.sendResponse({
@@ -192,10 +226,14 @@
Browser.prototype.disabled = function(page_id, id) {
return this.sendResponse(this.node(page_id, id).isDisabled());
};
+ Browser.prototype.path = function(page_id, id) {
+ return this.sendResponse(this.node(page_id, id).path());
+ };
+
Browser.prototype.evaluate = function(script) {
return this.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
};
Browser.prototype.execute = function(script) {
@@ -345,10 +383,15 @@
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);
};
+ Browser.prototype.drag_by = function(page_id, id, x, y) {
+ this.node(page_id, id).dragBy(x, y);
+ return this.sendResponse(true);
+ };
+
Browser.prototype.trigger = function(page_id, id, event) {
this.node(page_id, id).trigger(event);
return this.sendResponse(event);
};
@@ -368,19 +411,33 @@
});
return this.sendResponse(true);
};
Browser.prototype.send_keys = function(page_id, id, keys) {
- var key, sequence, target, _i, _len;
+ var key, modifier_code, modifier_key, modifier_keys, sequence, target, _i, _j, _k, _len, _len1, _len2;
target = this.node(page_id, id);
if (!target.containsSelection()) {
target.mouseEvent('click');
}
for (_i = 0, _len = keys.length; _i < _len; _i++) {
sequence = keys[_i];
key = sequence.key != null ? this.currentPage.keyCode(sequence.key) : sequence;
- this.currentPage.sendEvent('keypress', key);
+ if (sequence.modifier != null) {
+ modifier_keys = this.currentPage.keyModifierKeys(sequence.modifier);
+ modifier_code = this.currentPage.keyModifierCode(sequence.modifier);
+ for (_j = 0, _len1 = modifier_keys.length; _j < _len1; _j++) {
+ modifier_key = modifier_keys[_j];
+ this.currentPage.sendEvent('keydown', modifier_key);
+ }
+ this.currentPage.sendEvent('keypress', key, null, null, modifier_code);
+ for (_k = 0, _len2 = modifier_keys.length; _k < _len2; _k++) {
+ modifier_key = modifier_keys[_k];
+ this.currentPage.sendEvent('keyup', modifier_key);
+ }
+ } else {
+ this.currentPage.sendEvent('keypress', key);
+ }
}
return this.sendResponse(true);
};
Browser.prototype.render_base64 = function(format, full, selector) {
@@ -566,9 +623,23 @@
};
Browser.prototype.set_url_blacklist = function() {
this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
return this.sendResponse(true);
+ };
+
+ Browser.prototype.set_confirm_process = function(process) {
+ this.confirm_processes.push(process);
+ return this.sendResponse(true);
+ };
+
+ Browser.prototype.set_prompt_response = function(response) {
+ this.prompt_responses.push(response);
+ return this.sendResponse(true);
+ };
+
+ Browser.prototype.modal_message = function() {
+ return this.sendResponse(this.processed_modal_messages.shift());
};
return Browser;
})();