Skip to content

Commit

Permalink
Add Capybara::Apparition::NetworkTraffic::Request#finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
dkniffin committed Apr 16, 2020
1 parent f347909 commit c583c9d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/capybara/apparition/network_traffic/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def initialize(data, response_parts = [])
@response_parts = response_parts
@response = nil
@blocked_params = nil
@finished = false
end

def response=(response)
Expand Down Expand Up @@ -43,5 +44,13 @@ def blocked?
def error
response_parts.last&.error
end

def finished?
@finished
end

def finish!
@finished = true
end
end
end
5 changes: 5 additions & 0 deletions lib/capybara/apparition/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,11 @@ def register_event_handlers
end
end

@session.on 'Network.loadingFinished' do |request_id:, **|
req = @network_traffic.find { |request| request.request_id == request_id }
req&.finish!
end

@session.on 'Network.loadingFailed' do |type:, request_id:, blocked_reason: nil, error_text: nil, **params|
req = @network_traffic.find { |request| request.request_id == request_id }
req&.blocked_params = params if blocked_reason
Expand Down

0 comments on commit c583c9d

Please sign in to comment.