lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-0.3.0 vs lib/capybara/poltergeist/client/compiled/browser.js in poltergeist-0.4.0
- old
+ new
@@ -1,26 +1,31 @@
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
Poltergeist.Browser = (function() {
function Browser(owner) {
this.owner = owner;
- this.awaiting_response = false;
+ this.state = 'default';
this.resetPage();
}
Browser.prototype.resetPage = function() {
if (this.page != null) {
this.page.release();
}
this.page = new Poltergeist.WebPage;
+ this.page.onLoadStarted = __bind(function() {
+ if (this.state === 'clicked') {
+ return this.state = 'loading';
+ }
+ }, this);
return this.page.onLoadFinished = __bind(function(status) {
- if (this.awaiting_response) {
+ if (this.state === 'loading') {
this.owner.sendResponse(status);
- return this.awaiting_response = false;
+ return this.state = 'default';
}
}, this);
};
Browser.prototype.visit = function(url) {
- this.awaiting_response = true;
+ this.state = 'loading';
return this.page.open(url);
};
Browser.prototype.current_url = function() {
return this.owner.sendResponse(this.page.currentUrl());
};
@@ -69,11 +74,11 @@
};
Browser.prototype.visible = function(id) {
return this.owner.sendResponse(this.page.get(id).isVisible());
};
Browser.prototype.evaluate = function(script) {
- return this.owner.sendResponse(this.page.evaluate("function() { return " + script + " }"));
+ return this.owner.sendResponse(JSON.parse(this.page.evaluate("function() { return JSON.stringify(" + script + ") }")));
};
Browser.prototype.execute = function(script) {
this.page.execute("function() { " + script + " }");
return this.owner.sendResponse(true);
};
@@ -84,19 +89,14 @@
Browser.prototype.pop_frame = function() {
this.page.popFrame();
return this.owner.sendResponse(true);
};
Browser.prototype.click = function(id) {
- var load_detected;
- load_detected = false;
- this.page.onLoadStarted = __bind(function() {
- this.awaiting_response = true;
- return load_detected = true;
- }, this);
+ this.state = 'clicked';
this.page.get(id).click();
return setTimeout(__bind(function() {
- this.page.onLoadStarted = null;
- if (!load_detected) {
+ if (this.state === 'clicked') {
+ this.state = 'default';
return this.owner.sendResponse(true);
}
}, this), 10);
};
Browser.prototype.drag = function(id, other_id) {
\ No newline at end of file