오이 테스트를 위해 셀레늄을 사용하여 스크린 샷을 찍고 있습니다. 내 단계 중 하나가 단계 + 타임 스탬프의 입력을 사용하여 생성 된 폴더 이름이있는 폴더에 스크린 샷 파일을 저장하려고합니다. 여기디렉토리 만들기 및 파일 이동
는 지금까지 성취 한 것입니다 : 디렉토리가 존재하지 않습니다
Then /^screen shots are placed in the folder "(.*)"$/ do |folder_name|
time = Time.now.strftime("%Y%m%d%H%M%S")
source ="screen_shots"
destination = "screen_shots\_#{folder_name}_#{time}"
if !Dir.exists? destination
Dir.new destination
end
Dir.glob(File.join(source, '*')).each do |file|
if File.exists? (file)
File.move file, File.join(destination, File.basename(file))
end
end
end
경우, 나는 그것을 만들려고합니다. 그런 다음 모든 스크린 샷을 새 디렉토리에 저장하려고합니다.
폴더는 스크린 샷과 동일한 디렉토리에 만들어지고 모든 스크린 샷 파일은 폴더로 이동됩니다. 난 아직 루비를 배우고, 함께이를 넣어 내 시도는 전혀 운동을하지 않는 : 한마디로
Desktop > cucumber_project_folder > screenshots_folder > shot1.png, shot2.png
, 나는 screenshots
에 새 디렉토리를 만들고 그것으로 shot1.png
및 shot2.png
을 이동하려는. 그렇게하려면 어떻게해야합니까?
이 주어진 답변에 따라 소스 경로가 너무 다른 사용자가 정의를 수정할 필요가 없습니다 단계에 표시됩니다 (오이에 대한) 솔루션
Then /^screen shots are placed in the folder "(.*)" contained in "(.*)"$/ do |folder_name, source_path|
date_time = Time.now.strftime('%m-%d-%Y %H:%M:%S')
source = Pathname.new(source_path)
destination = source + "#{folder_name}_#{date_time}"
destination.mkdir unless destination.exist?
files = source.children.find_all { |f| f.file? and f.fnmatch?('*.png') }
FileUtils.move(files, destination)
end
입니다.
당신이 보일 것입니다 [** Fileutils의 **] (http://www.ruby-doc.org/stdlib-2.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-mkdir_p) 및 혼자서 시도해보십시오. 매우 쉽습니다 ..이 stdlib를 사용하여 모두 수행 할 수 있습니다. :)) –
StackOverflow는 질문을하기에 좋은 장소이지만, 우리가 당신을 위해 일하기를 기대해서는 안됩니다. 우리가 가지고있는 것과 작동하지 않는 것을 보여주고 우리가 여러분을 도우 려 노력할 것입니다. 그러나 @Priti가 말했듯이, 이것은 Ruby 표준 라이브러리를 사용하여 작성하는 것이 매우 간단합니다. –
감사! 나는 명심 할 것이다 :) – meggex