superbot 0.1.10 → 0.1.11

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: 5521299c6e822711616b725a18c9c60d66757301762518ab47543e8e055f4f9c
4
- data.tar.gz: 3b5e2d80ee4c4ea7b308618517c37556c193e07f0d22a430ef2247438f521cca
3
+ metadata.gz: f71e13691620164c6f8ccb20568412b28edd9fbf6a8c8284dd7f1ba728dbdecf
4
+ data.tar.gz: afb80afe5c87473d1bd43b33b5d2a4bf5306f6577b01f415055a5ca33fd0e8dd
5
5
  SHA512:
6
- metadata.gz: 3046c7aada967221fb3b5833dd5cf2a1db4d33d4ddd91c59c546136b5f014ba100b14e9575f47364b7f719f6aa895ac3c519da8fb441dc1067b97266454a1a20
7
- data.tar.gz: e370c5eae0bcbf34b520db8857d96dfb51974b780b162d2c3f1095462e0214dba02c8a59014192ee074dad063f8853c0ba93b08d797bf470b006ddb0dc20158f
6
+ metadata.gz: '09789a18105dba7f043de350645a527a299dcc86525a62ee99b31b3ca805dfb7c6ec8c13f2b5fee8c31df2da6a721ffd51c88f119e729bc25db9bab07e1ddb39'
7
+ data.tar.gz: f3ec0a6cba8bf4f2986d8c96767dccfe7853acaf3cdfcc026dec2332043f77e24761875207fcc2bd0b4b4dd405a9a7cbc60fb61d8ce626886d178b8d49b08ca0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot (0.1.10)
4
+ superbot (0.1.11)
5
5
  clamp (= 1.2.1)
6
6
  kommando (~> 0.1)
7
7
  launchy (= 2.4.3)
@@ -111,7 +111,7 @@ GEM
111
111
  rack-protection (= 2.0.3)
112
112
  tilt (~> 2.0)
113
113
  sinatra-silent (0.0.1)
114
- superbot-cloud (0.1.5)
114
+ superbot-cloud (0.1.6)
115
115
  marcel (= 0.3.3)
116
116
  multipart-post (= 2.0.0)
117
117
  thor (0.20.0)
@@ -13,8 +13,6 @@ module Superbot
13
13
  validates_browser_type browser
14
14
  end
15
15
  option ['--region'], 'REGION', 'Region for remote webdriver'
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
18
16
 
19
17
  def execute
20
18
  script = File.read(File.join(path, 'main.rb'))
@@ -11,9 +11,11 @@ module Superbot
11
11
  option ['--region'], 'REGION', 'Region for remote webdriver'
12
12
 
13
13
  def execute
14
- @web = Superbot::Web.new(webdriver_type: browser).tap(&:run_async_after_running!)
14
+ @web = Superbot::Web.new(webdriver_type: browser, region: region)
15
+ @web.run_async_after_running!
15
16
 
16
17
  @chromedriver = Kommando.run_async 'chromedriver --silent --port=9515' if browser == 'local'
18
+
17
19
  puts "", "🤖 Teleport is active ☁️ "
18
20
  puts "", "Configure your webdriver to http://localhost:4567/wd/hub"
19
21
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superbot
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.11"
5
5
  end
data/lib/superbot/web.rb CHANGED
@@ -2,14 +2,14 @@
2
2
 
3
3
  require "sinatra/base"
4
4
  require "sinatra/silent"
5
- require 'net/http'
5
+ require "net/http"
6
6
 
7
7
  require_relative "capybara/convert"
8
8
  require_relative "capybara/runner"
9
9
 
10
10
  module Superbot
11
11
  class Web
12
- def initialize(webdriver_type: 'cloud')
12
+ def initialize(webdriver_type: 'cloud', region: nil)
13
13
  @sinatra = Sinatra.new
14
14
  @sinatra.set :bind, "127.0.0.1"
15
15
  @sinatra.set :silent_sinatra, true
@@ -37,20 +37,23 @@ module Superbot
37
37
  instance.capybara_runner.run(converted_script)
38
38
  end
39
39
 
40
- webdriver_uri = URI.parse(Superbot.webdriver_endpoint(webdriver_type))
40
+ @webdriver_type = webdriver_type
41
+ webdriver_uri = URI.parse(Superbot.webdriver_endpoint(@webdriver_type))
41
42
  @request_settings = {
42
43
  host: webdriver_uri.host,
43
44
  port: webdriver_uri.port,
44
45
  path: webdriver_uri.path
45
46
  }
47
+ @region = region
46
48
 
47
49
  %w(get post put patch delete).each do |verb|
48
50
  @sinatra.send(verb, "/wd/hub/*") do
49
51
  begin
52
+ request_path = request.path_info.gsub('/wd/hub', '')
50
53
  content_type 'application/json'
51
54
  response = instance.remote_webdriver_request(
52
55
  verb.capitalize,
53
- request.path_info,
56
+ request_path,
54
57
  request.query_string,
55
58
  request.body,
56
59
  instance.incomming_headers(request)
@@ -58,9 +61,9 @@ module Superbot
58
61
  status response.code
59
62
  headers instance.all_headers(response)
60
63
  response.body
61
- rescue
64
+ rescue StandardError => e
62
65
  error_message = "Remote webdriver doesn't responding"
63
- puts error_message
66
+ puts error_message, e
64
67
  halt 500, { message: error_message }.to_json
65
68
  end
66
69
  end
@@ -74,23 +77,39 @@ module Superbot
74
77
  def remote_webdriver_request(type, path, query_string, body, new_headers)
75
78
  uri = URI::HTTP.build(
76
79
  @request_settings.merge(
77
- path: [@request_settings[:path], path.gsub('wd/hub/', '')].join,
80
+ path: @request_settings[:path] + path,
78
81
  query: query_string.empty? ? nil : query_string
79
82
  )
80
83
  )
81
84
  req = Net::HTTP.const_get(type).new(uri, new_headers.merge('Content-Type' => 'application/json'))
82
85
 
83
- if Superbot::Cloud.credentials
84
- req.basic_auth(*Superbot::Cloud.credentials.slice(:username, :token).values)
86
+ request_body = body.read
87
+ if cloud_teleport?
88
+ user_auth_creds = Superbot::Cloud.credentials&.slice(:username, :token)
89
+ req.basic_auth(*user_auth_creds.values) if user_auth_creds
90
+
91
+ if @region && creating_session?(type, path)
92
+ parsed_body = JSON.parse(request_body)
93
+ parsed_body['desiredCapabilities']['superOptions'] = { 'region': @region }
94
+ request_body = parsed_body.to_json
95
+ end
85
96
  end
97
+ req.body = request_body
86
98
 
87
- req.body = body.read
88
99
  Net::HTTP.new(uri.hostname, uri.port).start do |http|
89
100
  http.read_timeout = Superbot.cloud_timeout
90
101
  http.request(req)
91
102
  end
92
103
  end
93
104
 
105
+ def cloud_teleport?
106
+ %w(cloud local_cloud).include?(@webdriver_type)
107
+ end
108
+
109
+ def creating_session?(method, path)
110
+ method.casecmp?('post') && path == '/session'
111
+ end
112
+
94
113
  def all_headers(response)
95
114
  header_list = {}
96
115
  response.header.each_capitalized do |k, v|
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.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Superbots
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2018-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp