superbara 0.2.3 → 0.3.0
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/bin/release +1 -1
- data/e2e/main.rb +1 -0
- data/lib/capybara_monkey.rb +36 -0
- data/lib/superbara/chrome.rb +49 -0
- data/lib/superbara/dsl.rb +12 -0
- data/lib/superbara/version.rb +1 -1
- data/lib/superbara.rb +10 -3
- data/lib/supershell +5 -1
- metadata +2 -4
- data/lib/superbara/drivers/chrome.rb +0 -10
- data/lib/superbara/drivers/chrome_headless.rb +0 -11
- data/lib/superbara/drivers/chrome_remote.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a71b7472f0e04259d7a88bf3996ed8dd4da4e99e9205364a9f6e4eaa48f06481
|
4
|
+
data.tar.gz: 2977c0895d9b2f0bc8b9d325d333abcb9d2c88abf0f239fa48b7671b5fac8a42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85c65b401aa1315c7e81a4cab106651688d0b7d02669149f4a597cddfd7eb9e9332099f9f92ba9370855874197755d456bf742260557a22911e51fc3c52aba7d
|
7
|
+
data.tar.gz: 902595d9e177b8cdab6617a29c030f4bc4177b993d821164fdb6bc18d5c13694aab08ee8fed54d265bdbb67f707aca903564b861b0cd869a31e244d995f8d0ef
|
data/Gemfile.lock
CHANGED
data/bin/release
CHANGED
data/e2e/main.rb
CHANGED
data/lib/capybara_monkey.rb
CHANGED
@@ -10,4 +10,40 @@ module Capybara
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
class Result
|
15
|
+
def click_random(highlight: false, once: true)
|
16
|
+
unless self.any?
|
17
|
+
Superbara.puts "no elements in collection"
|
18
|
+
return false
|
19
|
+
end
|
20
|
+
|
21
|
+
index = if once
|
22
|
+
@__superbara_clicked ||= []
|
23
|
+
if @__superbara_clicked.size == self.size
|
24
|
+
Superbara.puts "no unclicked elements left, not clicking anything"
|
25
|
+
return false
|
26
|
+
end
|
27
|
+
|
28
|
+
selected_index = nil
|
29
|
+
possible_index = nil
|
30
|
+
loop do
|
31
|
+
possible_index = rand(self.size)
|
32
|
+
next if @__superbara_clicked.include? possible_index
|
33
|
+
selected_index = possible_index
|
34
|
+
@__superbara_clicked << selected_index
|
35
|
+
break
|
36
|
+
end
|
37
|
+
|
38
|
+
selected_index
|
39
|
+
else
|
40
|
+
rand(self.size)
|
41
|
+
end
|
42
|
+
|
43
|
+
element = self[index]
|
44
|
+
element.highlight if highlight
|
45
|
+
Superbara.puts "clicking index: #{index} out of #{self.size}"
|
46
|
+
element.click
|
47
|
+
end
|
48
|
+
end
|
13
49
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Superbara; module Chrome
|
2
|
+
@@page_load_strategy = "normal"
|
3
|
+
|
4
|
+
def self.page_load_strategy=(strategy)
|
5
|
+
raise "unknown strategy: #{strategy}" unless ["none", "normal"].include? strategy
|
6
|
+
@@page_load_strategy = strategy
|
7
|
+
|
8
|
+
self.register_drivers
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.register_drivers
|
12
|
+
options = ::Selenium::WebDriver::Chrome::Options.new
|
13
|
+
options.add_argument 'window-size=1680,1024'
|
14
|
+
options.add_argument 'disable-infobars'
|
15
|
+
|
16
|
+
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
|
17
|
+
pageLoadStrategy: @@page_load_strategy
|
18
|
+
)
|
19
|
+
|
20
|
+
Capybara.register_driver :chrome do
|
21
|
+
Capybara::Selenium::Driver.new(nil,
|
22
|
+
browser: :chrome,
|
23
|
+
options: options,
|
24
|
+
desired_capabilities: capabilities
|
25
|
+
)
|
26
|
+
end
|
27
|
+
|
28
|
+
Capybara.register_driver :chrome_remote do
|
29
|
+
Capybara::Selenium::Driver.new(nil,
|
30
|
+
browser: :remote,
|
31
|
+
desired_capabilities: capabilities,
|
32
|
+
url: "http://#{ENV['CHROME_HOST'] || 'chrome'}:#{ENV['CHROME_PORT'] || '4444'}/wd/hub"
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
Capybara.register_driver :chrome_headless do
|
37
|
+
options.add_argument 'disable-gpu'
|
38
|
+
|
39
|
+
Capybara::Selenium::Driver.new(nil,
|
40
|
+
browser: :chrome,
|
41
|
+
desired_capabilities: capabilities,
|
42
|
+
options: options
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
Superbara.puts "registered drivers"
|
47
|
+
Superbara.puts capabilities.inspect
|
48
|
+
end
|
49
|
+
end; end
|
data/lib/superbara/dsl.rb
CHANGED
@@ -3,6 +3,18 @@ module Superbara; module DSL
|
|
3
3
|
puts "Superbara::DSL included in #{includer.inspect}"
|
4
4
|
end
|
5
5
|
|
6
|
+
def atleast(range)
|
7
|
+
min = range.to_a.first
|
8
|
+
add = rand(range.to_a.last)
|
9
|
+
min+add
|
10
|
+
end
|
11
|
+
def think(range)
|
12
|
+
duration = atleast(range)
|
13
|
+
|
14
|
+
Superbara.puts "thinking #{duration}s"
|
15
|
+
sleep duration
|
16
|
+
end
|
17
|
+
|
6
18
|
def wait(seconds, &block)
|
7
19
|
def wait_formatted_output(status, took_delta)
|
8
20
|
word, color = if status
|
data/lib/superbara/version.rb
CHANGED
data/lib/superbara.rb
CHANGED
@@ -8,12 +8,17 @@ require "selenium-webdriver"
|
|
8
8
|
require_relative "capybara_monkey"
|
9
9
|
require_relative "pry_monkey"
|
10
10
|
|
11
|
+
module Superbara
|
12
|
+
def self.puts(str)
|
13
|
+
return unless ENV["SUPERBARA_DEBUG"]
|
14
|
+
Kernel.puts "Superbara #{caller[0][/`.*'/][1..-2]}: #{str}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
11
18
|
require_relative "superbara/version"
|
12
19
|
require_relative "superbara/helpers"
|
13
20
|
|
14
|
-
require_relative "superbara/
|
15
|
-
require_relative "superbara/drivers/chrome_headless"
|
16
|
-
require_relative "superbara/drivers/chrome_remote"
|
21
|
+
require_relative "superbara/chrome"
|
17
22
|
|
18
23
|
trap "SIGINT" do
|
19
24
|
puts "
|
@@ -29,6 +34,8 @@ control+c pressed, closing the browser..."
|
|
29
34
|
exit 99
|
30
35
|
end
|
31
36
|
|
37
|
+
Superbara::Chrome.register_drivers
|
38
|
+
|
32
39
|
require "chromedriver/helper"
|
33
40
|
Chromedriver.set_version "2.37"
|
34
41
|
|
data/lib/supershell
CHANGED
@@ -69,7 +69,7 @@ Error () {
|
|
69
69
|
}
|
70
70
|
|
71
71
|
case $1 in
|
72
|
-
""|"init")
|
72
|
+
""|"init"|"version")
|
73
73
|
;;
|
74
74
|
*)
|
75
75
|
if [ -f $2 ]; then
|
@@ -116,6 +116,10 @@ start testing with:
|
|
116
116
|
shift
|
117
117
|
mode=single
|
118
118
|
;;
|
119
|
+
"version")
|
120
|
+
ruby -r$DIR/superbara -e "puts Superbara::VERSION"
|
121
|
+
exit 0
|
122
|
+
;;
|
119
123
|
*)
|
120
124
|
Usage
|
121
125
|
;;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: superbara
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matti Paksula
|
@@ -220,9 +220,7 @@ files:
|
|
220
220
|
- lib/capybara_monkey.rb
|
221
221
|
- lib/pry_monkey.rb
|
222
222
|
- lib/superbara.rb
|
223
|
-
- lib/superbara/
|
224
|
-
- lib/superbara/drivers/chrome_headless.rb
|
225
|
-
- lib/superbara/drivers/chrome_remote.rb
|
223
|
+
- lib/superbara/chrome.rb
|
226
224
|
- lib/superbara/dsl.rb
|
227
225
|
- lib/superbara/helpers.rb
|
228
226
|
- lib/superbara/rspec.rb
|
@@ -1,10 +0,0 @@
|
|
1
|
-
Capybara.register_driver :chrome do
|
2
|
-
options = ::Selenium::WebDriver::Chrome::Options.new
|
3
|
-
options.add_argument 'window-size=1680,1024'
|
4
|
-
options.add_argument 'disable-infobars'
|
5
|
-
|
6
|
-
Capybara::Selenium::Driver.new(nil,
|
7
|
-
browser: :chrome,
|
8
|
-
options: options
|
9
|
-
)
|
10
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
Capybara.register_driver :chrome_headless do
|
2
|
-
options = ::Selenium::WebDriver::Chrome::Options.new
|
3
|
-
options.add_argument 'headless'
|
4
|
-
options.add_argument 'disable-gpu'
|
5
|
-
options.add_argument 'window-size=1680,1024'
|
6
|
-
|
7
|
-
Capybara::Selenium::Driver.new(nil,
|
8
|
-
browser: :chrome,
|
9
|
-
options: options
|
10
|
-
)
|
11
|
-
end
|