superbot 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61e129678c2b0dbe5b2b3917213fa1b9a757ac58d8e663029df774ea41eead31
4
- data.tar.gz: 8fb4aa0d11093ad5f733dd2acc96cb2684fb5154aaf1ba03ab56232d42437432
3
+ metadata.gz: 42bb47f3be6a83eeff358b7f7885c5339322d880080846f44b6a98e3c8db261d
4
+ data.tar.gz: d278fabe3dc9bdb05ce7178957d194610f5649211a0bdcb38b4a2fd92a91505c
5
5
  SHA512:
6
- metadata.gz: e7591a876f26d01108159691d377c984a28a2083bcaedeae09929e3628969d2751e423a06474bbea8befabd220dbc4b22c36705bd1a83ad38c34dc19b0f0b7aa
7
- data.tar.gz: 52f817ce561627e0d7f4c2d164267040416ed72034df3c836f4d858d217cc379e4ec0f8d111a54aa65f0612b33b5bb1b8dbc880fced488aad7cf30f599c0423f
6
+ metadata.gz: 4b0a458a747545924dec284a92371f45cb9a01dc8074a79817aa32430523902864e713582350225f4a52bd3e19b8625546bfb1b5e2436494f4b8d72506fa68c0
7
+ data.tar.gz: '074199a1217ab401674a6d3ec4d61760fe3f5adf28971061858e46b904612286c2ff22ccc5f0417a40f8e5edc8409827d22908eebefb3d6193e4480f2b08b859'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot (0.1.5)
4
+ superbot (0.1.6)
5
5
  clamp (= 1.2.1)
6
6
  kommando (~> 0.1)
7
7
  launchy (= 2.4.3)
data/lib/superbot.rb CHANGED
@@ -3,10 +3,17 @@
3
3
  module Superbot
4
4
  WEBDRIVER_ENDPOINT = {
5
5
  cloud: "http://webdriver.superbot.cloud:3000/webdriver/v1",
6
- local: "http://127.0.0.1:9515"
6
+ local: "http://127.0.0.1:9515",
7
+ local_cloud: "htpp://localhost:3000/webdriver/v1"
7
8
  }.freeze
8
9
  private_constant :WEBDRIVER_ENDPOINT
9
10
 
11
+ SCREENSHOTS_ENDPOINT = {
12
+ cloud: "http://peek.superbot.cloud/v1",
13
+ local_cloud: "http://localhost:3002/v1"
14
+ }.freeze
15
+ private_constant :SCREENSHOTS_ENDPOINT
16
+
10
17
  CLOUD_TIMEOUT = 2000
11
18
  private_constant :CLOUD_TIMEOUT
12
19
 
@@ -21,6 +28,10 @@ module Superbot
21
28
  def self.cloud_timeout
22
29
  CLOUD_TIMEOUT
23
30
  end
31
+
32
+ def self.screenshots_url(type, session_id)
33
+ "#{SCREENSHOTS_ENDPOINT[type.to_sym]}/#{session_id}"
34
+ end
24
35
  end
25
36
 
26
37
  require_relative "superbot/version"
@@ -17,11 +17,6 @@ module Superbot
17
17
  def run(script)
18
18
  puts "Attaching to #{browser} browser..."
19
19
  create_runner
20
- if browser == 'cloud'
21
- puts "Opening screenshot stream..."
22
- runner.in.writeln({ eval: screenshot_stream }.to_json)
23
- wait_for_finish
24
- end
25
20
  puts "Running test..."
26
21
  runner.in.writeln({ eval: script }.to_json)
27
22
  wait_for_finish
@@ -72,7 +67,6 @@ module Superbot
72
67
  case parsed_error[:class]
73
68
  when "Selenium::WebDriver::Error::WebDriverError", "Selenium::WebDriver::Error::NoSuchWindowError"
74
69
  kill_session
75
- puts parsed_error[:message]
76
70
  puts "", "Seems like browser session has been closed, try to run test again to create new session"
77
71
  when "Selenium::WebDriver::Error::ServerError"
78
72
  kill_session
@@ -119,20 +113,8 @@ module Superbot
119
113
  )
120
114
  end
121
115
  ::Capybara.current_driver = :chrome_remote
122
- session_id = ::Capybara.current_session.driver.browser.send(:bridge).session_id
123
116
  WEBDRIVER_CONFIG
124
117
  end
