Class: Watir::Browser
- Inherits:
-
Object
- Object
- Watir::Browser
- Defined in:
- lib/tagen/watir.rb
Instance Method Summary collapse
-
#dump_cookies(file) ⇒ Object
Write cookies to Mozilla cookies.txt-style IO stream.
-
#keep_cookies! ⇒ Object
TODO: support windows.
-
#load_cookies(file) ⇒ Object
Read cookies from Mozilla cookies.txt-style IO stream.
Instance Method Details
#dump_cookies(file) ⇒ Object
Write cookies to Mozilla cookies.txt-style IO stream
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tagen/watir.rb', line 55 def (file) io = case file when String open(file, "w") else file end .to_a.each do || io.puts([ [:domain], "FALSE", # for_domain [:path], [:secure] ? "TRUE" : "FALSE", [:expires].to_i.to_s, [:name], [:value] ].join("\t")) end io.close if String === file self end |
#keep_cookies! ⇒ Object
TODO: support windows.
firefox only.
9 10 11 12 13 14 |
# File 'lib/tagen/watir.rb', line 9 def require "tagen/selenium-webdriver/webdriver/firefox" launcher = driver.instance_variable_get("@bridge").instance_variable_get("@launcher") launcher. end |
#load_cookies(file) ⇒ Object
Read cookies from Mozilla cookies.txt-style IO stream
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tagen/watir.rb', line 20 def (file) now = ::Time.now io = case file when String open(file) else file end io.each_line do |line| line.chomp! line.gsub!(/#.+/, '') fields = line.split("\t") next if fields.length != 7 name, value, domain, for_domain, path, secure, version = fields[5], fields[6], fields[0], (fields[1] == "TRUE"), fields[2], (fields[3] == "TRUE"), 0 expires_seconds = fields[4].to_i expires = (expires_seconds == 0) ? nil : ::Time.at(expires_seconds) next if expires and (expires < now) .add(name, value, domain: domain, path: path, expires: expires, secure: secure) end io.close if String === file self end |