让Ruby提取特定文件类型的上次下载文件

问题描述 投票:0回答:1

我正在尝试进行自动化测试,最后下载文档,并将文档文件名放入控制台。我在帮助它查找最新文档时遇到了麻烦。我在用红宝石和黄瓜。目前正在Firefox上运行。下面是我特定的步进定义语言,可用于提取文件,但不完全是最新文件:

When(/^I can see the file name of download pdf from the (.+) directory displayed on the console 
screen$/) { |path| 
 Dir.foreach(path) do |fname|
if fname.include?(".pdf")
  @file_name = fname
  break
end

end puts @file_name }

ruby testing selenium-webdriver automation cucumber
1个回答
0
投票
Dir.glob("*.pdf").max_by { |f| File.mtime(f) }

信用证转到:Ruby: Finding most recently modified file

© www.soinside.com 2019 - 2024. All rights reserved.