125
-
126
- def screenshot_stream
127
- <<-SCREENSHOT_STREAM
128
- screenshots_url = 'http://peek.superbot.cloud/v1/' + session_id
129
- ::Capybara.current_driver = :selenium_chrome
130
- ::Capybara.session_name = :peek
131
- visit screenshots_url
132
- ::Capybara.current_driver = :chrome_remote
133
- ::Capybara.session_name = :default
134
- SCREENSHOT_STREAM
135
- end
136
118
  end
137
119
  end
138
120
  end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require_relative "new_command"
4
4
  require_relative "run_command"
5
+ require_relative "teleport_command"
5
6
  require_relative "version_command"
6
7
 
7
8
  module Superbot
@@ -12,6 +13,7 @@ module Superbot
12
13
  subcommand ["new"], "Create a new project", NewCommand
13
14
  subcommand ["run"], "Run a project", RunCommand
14
15
  subcommand ["version"], "Show version information", VersionCommand
16
+ subcommand ["teleport"], "Open a teleport for superbots", TeleportCommand
15
17
 
16
18
  def self.run
17
19
  super
@@ -13,28 +13,28 @@ module Superbot
13
13
  validates_browser_type browser
14
14
  end
15
15
  option ['--region'], 'REGION', 'Region for remote webdriver'
16
- option ['--auth-token'], 'AUTH_TOKEN', 'Cloud webdriver auth credentials', environment_variable: 'CLOUD_DRIVER_AUTH_TOKEN'
16
+ option ['-u', '--user'], 'AUTH_USER_NAME', 'Cloud webdriver auth credentials', environment_variable: 'AUTH_USER_NAME', attribute_name: :auth_user
17
+ option ['-p', '--password'], 'AUTH_USER_PASSWORD', 'Cloud webdriver auth credentials', environment_variable: 'AUTH_USER_PASSWORD', attribute_name: :auth_password
17
18
 
18
19
  def execute
19
20
  script = File.read(File.join(path, 'main.rb'))
20
21
 
21
- webdriver_proxy = Superbot::Web.new(webdriver_endpoint: Superbot.webdriver_endpoint(browser), auth_token: auth_token)
22
- webdriver_proxy.run_async_after_running!
23
- puts "🤖 active"
22
+ @teleport = Thread.new do
23
+ Superbot::CLI::TeleportCommand.run(nil, ARGV[2..-1], context)
24
+ rescue => e
25
+ abort e.message
26
+ end
24
27
 
25
- chromedriver = Kommando.run_async 'chromedriver --silent --port=9515' if browser == 'local'
28
+ @capybara_runner = Superbot::Capybara::Runner.new(browser: browser, region: region)
29
+ @capybara_runner.run(script)
30
+ puts @capybara_runner.test_result
26
31
 
27
- capybara_runner = Superbot::Capybara::Runner.new(browser: browser, region: region)
28
- capybara_runner.run(script)
29
-
30
- puts capybara_runner.test_result
31
32
  puts "Press ENTER to exit"
32
33
 
33
34
  $stdin.gets
34
35
  ensure
35
- chromedriver&.kill
36
- webdriver_proxy&.quit!
37
- capybara_runner&.kill_session
36
+ @teleport&.kill
37
+ @capybara_runner&.kill_session
38
38
  end
39
39
  end
40
40
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Superbot
4
+ module CLI
5
+ class TeleportCommand < Clamp::Command
6
+ include Superbot::Validations
7
+
8
+ option ['--browser'], 'BROWSER', "Browser type to use. Can be either local or cloud", default: 'local' do |browser|
9
+ validates_browser_type browser
10
+ end
11
+ option ['--region'], 'REGION', 'Region for remote webdriver'
12
+ option ['-u', '--user'], 'AUTH_USER_NAME', 'Cloud webdriver auth credentials', environment_variable: 'AUTH_USER_NAME', attribute_name: :auth_user
13
+ option ['-p', '--password'], 'AUTH_USER_PASSWORD', 'Cloud webdriver auth credentials', environment_variable: 'AUTH_USER_PASSWORD', attribute_name: :auth_password
14
+
15
+ def execute
16
+ @web = Superbot::Web.new(
17
+ webdriver_type: browser,
18
+ auth_user: auth_user,
19
+ auth_password: auth_password
20
+ ).tap(&:run_async_after_running!)
21
+
22
+ @chromedriver = Kommando.run_async 'chromedriver --silent --port=9515' if browser == 'local'
23
+ puts "", "🤖 Teleport is active ☁️ "
24
+
25
+ $stdin.gets
26
+ rescue
27
+ @chromedriver&.kill
28
+ @web&.quit!
29
+ ensure
30
+ @chromedriver&.kill
31
+ @web&.quit!
32
+ end
33
+ end
34
+ end
35
+ end
@@ -16,7 +16,7 @@ module Superbot
16
16
  end
