Class: SeleniumShots::Command::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium_shots/cli/commands/base.rb

Direct Known Subclasses

App, Auth, Help

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Returns a new instance of Base.



6
7
8
# File 'lib/selenium_shots/cli/commands/base.rb', line 6

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



5
6
7
# File 'lib/selenium_shots/cli/commands/base.rb', line 5

def args
  @args
end

Instance Method Details

#askObject



22
23
24
# File 'lib/selenium_shots/cli/commands/base.rb', line 22

def ask
  gets.strip
end

#ask_for_config_fileObject



43
44
45
46
47
48
49
50
# File 'lib/selenium_shots/cli/commands/base.rb', line 43

def ask_for_config_file
  if File.exists?(config_file)
    print "The file config/selenium_shots.yml exists, do you want overwrite this? (y/n): "
    ask
  else
    "y"
  end
end

#config_fileObject



38
39
40
# File 'lib/selenium_shots/cli/commands/base.rb', line 38

def config_file
  'config/selenium_shots.yml'
end

#display(msg, newline = true) ⇒ Object



18
19
20
# File 'lib/selenium_shots/cli/commands/base.rb', line 18

def display(msg, newline=true)
  newline ? puts(msg) : print(msg)
end

#home_directoryObject



30
31
32
# File 'lib/selenium_shots/cli/commands/base.rb', line 30

def home_directory
  running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
end

#make_config_file(name, api_key) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/selenium_shots/cli/commands/base.rb', line 52

def make_config_file(name, api_key)
    overwrite_or_create_file = ask_for_config_file
    if overwrite_or_create_file == "y"
      config_file_hash = "api_key: \"\#{api_key}\"\nmode: \"remote\" # \"local\" for run test locally\ndefault_browser_url: \"http://www.myapp.com\"\napplication_name: \"\#{name}\"\nlocal_browser: \"firefox\"\nbrowsers:\n  - IE8 on XP\n  - Firefox3.6 on XP\n"
    File.open(config_file, 'w') do |f|
      f.puts config_file_hash
    end
  end
  overwrite_or_create_file
end

#running_on_windows?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/selenium_shots/cli/commands/base.rb', line 34

def running_on_windows?
  RUBY_PLATFORM =~ /mswin32/
end

#selenium_shotsObject



10
11
12
# File 'lib/selenium_shots/cli/commands/base.rb', line 10

def selenium_shots
  @selenium_shots ||= SeleniumShots::Command.run_internal('auth:client', args)
end

#selenium_shots_api_keyObject



14
15
16
# File 'lib/selenium_shots/cli/commands/base.rb', line 14

def selenium_shots_api_key
  @api_key ||= SeleniumShots::Command.run_internal('auth:api_key', args)
end

#shell(cmd) ⇒ Object



26
27
28
# File 'lib/selenium_shots/cli/commands/base.rb', line 26

def shell(cmd)
  `#{cmd}`
end