mirror of
https://github.com/teampoltergeist/poltergeist.git
synced 2022-11-09 12:05:00 -05:00
merged new version of code for identifying HTTP code of an loaded page
This commit is contained in:
parent
f04b9b538f
commit
72e5d2d276
7 changed files with 50 additions and 17 deletions
|
@ -212,6 +212,7 @@ makes debugging easier). Running `rake autocompile` will watch the
|
|||
(wynst) [Issue #97]
|
||||
* Scroll element into viewport if needed on click (Gabriel Sobrinho)
|
||||
[Issue #83]
|
||||
* Added status code support. (Dmitriy Nesteryuk and Jon Leighton) [Issue #37]
|
||||
|
||||
#### Bug fixes ###
|
||||
|
||||
|
|
|
@ -77,6 +77,10 @@ Poltergeist.WebPage = (function() {
|
|||
}
|
||||
};
|
||||
|
||||
WebPage.prototype.onLoadStartedNative = function() {
|
||||
return this.requestId = this.lastRequestId;
|
||||
};
|
||||
|
||||
WebPage.prototype.onLoadFinishedNative = function() {
|
||||
return this._source || (this._source = this["native"].content);
|
||||
};
|
||||
|
@ -101,12 +105,8 @@ Poltergeist.WebPage = (function() {
|
|||
});
|
||||
};
|
||||
|
||||
WebPage.prototype.onLoadStartedNative = function() {
|
||||
return this._url = this.lastUrl;
|
||||
};
|
||||
|
||||
WebPage.prototype.onResourceRequestedNative = function(request) {
|
||||
this.lastUrl = request.url;
|
||||
this.lastRequestId = request.id;
|
||||
return this._networkTraffic[request.id] = {
|
||||
request: request,
|
||||
responseParts: []
|
||||
|
@ -115,9 +115,9 @@ Poltergeist.WebPage = (function() {
|
|||
|
||||
WebPage.prototype.onResourceReceivedNative = function(response) {
|
||||
this._networkTraffic[response.id].responseParts.push(response);
|
||||
if (this._url === response.url) {
|
||||
if (this.requestId === response.id) {
|
||||
if (response.redirectURL) {
|
||||
return this._url = response.redirectURL;
|
||||
return this.requestId = response.id;
|
||||
} else {
|
||||
return this._statusCode = response.status;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,9 @@ class Poltergeist.WebPage
|
|||
@_source = @native.content
|
||||
false
|
||||
|
||||
onLoadStartedNative: ->
|
||||
@requestId = @lastRequestId
|
||||
|
||||
onLoadFinishedNative: ->
|
||||
@_source or= @native.content
|
||||
|
||||
|
@ -61,11 +64,8 @@ class Poltergeist.WebPage
|
|||
|
||||
@_errors.push(message: message, stack: stackString)
|
||||
|
||||
onLoadStartedNative: ->
|
||||
@_url = @lastUrl
|
||||
|
||||
onResourceRequestedNative: (request) ->
|
||||
@lastUrl = request.url
|
||||
@lastRequestId = request.id
|
||||
|
||||
@_networkTraffic[request.id] = {
|
||||
request: request,
|
||||
|
@ -75,9 +75,9 @@ class Poltergeist.WebPage
|
|||
onResourceReceivedNative: (response) ->
|
||||
@_networkTraffic[response.id].responseParts.push(response)
|
||||
|
||||
if @_url == response.url
|
||||
if @requestId == response.id
|
||||
if response.redirectURL
|
||||
@_url = response.redirectURL
|
||||
@requestId = response.id
|
||||
else
|
||||
@_statusCode = response.status
|
||||
|
||||
|
|
|
@ -254,9 +254,9 @@ module Capybara::Poltergeist
|
|||
end
|
||||
end
|
||||
|
||||
describe 'status code support' do
|
||||
context 'status code support' do
|
||||
it 'should determine status from the simple response' do
|
||||
@driver.visit('/poltergeist/500')
|
||||
@driver.visit('/poltergeist/status/500')
|
||||
@driver.status_code.should == 500
|
||||
end
|
||||
|
||||
|
|
|
@ -253,5 +253,25 @@ describe Capybara::Session do
|
|||
@session.evaluate_script("3;").should == 3
|
||||
end
|
||||
end
|
||||
|
||||
context 'status code support', :status_code_support => true do
|
||||
it 'should determine status code when an user goes to a page by using a link on it' do
|
||||
@session.visit '/poltergeist/with_different_resources'
|
||||
|
||||
@session.click_link 'Go to 500'
|
||||
|
||||
@session.status_code.should == 500
|
||||
end
|
||||
|
||||
it 'should determine properly status code when an user goes through a few pages' do
|
||||
@session.visit '/poltergeist/with_different_resources'
|
||||
|
||||
@session.click_link 'Go to 201'
|
||||
@session.click_link 'Do redirect'
|
||||
@session.click_link 'Go to 402'
|
||||
|
||||
@session.status_code.should == 402
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,8 +20,9 @@ class TestApp
|
|||
halt 404
|
||||
end
|
||||
|
||||
get '/poltergeist/500' do
|
||||
halt 500
|
||||
get '/poltergeist/status/:status' do
|
||||
status params['status']
|
||||
render_view 'with_different_resources'
|
||||
end
|
||||
|
||||
get '/poltergeist/redirect' do
|
||||
|
@ -29,6 +30,12 @@ class TestApp
|
|||
end
|
||||
|
||||
get '/poltergeist/:view' do |view|
|
||||
render_view view
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def render_view(view)
|
||||
erb File.read("#{POLTERGEIST_VIEWS}/#{view}.erb")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,5 +6,10 @@
|
|||
|
||||
<body>
|
||||
<img src="unexist.png">
|
||||
|
||||
<a href="/poltergeist/redirect">Do redirect</a>
|
||||
<a href="/poltergeist/status/201">Go to 201</a>
|
||||
<a href="/poltergeist/status/402">Go to 402</a>
|
||||
<a href="/poltergeist/status/500">Go to 500</a>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue