superbot 0.1.3 → 0.1.4.rc1

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: 1daf8db5c8573f4ea88fc5b58d7eb2362e84a716baedfbc971bb9ef52cf904e3
4
- data.tar.gz: 6ee9f09184abc8015a4c5293f07beb8e18be57dc263d85a84776a0ad2380565c
3
+ metadata.gz: f96f7642c6913a2137b12f40ecefa344b49b345fa112de19cd5ae284c88ea006
4
+ data.tar.gz: afd49aafb562eb0ddd366a8ce6fb13a75faede33b125d35bed576dd60e407322
5
5
  SHA512:
6
- metadata.gz: fcffe77a0b61e4abb99783a35387fd7ef10f66890309bc7991b99f8285edd02cf7a4228a281b4a8048731196f014f30f405da71708d1f5ba32d39cc7bd0dd4cd
7
- data.tar.gz: 45859ff06232597c4e9c8322878b0bcddfcacf6d5f0ac8c16f98d0d04b52f4b74acadea45406dafbda8e4a95f079ff04f1cbf05e934ca49ae4207e4ba5301ac2
6
+ metadata.gz: 5616bb9d61f728884c6b8b688850e25c2ea4c6777ff9a9756aa64f6a9e7f715f98290c58ca36f9d05606fcbd44af0f7a4e4c033a51c4cd686e863689a7371c6d
7
+ data.tar.gz: 73df24e55278661370984c2c73bd8cb90f06380fd4e13514dce9771ba472d6f7a4a37bb38a726e4b5503920ec6baf0e23ae5f9ae9f1ed130f1b73e84d8f21fa1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbot (0.1.3)
4
+ superbot (0.1.4.rc1)
5
5
  clamp (= 1.2.1)
6
6
  launchy (= 2.4.3)
7
7
  sinatra (= 2.0.3)
@@ -12,7 +12,7 @@ module Superbot
12
12
  end
13
13
 
14
14
  def call
15
- converted_json&.tap { |script| Superbot::Capybara::Runner.run(script) }
15
+ converted_json
16
16
  end
17
17
 
18
18
  attr_accessor :json
@@ -26,6 +26,7 @@ module Superbot
26
26
  when 'scroll' then
27
27
  "page.execute_script('window.scrollBy(0,' + (page.execute_script('return document.body.scrollHeight') * #{action[:amountPercent]} / 100).to_s + ')')"
28
28
  when 'resolution' then "page.driver.browser.manage.window.resize_to(#{action[:resolution].join(',')})"
29
+ when 'has-text' then "page.assert_text('#{action[:text]}')"
29
30
  end
30
31
  end
31
32
 
@@ -5,59 +5,58 @@ require 'kommando'
5
5
  module Superbot
6
6
  module Capybara
7
7
  class Runner
8
- def initialize(script)
9
- @script = script
8
+ def self.run(script)
9
+ new.run(script)
10
10
  end
11
11
 
12
- def self.run(*args)
13
- new(*args).run
12
+ def run(script)
13
+ create_runner
14
+ runner.in.writeln({ eval: script }.to_json)
14
15
  end
15
16
 
16
- def run
17
- run_script
17
+ def rerun(script)
18
+ runner.in.writeln({ eval: script }.to_json)
18
19
  end
19
20
 
21
+ def kill_session
22
+ runner&.kill
23
+ rescue Timeout::Error
24
+ p # do nothing
25
+ ensure
26
+ @runner = nil
27
+ end
28
+
29
+ attr_accessor :script, :runner, :finished
30
+
20
31
  private
21
32
 
22
- attr_accessor :script
33
+ def create_runner
34
+ return if runner
23
35
 
24
- def run_script
25
36
  gem 'superbot-capybara'
26
37
 
27
- k = Kommando.new "sb-capybara"
28
- k.in.writeln({ eval: script }.to_json)
38
+ @runner = Kommando.new "sb-capybara"
29
39
 
30
- finished = false
40
+ @finished = false
31
41
 
32
- k.out.once(/{"type":"ok".*\n/) do
33
- puts "Test succeed"
34
- finished = true
42
+ runner.out.every(/{"type":"ok".*\n/) do
43
+ puts "Test succeed!"
44
+ @finished = true
35
45
  end
36
46
 
37
- k.out.once(/{"type":"error".*\n/) do
38
- begin
39
- parsed_error = JSON.parse(k.out.lines.last, symbolize_names: true)
40
- error_message = parsed_error[:message]
41
- puts "Test failed with #{error_message}"
47
+ runner.out.every(/{"type":"error".*\n/) do
48
+ parsed_error = JSON.parse(runner.out.lines.last, symbolize_names: true)
49
+ puts "Test failed: #{parsed_error[:message]}"
50
+ @finished = true
51
+ if parsed_error[:class].start_with?('Selenium::WebDriver::Error')
52
+ kill_session
53
+ puts "", "ERROR: Seems like browser session has been closed, try to run test again to create new session"
42
54
  end
43
- finished = true
44
- end
45
-
46
- k.run_async
47
-
48
- loop do
49
- break if finished
50
-
51
- sleep 0.001
52
55
  end
53
56
 
54
- begin
55
- k.kill
56
- rescue Timeout::Error
57
- p # do nothing
58
- end
57
+ runner.run_async
59
58
  rescue Gem::LoadError
60
- puts "superbot-capybara not installed"
59
+ abort "superbot-capybara not installed"
61
60
  end
62
61
  end
63
62
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Superbot
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4.rc1"
5
5
  end
data/lib/superbot/web.rb CHANGED
@@ -13,6 +13,7 @@ module Superbot
13
13
  @sinatra.set :silent_sinatra, true
14
14
  @sinatra.set :silent_webrick, true
15
15
  @sinatra.set :silent_access_log, false
16
+ instance = self
16
17
 
17
18
  @sinatra.before do
18
19
  headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, DELETE, OPTIONS'
@@ -30,10 +31,15 @@ module Superbot
30
31
  end
31
32
 
32
33
  @sinatra.post "/__superbot/v1/convert" do
33
- Superbot::Capybara::Convert.call(request.body.read)
34
+ converted_script = Superbot::Capybara::Convert.call(request.body.read)
35
+ instance.capybara_runner.run(converted_script)
34
36
  end
35
37
  end
36
38
 
39
+ def capybara_runner
40
+ @capybara_runner ||= Superbot::Capybara::Runner.new
41
+ end
42
+
37
43
  def run!
38
44
  @sinatra.run_async!
39
45
  end
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.3
4
+ version: 0.1.4.rc1
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-16 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clamp
@@ -308,9 +308,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
308
308
  version: '0'
309
309
  required_rubygems_version: !ruby/object:Gem::Requirement
310
310
  requirements:
311
- - - ">="
311
+ - - ">"
312
312
  - !ruby/object:Gem::Version
313
- version: '0'
313
+ version: 1.3.1
314
314
  requirements: []
315
315
  rubyforge_project:
316
316
  rubygems_version: 2.7.6