2017-02-23 52 views
0

在Jruby 9.1.7.0中運行黃瓜腳本。輸出轉到STDOUT。我怎樣才能將它保存到本地變量?如何從Cucumber :: CLI :: Main.execute獲取輸出(STDOUT)到變量

require 'cucumber' 
require 'stringio' 

@output = StringIO.new 
features = 'features/first.feature' 
args = features.split.concat %w(-f html) 

# Run cucumber 
begin 
# output goes to STDOUT 
    Cucumber::Cli::Main.new(args).execute! 
rescue SystemExit 
    puts "Cucumber calls @kernel.exit(), killing your script unless you rescue" 
end 

回答

0

如果你在cmd中「黃瓜--help」

-o, --out [FILE|DIR]    Write output to a file/directory instead of STDOUT. This option 
           applies to the previously specified --format, or the 
           default format if no format is specified. Check the specific 
           formatter's docs to see whether to pass a file or a dir. 

您可以

args = features.split.concat %w(-f html -o test.html) 
0

修改代碼鍵入你也可以把它寫在一個臨時文件和讀取來自文件的值。

require 'cucumber' 
require 'tempfile' 
require 'securerandom' 

filename = "#{SecureRandom.urlsafe_base64}" 
file = Tempfile.new(filename) 
filepath = "#{file.path}" 
features = "cucumber/ars/features/ars_additional.feature" 
args = features.split.concat %w(-f html -o) 
args << filepath 
Cucumber::Cli::Main.new(args).execute! 

@output = file.read 
file.close 
file.unlink 
相關問題