superbot 0.1.31 → 0.1.32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/Rakefile +2 -4
- data/lib/superbot.rb +2 -1
- data/lib/superbot/cli/root_command.rb +1 -5
- data/lib/superbot/version.rb +1 -1
- metadata +2 -7
- data/lib/superbot/capybara/convert.rb +0 -45
- data/lib/superbot/capybara/runner.rb +0 -124
- data/lib/superbot/cli/run_command.rb +0 -37
- data/lib/superbot/convert.rb +0 -10
- data/lib/superbot/convert/web.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f5cde0274efbaa2f0c9872151cfb0ffd7df1121c48c4335bce22d3663d1d125
|
4
|
+
data.tar.gz: 83cbc23095365321157ab12a601fbe9fb8ad0ecf3d759f8458d3ab9df999f47e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0c33fd9f1039401e2c360aad2de83026b5a3bbe5ccd89456caa0c09e719989620d2a712adced0f2be5d44732c50093d9336a8c33248f80c1c09239c64a1e2a3
|
7
|
+
data.tar.gz: aa306fb65c6a4df2d0e6ba84053643c67cafd971e589fea25a847116768c11d7a894b0b1b46b88d77750bd579a89d9fe5af97fbb745022dc7cb3674cbdc30881
|
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -3,17 +3,15 @@
|
|
3
3
|
STDOUT.sync = true
|
4
4
|
|
5
5
|
require "bundler/gem_tasks"
|
6
|
+
require "rspec/core/rake_task"
|
6
7
|
require "rubocop/rake_task"
|
7
8
|
require "kommando"
|
8
9
|
|
9
10
|
RuboCop::RakeTask.new
|
11
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
12
|
|
11
13
|
task default: %i[rubocop spec e2e]
|
12
14
|
|
13
|
-
task :spec do
|
14
|
-
system('rspec')
|
15
|
-
end
|
16
|
-
|
17
15
|
task :e2e do
|
18
16
|
e2e_k = Kommando.run "bin/e2e"
|
19
17
|
if e2e_k.code.zero?
|
data/lib/superbot.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'kommando'
|
4
|
+
|
3
5
|
module Superbot
|
4
6
|
DOMAIN = ENV.fetch('SUPERBOT_DOMAIN', 'superbot.cloud')
|
5
7
|
URI_SCHEME = ENV.fetch('SUPERBOT_URI_SCHEME', 'https')
|
@@ -52,6 +54,5 @@ require_relative "superbot/cli/validations"
|
|
52
54
|
end
|
53
55
|
|
54
56
|
require_relative "superbot/project"
|
55
|
-
require_relative "superbot/convert"
|
56
57
|
require_relative "superbot/cli"
|
57
58
|
require_relative "superbot/web"
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "new_command"
|
4
|
-
require_relative "run_command"
|
5
4
|
require_relative "version_command"
|
6
5
|
require_relative "record_command"
|
7
6
|
|
@@ -17,10 +16,7 @@ module Superbot
|
|
17
16
|
|
18
17
|
subcommand ["version"], "Show version information", VersionCommand
|
19
18
|
subcommand ["record"], "Open browser with selenium ide pre-loaded", RecordCommand if ENV['SUPERBOT_FEAT_RECORD'] == 'true'
|
20
|
-
if ENV['SUPERBOT_FEAT_PROJECT'] == 'true'
|
21
|
-
subcommand ["new"], "Create a new project", NewCommand
|
22
|
-
subcommand ["run"], "Run a project", RunCommand
|
23
|
-
end
|
19
|
+
subcommand ["new"], "Create a new project", NewCommand if ENV['SUPERBOT_FEAT_PROJECT'] == 'true'
|
24
20
|
|
25
21
|
if defined?(::Superbot::Cloud::CLI::RootCommand)
|
26
22
|
subcommand ["cloud"], "Show cloud commands", ::Superbot::Cloud::CLI::RootCommand
|
data/lib/superbot/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.32
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Superbots
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clamp
|
@@ -291,17 +291,12 @@ files:
|
|
291
291
|
- bin/superside.crx
|
292
292
|
- exe/superbot
|
293
293
|
- lib/superbot.rb
|
294
|
-
- lib/superbot/capybara/convert.rb
|
295
|
-
- lib/superbot/capybara/runner.rb
|
296
294
|
- lib/superbot/cli.rb
|
297
295
|
- lib/superbot/cli/new_command.rb
|
298
296
|
- lib/superbot/cli/record_command.rb
|
299
297
|
- lib/superbot/cli/root_command.rb
|
300
|
-
- lib/superbot/cli/run_command.rb
|
301
298
|
- lib/superbot/cli/validations.rb
|
302
299
|
- lib/superbot/cli/version_command.rb
|
303
|
-
- lib/superbot/convert.rb
|
304
|
-
- lib/superbot/convert/web.rb
|
305
300
|
- lib/superbot/project.rb
|
306
301
|
- lib/superbot/version.rb
|
307
302
|
- lib/superbot/web.rb
|
@@ -1,45 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Superbot
|
4
|
-
module Capybara
|
5
|
-
class Convert
|
6
|
-
def initialize(json)
|
7
|
-
@json = JSON.parse(json, symbolize_names: true)
|
8
|
-
end
|
9
|
-
|
10
|
-
def self.call(json)
|
11
|
-
new(json).call
|
12
|
-
end
|
13
|
-
|
14
|
-
def call
|
15
|
-
converted_json
|
16
|
-
end
|
17
|
-
|
18
|
-
attr_accessor :json
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def convert_action(action)
|
23
|
-
case action[:type]
|
24
|
-
when 'visit' then "visit '#{action[:url]}'"
|
25
|
-
when 'click' then "find('#{action[:selector]}', match: :first).click"
|
26
|
-
when 'scroll' then
|
27
|
-
"page.execute_script('window.scrollBy(0,' + (page.execute_script('return document.body.scrollHeight') * #{action[:amountPercent]} / 100).to_s + ')')"
|
28
|
-
when 'resolution' then "page.driver.browser.manage.window.resize_to(#{action[:resolution].join(',')})"
|
29
|
-
when 'has-text' then "page.assert_text('#{action[:text]}')"
|
30
|
-
when 'input' then "find('#{action[:selector]}', match: :first).set('#{action[:value]}')"
|
31
|
-
when 'key-press' then "page.driver.browser.action.send_keys(#{coerced_keys(action[:keys])}).perform"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def converted_json
|
36
|
-
return json.map { |action| convert_action(action) }.join('; ') if json.is_a?(Array)
|
37
|
-
return convert_action(json) if json.is_a?(Hash)
|
38
|
-
end
|
39
|
-
|
40
|
-
def coerced_keys(incoming_keys)
|
41
|
-
incoming_keys.map { |k| k = k.delete(':'); k.length > 1 && k.to_sym || k.to_s }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'kommando'
|
4
|
-
|
5
|
-
module Superbot
|
6
|
-
module Capybara
|
7
|
-
class Runner
|
8
|
-
def initialize(browser: :local, region: nil)
|
9
|
-
@browser = browser
|
10
|
-
@region = region
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.run(script, browser: :local, region: nil)
|
14
|
-
new(browser: browser, region: region).run(script)
|
15
|
-
end
|
16
|
-
|
17
|
-
def run(script)
|
18
|
-
puts "Attaching to #{browser} browser..."
|
19
|
-
create_runner
|
20
|
-
puts "Running test..."
|
21
|
-
runner.in.writeln({ eval: script }.to_json)
|
22
|
-
wait_for_finish
|
23
|
-
end
|
24
|
-
|
25
|
-
def kill_session
|
26
|
-
runner&.kill
|
27
|
-
rescue Timeout::Error
|
28
|
-
p # do nothing
|
29
|
-
ensure
|
30
|
-
@runner = nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def wait_for_finish
|
34
|
-
loop do
|
35
|
-
if finished
|
36
|
-
@finished = false
|
37
|
-
break
|
38
|
-
end
|
39
|
-
|
40
|
-
sleep 0.1
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
attr_accessor :script, :runner, :finished, :test_result, :browser, :region
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def create_runner
|
49
|
-
@finished = false
|
50
|
-
|
51
|
-
return if runner
|
52
|
-
|
53
|
-
gem 'superbot-capybara'
|
54
|
-
|
55
|
-
@runner = Kommando.new "sb-capybara"
|
56
|
-
|
57
|
-
runner.out.every(/{"type":"ok".*\n/) do
|
58
|
-
@test_result = "Test succeed!"
|
59
|
-
@finished = true
|
60
|
-
end
|
61
|
-
|
62
|
-
runner.out.every(/{"type":"error".*\n/) do
|
63
|
-
parsed_error = begin
|
64
|
-
JSON.parse(runner.out.lines.last, symbolize_names: true)
|
65
|
-
rescue JSON::ParseError
|
66
|
-
{ message: runner.out.lines.last }
|
67
|
-
end
|
68
|
-
@test_result = "Test failed: #{parsed_error[:message]}"
|
69
|
-
@finished = true
|
70
|
-
|
71
|
-
case parsed_error[:class]
|
72
|
-
when "Selenium::WebDriver::Error::WebDriverError", "Selenium::WebDriver::Error::NoSuchWindowError"
|
73
|
-
kill_session
|
74
|
-
puts "", "Seems like browser session has been closed, try to run test again to create new session"
|
75
|
-
when "Selenium::WebDriver::Error::ServerError"
|
76
|
-
kill_session
|
77
|
-
abort "Remote browser error: #{parsed_error[:message]}"
|
78
|
-
else
|
79
|
-
abort parsed_error[:message]
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
runner.run_async
|
84
|
-
|
85
|
-
runner.in.writeln({ eval: webdriver_config }.to_json)
|
86
|
-
wait_for_finish
|
87
|
-
rescue Gem::LoadError
|
88
|
-
abort "superbot-capybara not installed"
|
89
|
-
end
|
90
|
-
|
91
|
-
def webdriver_config
|
92
|
-
<<-WEBDRIVER_CONFIG
|
93
|
-
::Capybara.register_driver :chrome_remote do |app|
|
94
|
-
webdriver_capabilities = ::Selenium::WebDriver::Remote::Capabilities.chrome(
|
95
|
-
chromeOptions: {
|
96
|
-
'args' => [
|
97
|
-
'no-sandbox',
|
98
|
-
'no-default-browser-check',
|
99
|
-
'disable-infobars',
|
100
|
-
'app=about:blank',
|
101
|
-
]
|
102
|
-
},
|
103
|
-
superOptions: #{region ? { region: region } : {}}
|
104
|
-
)
|
105
|
-
|
106
|
-
webdriver_http_client = ::Selenium::WebDriver::Remote::Http::Default.new.tap do |client|
|
107
|
-
client.read_timeout = #{Superbot.cloud_timeout}
|
108
|
-
client.open_timeout = #{Superbot.cloud_timeout}
|
109
|
-
end
|
110
|
-
|
111
|
-
::Capybara::Selenium::Driver.new(
|
112
|
-
app,
|
113
|
-
browser: :chrome,
|
114
|
-
desired_capabilities: webdriver_capabilities,
|
115
|
-
http_client: webdriver_http_client,
|
116
|
-
url: 'http://127.0.0.1:4567/wd/hub'
|
117
|
-
)
|
118
|
-
end
|
119
|
-
::Capybara.current_driver = :chrome_remote
|
120
|
-
WEBDRIVER_CONFIG
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Superbot
|
4
|
-
module CLI
|
5
|
-
class RunCommand < Clamp::Command
|
6
|
-
include Superbot::Validations
|
7
|
-
|
8
|
-
parameter "PATH", "project directory" do |path|
|
9
|
-
validates_project_path path
|
10
|
-
end
|
11
|
-
|
12
|
-
option ['--browser'], 'BROWSER', "Browser type to use. Can be either local or cloud", default: 'cloud' do |browser|
|
13
|
-
validates_browser_type browser
|
14
|
-
end
|
15
|
-
option ['--region'], 'REGION', 'Region for remote webdriver'
|
16
|
-
|
17
|
-
def execute
|
18
|
-
script = File.read(File.join(path, 'main.rb'))
|
19
|
-
|
20
|
-
@teleport = Thread.new do
|
21
|
-
Superbot::CLI::TeleportCommand.run(nil, ARGV[2..-1], context)
|
22
|
-
end
|
23
|
-
|
24
|
-
@capybara_runner = Superbot::Capybara::Runner.new(browser: browser, region: region)
|
25
|
-
@capybara_runner.run(script)
|
26
|
-
puts @capybara_runner.test_result
|
27
|
-
|
28
|
-
puts "Press [enter] to exit"
|
29
|
-
|
30
|
-
$stdin.gets
|
31
|
-
ensure
|
32
|
-
@teleport&.kill
|
33
|
-
@capybara_runner&.kill_session
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/superbot/convert.rb
DELETED
data/lib/superbot/convert/web.rb
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Superbot
|
4
|
-
module Convert
|
5
|
-
module Web
|
6
|
-
def self.registered(sinatra)
|
7
|
-
sinatra.helpers do
|
8
|
-
def capybara_runner
|
9
|
-
@capybara_runner ||= Superbot::Capybara::Runner.new
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
sinatra.post "/__superbot/v1/convert" do
|
14
|
-
begin
|
15
|
-
converted_script = Superbot::Capybara::Convert.call(request.body.read)
|
16
|
-
capybara_runner.run(converted_script)
|
17
|
-
halt 200
|
18
|
-
rescue SystemExit => e
|
19
|
-
e.message
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|