Sha256: 2cd93789614fbb9555357a77acdb283035357ab132e3db570eb144950ecde899

Contents?: true

Size: 866 Bytes

Versions: 4

Compression:

Stored size: 866 Bytes

Contents

module Watir
  class Cookies
    def initialize(control)
      @control = control
    end

    def to_a
      @control.all_cookies.each do |e|
        e[:expires] = to_time(e[:expires]) if e[:expires]
      end
    end

    def add(name, value, opts = {})
      cookie = {
        :name    => name,
        :value   => value,
        :secure  => opts[:secure],
        :path    => opts[:path],
        :expires => opts[:expires],
      }

      if opts[:domain]
        cookie[:domain] = opts[:domain]
      end

      @control.add_cookie cookie
    end

    def delete(name)
      @control.delete_cookie(name)
    end

    def clear
      @control.delete_all_cookies
    end

    private

    def to_time(t)
      if t.respond_to?(:to_time)
        t.to_time
      else
        ::Time.local t.year, t.month, t.day, t.hour, t.min, t.sec
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
watir-webdriver-0.6.1 lib/watir-webdriver/cookies.rb
watir-webdriver-0.6.0 lib/watir-webdriver/cookies.rb
watir-webdriver-0.5.8 lib/watir-webdriver/cookies.rb
watir-webdriver-0.5.7 lib/watir-webdriver/cookies.rb