17
17
 
18
18
  def validates_browser_type(browser)
19
- unless %w(local cloud).include?(browser)
19
+ unless %w(local cloud local_cloud).include?(browser)
20
20
  raise ArgumentError, "The '#{browser}' browser option is not allowed. Should be either 'local' or 'cloud'."
21
21
  end
22
22
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superbot
4
- VERSION = "0.1.5"
4
+ VERSION = "0.1.6"
5
5
  end
data/lib/superbot/web.rb CHANGED
@@ -3,13 +3,14 @@
3
3
  require "sinatra/base"
4
4
  require "sinatra/silent"
5
5
  require 'net/http'
6
+ require 'selenium-webdriver'
6
7
 
7
8
  require_relative "capybara/convert"
8
9
  require_relative "capybara/runner"
9
10
 
10
11
  module Superbot
11
12
  class Web
12
- def initialize(webdriver_endpoint: nil, auth_token: nil)
13
+ def initialize(webdriver_type: 'local', auth_user: nil, auth_password: nil)
13
14
  @sinatra = Sinatra.new
14
15
  @sinatra.set :bind, "127.0.0.1"
15
16
  @sinatra.set :silent_sinatra, true
@@ -37,12 +38,11 @@ module Superbot
37
38
  instance.capybara_runner.run(converted_script)
38
39
  end
39
40
 
40
- return unless webdriver_endpoint
41
-
42
- webdriver_uri = URI.parse(webdriver_endpoint)
43
- @auth_token = auth_token
41
+ webdriver_uri = URI.parse(Superbot.webdriver_endpoint(webdriver_type))
42
+ @auth_user = auth_user
43
+ @auth_password = auth_password
44
44
  @request_settings = {
45
- userinfo: @auth_token,
45
+ userinfo: [@auth_user, @auth_password].join(':'),
46
46
  host: webdriver_uri.host,
47
47
  port: webdriver_uri.port,
48
48
  path: webdriver_uri.path
@@ -61,10 +61,18 @@ module Superbot
61
61
  )
62
62
  status response.code
63
63
  headers instance.all_headers(response)
64
+
65
+ if %w(cloud local_cloud).include?(webdriver_type) && verb == 'post' && request.path_info == '/wd/hub/session' && response.kind_of?(Net::HTTPSuccess)
66
+ session_id = JSON.parse(response.body)['sessionId']
67
+
68
+ puts "Opening screenshots stream..."
69
+ options = Selenium::WebDriver::Chrome::Options.new
70
+ options.add_argument("app=#{Superbot.screenshots_url(webdriver_type, session_id)}")
71
+ options.add_argument('no-sandbox')
72
+ ::Selenium::WebDriver.for :chrome, options: options
73
+ end
74
+
64
75
  response.body
65
- rescue => e
66
- puts e.message
67
- halt 500, { message: e.message }.to_json
68
76
  end
69
77
  end
70
78
  end
@@ -82,7 +90,7 @@ module Superbot
82
90
  )
83
91
  )
84
92
  req = Net::HTTP.const_get(type).new(uri, new_headers.merge('Content-Type' => 'application/json'))
85
- req.basic_auth(*@auth_token.split(':')) if @auth_token
93
+ req.basic_auth(@auth_user, @auth_password) if @auth_user && @auth_password
86
94
  req.body = body.read
87
95
  Net::HTTP.new(uri.hostname, uri.port).start do |http|
88
96
  http.read_timeout = Superbot.cloud_timeout
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-30 00:00:00.000000000 Z
11
+ date: 2018-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -267,6 +267,7 @@ files:
267
267
  - lib/superbot/cli/new_command.rb
268
268
  - lib/superbot/cli/root_command.rb
269
269
  - lib/superbot/cli/run_command.rb
270
+ - lib/superbot/cli/teleport_command.rb
270
271
  - lib/superbot/cli/validations.rb
271
272
  - lib/superbot/cli/version_command.rb
272
273
  - lib/superbot/project.rb