Module: Taf::CMDLine

Defined in:
lib/taf/cmd_line.rb

Overview

cmd_line.rb - command line script Script

Class Method Summary collapse

Class Method Details

.browser(browser) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/taf/cmd_line.rb', line 23

def self.browser(browser)
  @browser_type = browser
  unless %w[chrome chrome-headless firefox firefox-headless]
         .include?(@browser_type)
    Taf::MyLog.log.warn 'A valid Browser has not been supplied as a' \
              ' command-line parameter as expected'
    Process.exit
  end
end

.browser_typeObject



51
52
53
# File 'lib/taf/cmd_line.rb', line 51

def self.browser_type
  @browser_type
end

.cmdline_inputObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/taf/cmd_line.rb', line 59

def self.cmdline_input
  # check if the test suite file name exists on the command line
  # allow a user to input 2 arguments in to CMD line the 2 values are:
  # Testcase Folder and Browser.
  options = {}
  ARGV.push('-h') if ARGV.empty?
  OptionParser.new do |opt|
    opt.banner = 'Usage: taf [options]'
    opt.on('-h', '--help') { help }
    opt.on('-v', '--version') { taf_version }
    opt.on('-b', '--browser b') { |b| options[:browser] = b, browser(b) }
    opt.on('-t', '--tests t') { |t| options[:testfolder] = t, tests(t) }
  end.parse!
end

.helpObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/taf/cmd_line.rb', line 12

def self.help
  puts '  Usage: taf [options]'
  puts '-h --help 2 arguments are required: -b {Browser}'\
          '-t {Testcase folder}'
  puts '-v --verision Shows current version'
  puts '-b --browser browser Supported Browsers: chrome, chrome-headless,'\
          ' firefox, firefox-headless'
  puts '-t --tests testfolder i.e. tests/*.json'
  Process.exit
end

.taf_versionObject



46
47
48
49
# File 'lib/taf/cmd_line.rb', line 46

def self.taf_version
  puts "TAF Version: #{Taf::VERSION}"
  Process.exit
end

.tests(testfolder) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/taf/cmd_line.rb', line 33

def self.tests(testfolder)
  @tests_folder = testfolder
  if Taf::Parser.test_files.size.positive?
    Taf::MyLog.log.info "There are: #{Taf::Parser.test_files.size}" \
      " test files to process: #{Taf::Parser.test_files}\n"
  else
    Taf::MyLog.log.warn \
      'A valid Test case location has not been supplied' \
      ' as a command-line parameter as expected, Files should be .JSON'
    Process.exit
  end
end

.tests_folderObject



55
56
57
# File 'lib/taf/cmd_line.rb', line 55

def self.tests_folder
  @tests_folder
end