1
0
Fork 0
mirror of https://github.com/teampoltergeist/poltergeist.git synced 2022-11-09 12:05:00 -05:00

Raise an error if a URL fails to load in response to or .

This commit is contained in:
Jon Leighton 2012-02-16 23:58:37 +00:00
parent a6e4a012ff
commit d902565d8b
6 changed files with 27 additions and 6 deletions

View file

@ -170,6 +170,9 @@ makes debugging easier). Running `rake autocompile` will watch the
* Fix bug with page Javascript page loading causing problems. [Issue
#19]
* Raise an error if a URL fails to load in response to `#visit` or
`#click`.
### 0.3.0 ###
* There was a bad bug to do with clicking elements in a page where the

View file

@ -13,7 +13,11 @@ class Poltergeist.Browser
@page.onLoadFinished = (status) =>
if @state == 'loading'
@owner.sendResponse(status)
if status == 'success'
@owner.sendResponse(true)
else
@owner.sendError('URL failed to load')
@state = 'default'
visit: (url) ->

View file

@ -17,7 +17,11 @@ Poltergeist.Browser = (function() {
}, this);
return this.page.onLoadFinished = __bind(function(status) {
if (this.state === 'loading') {
this.owner.sendResponse(status);
if (status === 'success') {
this.owner.sendResponse(true);
} else {
this.owner.sendError('URL failed to load');
}
return this.state = 'default';
}
}, this);

View file

@ -8,9 +8,7 @@ Poltergeist = (function() {
try {
return this.browser[command.name].apply(this.browser, command.args);
} catch (error) {
return this.connection.send({
error: error.toString()
});
return this.sendError(error.toString());
}
};
Poltergeist.prototype.sendResponse = function(response) {
@ -18,6 +16,11 @@ Poltergeist = (function() {
response: response
});
};
Poltergeist.prototype.sendError = function(message) {
return this.connection.send({
error: message
});
};
return Poltergeist;
})();
Poltergeist.ObsoleteNode = (function() {

View file

@ -7,11 +7,14 @@ class Poltergeist
try
@browser[command.name].apply(@browser, command.args)
catch error
@connection.send({ error: error.toString() })
this.sendError(error.toString())
sendResponse: (response) ->
@connection.send({ response: response })
sendError: (message) ->
@connection.send({ error: message })
class Poltergeist.ObsoleteNode
toString: -> "Poltergeist.ObsoleteNode"

View file

@ -99,5 +99,9 @@ describe Capybara::Session do
sleep 0.1
@session.body.should include("Hello world")
end
it "raises an error if a load fails" do
expect { @session.visit 'omgwtfbbq12345632' }.to raise_error(Capybara::Poltergeist::BrowserError)
end
end
end