class Grell::RawPage
This class depends heavily on Capybara but contains no logic.
Public Instance Methods
all_anchors()
click to toggle source
# File lib/grell/rawpage.rb, line 23 def all_anchors # Some elements may not be "a" elements but still provide a link. This usually is done for Javascript # to convert other elements which are not links to be able to be clicked naturally. # Only return links which are visible. all('[href]', visible: true).to_a + all('[data-href]', visible: true).to_a end
body()
click to toggle source
# File lib/grell/rawpage.rb, line 19 def body page.body end
has_selector?(selector)
click to toggle source
# File lib/grell/rawpage.rb, line 34 def has_selector?(selector) page.has_selector?(selector) end
headers()
click to toggle source
# File lib/grell/rawpage.rb, line 11 def headers page.response_headers end
host()
click to toggle source
# File lib/grell/rawpage.rb, line 30 def host page.current_host end
status()
click to toggle source
# File lib/grell/rawpage.rb, line 15 def status page.status_code end
wait_for_all_ajax_requests(timeout, interval)
click to toggle source
# File lib/grell/rawpage.rb, line 38 def wait_for_all_ajax_requests(timeout, interval) Timeout::timeout(timeout) do (timeout / interval).ceil.times do jquery_active = page.evaluate_script("typeof jQuery !== 'undefined' && jQuery.active;") break if (!jquery_active || jquery_active.zero?) sleep(interval) end end true end
Private Instance Methods
follow_redirects!()
click to toggle source
# File lib/grell/rawpage.rb, line 51 def follow_redirects! # Phantom is very weird, it will follow a redirect to provide the correct body but will not fill the # status and the headers, if we are in that situation, revisit the page with the correct url this time. # Note that we will still fail if we have more than 5 redirects on a row redirects = 0 while(page.status_code == nil && redirects < 5) visit( CGI.unescape(page.current_url)) redirects = redirects + 1 end end