Class: Capybara::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/monkey-patches/capybara-patches.rb

Constant Summary collapse

DTD_REFS =
{
"-//W3C//DTD XHTML 1.0 Strict//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml1-strict.dtd", :type => :strict},
"-//W3C//DTD XHTML 1.0 Transitional//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml1-transitional.dtd", :type => :transitional}, 
"-//W3C//DTD XHTML+RDFa 1.0//EN" => {:dtd => "#{File.dirname( __FILE__)}/../../schemas/xhtml-rdfa-1.dtd", :type => :rdfa}}

Instance Method Summary collapse

Instance Method Details



76
77
78
# File 'lib/monkey-patches/capybara-patches.rb', line 76

def add_cookie(attribs)
  driver.add_cookie(attribs)
end

Get the cookie with the given name

Parameters:

  • name (String)

    the name of the cookie

Returns:

  • (Hash, nil)

    the cookie, or nil if it wasn’t found.



64
65
66
# File 'lib/monkey-patches/capybara-patches.rb', line 64

def cookie_named(name)    
  driver.cookie_named(name)
end

#cookiesArray<Hash>

Get all cookies

Returns:

  • (Array<Hash>)

    list of cookies



54
55
56
# File 'lib/monkey-patches/capybara-patches.rb', line 54

def cookies    
  driver.cookies
end

#delete_all_cookiesObject



72
73
74
# File 'lib/monkey-patches/capybara-patches.rb', line 72

def delete_all_cookies
  driver.delete_all_cookies
end


68
69
70
# File 'lib/monkey-patches/capybara-patches.rb', line 68

def delete_cookie(cookie)
  driver.delete_cookie(cookie)
end

#validate(source) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/monkey-patches/capybara-patches.rb', line 85

def validate(source)
  doctype = source.scan(/\"(.*?)\"/)[0].to_s 

  if(DTD_REFS[doctype])
    dtd = DTD_REFS[doctype][:dtd]
    type = DTD_REFS[doctype][:type]
  end

  raise "RDFA Validation not currently supported due to issues in Nokogiri" if type == :rdfa

  source = source.gsub(/PUBLIC \"-\/\/W3C\/\/DTD XHTML.*?\/\/EN\" \"http:\/\/www.w3.org.*?\"/, "SYSTEM \"#{dtd}\"")
  doc = Nokogiri::XML(source) { |cfg|
    cfg.noent.dtdload.dtdvalid
  }
  errors = doc.validate
  raise "Page (#{current_url}) failed XHTML vaidation (or Nokogiri Freaked out...please manually check against W3C), errors:#{errors.to_s}" unless errors == []
end