Class: Watir::Container::DownloadLink

Inherits:
Anchor
  • Object
show all
Defined in:
lib/watirmark/extensions/webdriver_extensions.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ DownloadLink

Returns a new instance of DownloadLink.



10
11
12
13
# File 'lib/watirmark/extensions/webdriver_extensions.rb', line 10

def initialize(*args)
  @dir = File.join(Watirmark::Configuration.instance.projectpath, "reports", "downloads")
  super
end

Instance Method Details

#download(file = nil) ⇒ Object



15
16
17
18
# File 'lib/watirmark/extensions/webdriver_extensions.rb', line 15

def download(file = nil)
  click
  locate_file(file)
end

#last_modified_fileObject



31
32
33
# File 'lib/watirmark/extensions/webdriver_extensions.rb', line 31

def last_modified_file
  Dir.new(@dir).select { |f| f!= '.' && f!='..' }.collect { |f| "#{@dir}/#{f}" }.sort { |a, b| File.mtime(b)<=>File.mtime(a) }.first
end

#locate_file(file = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/watirmark/extensions/webdriver_extensions.rb', line 20

def locate_file(file = nil)
  if file
    new_file = "#{@dir}/#{file}"
    File.delete(new_file) if File.file?(new_file)
    File.rename(last_modified_file, new_file)
    new_file
  else
    last_modified_file
  end
end