Class: CloudTest::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/cloud_test/cli.rb

Instance Method Summary collapse

Instance Method Details

#each(*commands) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/cloud_test/cli.rb', line 72

def each(*commands)
  require 'open3'
  config = Core.load_config
  config['browsers'].keys.each { |browser_config_name|
    Open3.popen2e({'CLOUD_TEST' =>browser_config_name.to_s}, commands.join(" ")) do |stdin, stdout_err, wait_thr|
      unless options[:q]
        while line = stdout_err.gets
          puts line
        end
      end
      exit_status = wait_thr.value
      if exit_status == 0
        puts "Test on browser: #{browser_config_name} was successful!"
      else
        puts "Error on browser: #{browser_config_name}!"
        puts stdout_err.read
        puts "Error on browser: #{browser_config_name}!"
      end
    end
  }
end

#generateObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cloud_test/cli.rb', line 31

def generate()
  case options[:provider].to_s.downcase
  when 'lambdatest', 'lt', 'l'
    provider = 'lambdatest'
  when 'crossbrowsertesting', 'cbs', 'ct', 'cbt', 'c'
    provider = 'crossbrowsertesting'
  when 'saucelabs', 'sauce', 'sc', 'sl', 's'
    provider = 'saucelabs'
  else
    provider = 'browserstack'
  end
  CloudTest::Generators::Config.start([provider])
  CloudTest::Generators::Support.start()
end

#generate_config(config) ⇒ Object



25
26
27
# File 'lib/cloud_test/cli.rb', line 25

def generate_config(config)
  CloudTest::Generators::Config.start([config])
end

#list_caps(provider) ⇒ Object



13
14
15
16
# File 'lib/cloud_test/cli.rb', line 13

def list_caps(provider)
  hash = {"provider" => provider}
  Core.get_provider_class(hash).get_all_caps
end

#list_default_caps(provider) ⇒ Object



19
20
21
22
# File 'lib/cloud_test/cli.rb', line 19

def list_default_caps(provider)
  hash = {"provider" => provider}
  Core.get_provider_class(hash).list_caps
end

#startObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cloud_test/cli.rb', line 48

def start()
  require 'open3'
  config = Core.load_config
  config['browsers'].keys.each { |browser_config_name|
    Open3.popen2e({'CLOUD_TEST' =>browser_config_name.to_s}, "bundle" ,"exec", "cucumber", "-t","#{config['cucumber_tag'].to_s}") do |stdin, stdout_err, wait_thr|
      unless options[:q]
        while line = stdout_err.gets
          puts line
        end
      end
      exit_status = wait_thr.value
      if exit_status == 0
        puts "Test on browser: #{browser_config_name} was successful!"
      else
        puts "Test on browser: #{browser_config_name} was not successful!"
        puts stdout_err
        raise "did not work"
      end
    end
  }
end

#test_connectionObject



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/cloud_test/cli.rb', line 95

def test_connection()
  require 'net/http'
  require 'uri'
  config = CloudTest::Core.load_config
  request, uri, request, server = Hash.new
  if config.has_key?('provider') && config.has_key?('user') && config.has_key?('key')
    case config.delete 'provider'.to_s.downcase
      when 'browserstack', 'bs', 'b'
        server = "https://www.browserstack.com/local/v1/list?auth_token=#{config['key']}&last=1"
      when 'lambdatest', 'lt', 'l'
        server = "https://api.lambdatest.com/automation/api/v1/tunnels"
        uri = URI.parse(server)
        request = Net::HTTP::Get.new(uri)
        request.basic_auth(config['user'], config['key'])
      when 'crossbrowsertesting', 'cbs', 'ct', 'cbt', 'c'
        server = "https://crossbrowsertesting.com/api/v3/tunnels"
        uri = URI.parse(server)
        request = Net::HTTP::Get.new(uri)
        request.basic_auth(config['user'].sub("@", "%40"), config['key'])
      when 'saucelabs', 'sauce', 'sc', 'sl', 's'
        server = "https://saucelabs.com/rest/v1/#{config['user']}/tunnels"
        uri = URI.parse(server)
        request = Net::HTTP::Get.new(uri)
        request.basic_auth(config['user'], config['key'])
    else
      puts "Unknown provider!"
      return
    end
    uri ||= URI.parse(server)
    request ||= Net::HTTP::Get.new(uri)
    request["Accept"] = "application/json"
    req_options = {
        use_ssl: uri.scheme == "https",
    }
    response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
      http.request(request)
    end
    if response.code == '200'
      puts "Connection successful!"
    else
      puts "Connection was not successful! :("
      puts response.code
    end
  else
    puts "You have not all necessary keys in your config file. `provider`, `user`, `key` are necessary"
  end
end

#versionObject



145
146
147
# File 'lib/cloud_test/cli.rb', line 145

def version
  say "cloud_test version: #{CloudTest::VERSION}"
end