为网站上的多个文件上传制作ruby脚本

时间:2013-06-19 11:24:19

标签: ruby

主要问题是如何管理从单击“添加文件”按钮后打开的上载窗口上传文件。 (查看img了解更多信息)

链接到窗口的img:http://failiem.lv/viewer.php?i=balfyns&n=UploadWindow.PNG

到目前为止,我有一个代码块可以设法打开这个窗口,我需要设法让它从数组中选择文件并上传它们。

kolekcija = {}
current_dir = "C:/Users/edgars.karkis/Desktop/TaaS/Automatization"
Dir.chdir("\\\\projekti\\testapps\\AUTOTESTS\\TaaS\\TaaS_testa_kopa")
#dirname = "C:/Users/edgars.karkis/Desktop/AUTOTESTI/letsmt_UserTest_automation" # <-- JĀMAINA UZ DIREKTORIJU, KUR ATRODAS SKRIPTS

Dir.glob( (current_dir + File.join("DOC","*.*")).force_encoding("UTF-8") ).each { |f| kolekcija.store(f, "doc|docx") }
Dir.glob( (current_dir + File.join("DOCX","*.*")).force_encoding("UTF-8") ).each { |f| kolekcija.store(f, "dox|docx") }
Dir.glob( (current_dir + File.join("HTM","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "htm") }
Dir.glob( (current_dir + File.join("HTML","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "html") }
Dir.glob( (current_dir + File.join("PDF","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "pdf") }
Dir.glob( (current_dir + File.join("PPT","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "ppt") }
Dir.glob( (current_dir + File.join("PPTX","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "pptx") }
Dir.glob( (current_dir + File.join("RTF","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "rtf") }
Dir.glob( (current_dir + File.join("SDLXLIFF","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "sdlxliff") }
Dir.glob( (current_dir + File.join("TXT","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "txt") }
Dir.glob( (current_dir + File.join("XLF","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "xlf") }
Dir.glob( (current_dir + File.join("XLIFF","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "xliff") }
Dir.glob( (current_dir + File.join("XLS","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "xls") }
Dir.glob( (current_dir + File.join("XLSX","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "xlsx") }
Dir.glob( (current_dir + File.join("XML","*.*")).force_encoding("UTF-8")).each { |f| kolekcija.store(f, "xml") }

puts ""
puts "Tiek veikta atlasīto failu ielāde..."
progress = ProgressBar.create(:title => "Failu ielāde:", :progress_mark => "|", :format => "%t [%B] %p%%", :total => kolekcija.length)

kolekcija.each do |file|
@file = files[0]
    @b.form(:id, "fileupload").span(:id, "add-files").when_present.click
    @b.form(:id, "fileupload").frame(:index, 0).file_field(:name, "files[]").set(@fails) # File absolute path
    @b.form(:id, "fileupload").frame(:index, 0).(:id, "").click
    @b.form(:id, "fileupload").table(:role, "presentation").wait_until_present
    @b.form(:class, "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix").span(:class => "ei-button-text", :text => "close", :index => 1).when_present.click
    sleep 5
    progress.increment
end

脚本在必须选择文件的位置停止。不知道如何让它发挥作用。

0 个答案:

没有答案