superbara 0.4.1 → 0.5.0

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: 0cb221cfedb0e07f9fd5dcb495a3574653c7330824a130f2c1a7812bf3184f0b
4
- data.tar.gz: 85c887a88c3183cd0a7b64fea61158d2717c6fbacb705d8e356337e15c723187
3
+ metadata.gz: 4d3ed6c4088db72ad7e50b5add522ca21e0e047da90c19805fd0e644b37ed174
4
+ data.tar.gz: de565273eae1360e53eeca61cf61821f3dfb353e863a5b6551c3522ccde3b041
5
5
  SHA512:
6
- metadata.gz: 7bdc13ea9845d3a51f9a98e2853b36b4e54584050cd02b6224acebe066d03100a45b933b1c42949f207463e05459d13e2c724e0e51e79b069a11b1a677755633
7
- data.tar.gz: 7e3510fb2f53a7cfce94fc019ac44f1ba260375289c1dd4da6227c5d3ac1623a4e1120e701a07f6484cb5665a15666e62f0ba68b174f8157c1759d2694f031be
6
+ metadata.gz: b09ae0bb806790c3090f495fa66502ee80cf9505b68379caaed1d52418a3a5016ac1074cda88b5ac5fa3006c469158e6ecff42c34d465e9b35df88d82b4e1677
7
+ data.tar.gz: 1597e47aecfab3de8c46deb32bc0bf1800ae8cb0cada1a1ffdc3928cd7bede4743fc80ed395cc6ebccbe51016b823f2f09e8f0b6908e46190929b3401a65c4f3
@@ -1,9 +1,2 @@
1
- export KUNG_FRONTEND=noninteractive KUNG_ENV=test
2
- kung rc chrome
3
- kung rc superbara
4
- kung stop chrome superbara
5
-
6
- kung rc chrome
7
- export CHROME_URL=http://localhost:14444/wd/hub
8
- echo q | exe/superbara run e2e
9
- kung stop
1
+ KUNG_ENV=test KUNG_FRONTEND=noninteractive kung rc chrome
2
+ KUNG_ENV=test kung rc superbara
data/Dockerfile CHANGED
@@ -3,5 +3,4 @@ ARG version
3
3
  COPY superbara-${version}.gem /tmp
4
4
  RUN gem install /tmp/superbara-${version}.gem && rm /tmp/superbara-${version}.gem
5
5
 
6
- WORKDIR /tests
7
- ENTRYPOINT ["/usr/local/bundle/bin/superbara", "run"]
6
+ ENTRYPOINT ["/usr/local/bundle/bin/superbara", "run", "/e2e"]
data/Gemfile.lock CHANGED
@@ -1,13 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- superbara (0.4.1)
4
+ superbara (0.5.0)
5
5
  binding_of_caller (~> 0.8, >= 0.8.0)
6
- capybara (~> 3.0, >= 3.0.0)
6
+ capybara (~> 3.1, >= 3.1.0)
7
7
  chromedriver-helper (~> 1.2.0, >= 1.2.0)
8
8
  colorize (~> 0.8, >= 0.8.1)
9
+ faker (~> 1.8, >= 1.8.7)
9
10
  pry-byebug (~> 3.6, >= 3.6.0)
10
- selenium-webdriver (~> 3.11, >= 3.11.0)
11
+ selenium-webdriver (~> 3.12, >= 3.12.0)
12
+ sinatra (~> 2.0, >= 2.0.1)
11
13
 
12
14
  GEM
13
15
  remote: https://rubygems.org/
@@ -19,7 +21,7 @@ GEM
19
21
  binding_of_caller (0.8.0)
20
22
  debug_inspector (>= 0.0.1)
21
23
  byebug (10.0.2)
22
- capybara (3.0.0)
24
+ capybara (3.1.0)
23
25
  addressable
24
26
  mini_mime (>= 0.1.3)
25
27
  nokogiri (~> 1.8)
@@ -33,13 +35,19 @@ GEM
33
35
  nokogiri (~> 1.8)
34
36
  coderay (1.1.2)
35
37
  colorize (0.8.1)
38
+ concurrent-ruby (1.0.5)
36
39
  debug_inspector (0.0.3)
37
40
  diff-lcs (1.3)
41
+ faker (1.8.7)
42
+ i18n (>= 0.7)
38
43
  ffi (1.9.23)
44
+ i18n (1.0.1)
45
+ concurrent-ruby (~> 1.0)
39
46
  io-like (0.3.0)
40
47
  method_source (0.9.0)
41
48
  mini_mime (1.0.0)
42
49
  mini_portile2 (2.3.0)
50
+ mustermann (1.0.2)
43
51
  nokogiri (1.8.2)
44
52
  mini_portile2 (~> 2.3.0)
45
53
  pry (0.11.3)
@@ -49,7 +57,9 @@ GEM
49
57
  byebug (~> 10.0)
50
58
  pry (~> 0.10)
51
59
  public_suffix (3.0.2)
52
- rack (2.0.4)
60
+ rack (2.0.5)
61
+ rack-protection (2.0.1)
62
+ rack
53
63
  rack-test (1.0.0)
54
64
  rack (>= 1.0, < 3)
55
65
  rake (10.5.0)
@@ -67,9 +77,15 @@ GEM
67
77
  rspec-support (~> 3.7.0)
68
78
  rspec-support (3.7.1)
69
79
  rubyzip (1.2.1)
70
- selenium-webdriver (3.11.0)
80
+ selenium-webdriver (3.12.0)
71
81
  childprocess (~> 0.5)
72
82
  rubyzip (~> 1.2)
83
+ sinatra (2.0.1)
84
+ mustermann (~> 1.0)
85
+ rack (~> 2.0)
86
+ rack-protection (= 2.0.1)
87
+ tilt (~> 2.0)
88
+ tilt (2.0.8)
73
89
  xpath (3.0.0)
74
90
  nokogiri (~> 1.8)
75
91
 
data/README.md CHANGED
@@ -1,22 +1,182 @@
1
1
  # Superbara
2
2
 
3
+ Web app test scripting that does not hurt.
4
+
5
+ - Based on Capybara: everything is just better and more natural
6
+ - All batteries included: just start scripting, nothing extra required
7
+ - A powerful command line interface with interactive debugger
8
+ - The most natural test language that is still programming, see:
9
+
10
+ ```ruby
11
+ visit "mysite.com"
12
+ wait 3 do
13
+ has_text? "welcome"
14
+ end
15
+
16
+ scroll 20
17
+ click_link "enter"
18
+
19
+ name_field = find "input#name"
20
+ name_field.type "Sarah", :enter
21
+
22
+ if has_text? "Welcome, Sarah"
23
+ run "logout"
24
+ else
25
+ fail "no greeting visible"
26
+ end
3
27
  ```
28
+
29
+ ## Install & Usage
30
+
31
+ ```shell
4
32
  gem install superbara
5
- mkdir tests
6
- cd tests
7
33
  superbara init example
8
34
  superbara start example
35
+ superbara usage
36
+ ```
37
+
38
+ ## Some things that Superbara does that Capybara does not:
39
+
40
+ ```ruby
41
+ # find+click in one line!
42
+ click 'h1'
43
+
44
+ # wait up to 3 seconds for block to return something else than nil or false
45
+ wait 3 do
46
+ has_text? "Welcome"
47
+ end
48
+
49
+ wait 3.1 do
50
+ find "#username"
51
+ end
52
+
53
+ # simulates real typing
54
+ textarea = find "textarea"
55
+ textarea.type "hello", :backspace, :backspace, :backspace, "sinki", :enter
56
+
57
+ # scrolling
58
+ scroll 50
59
+ scroll -20, duration: 4
60
+
61
+ # works also without http://
62
+ visit 'example.com'
63
+
64
+ # highlights when in interactive mode or SUPERBARA_VISUAL env is set
65
+ find "h1"
66
+
67
+ # runs project/file.rb
68
+ run "vars"
69
+
70
+ # possible to run just once per session (superbara start) to speed up
71
+ run "login", once: true
72
+
73
+ # ..and do something when already ran
74
+ run "login", once: true do
75
+ # when already logged in
76
+ visit "http://www.example.com/main"
77
+ end
78
+
79
+ # opens debugger when exception happens or when the test finishes or
80
+ debug
81
+
82
+ # back, forward, reload (and not only go_back, go_forward, refresh)
83
+ back
84
+ forward
85
+ reload
86
+
87
+ # natural sleeps, sleep between 2 and 4 seconds
88
+ think 2..4
89
+ ```
90
+
91
+ Everything that works in Capybara, works in Superbara, see https://github.com/teamcapybara/capybara/#the-dsl
92
+
93
+ Quick Reference:
9
94
  ```
95
+ click_link 'id-of-link'
96
+ click_link 'Link Text'
97
+ click_button 'Save'
98
+ click_on 'Link Text' || click_on 'Button Value'
99
+ click_text 'get started'
100
+
101
+ find 'h1'
102
+ find_field('First Name').value
103
+ find_field(id: 'my_field').value
104
+ find_link('Hello', :visible => :all).visible?
105
+ find_link(class: ['some_class', 'some_other_class'], visible: :all).visible?
106
+
107
+ find_button('Send').click
108
+ find_button(value: '1234').click
109
+
110
+ find(:xpath, ".//table/tr").click
111
+ find("#overlay").find("h1").click
112
+ for a in all('a') do
113
+ if a[:href].include? "about"
114
+ a.click
115
+ end
116
+ end
117
+
118
+ img_boxed = find('img') do |el|
119
+ el['data-box'] == true
120
+ end
121
+
122
+ within '#menu' do
123
+ click 'a', text: 'Pricing'
124
+ end
125
+
126
+ within_table 'Employee' do
127
+ fill_in 'Name', with: 'Sarah'
128
+ end
129
+
130
+ within_fieldset 'Employee' do
131
+ ...
132
+ end
133
+
134
+ facebook_window = window_opened_by do
135
+ click_button 'Like'
136
+ end
137
+
138
+ within_window facebook_window do
139
+ find('#login_email').type 'a@example.com'
140
+ find('#login_password').type 'qwerty'
141
+ click_button 'Submit'
142
+ end
143
+
144
+ execute_script "document.querySelector("#name").style.border = '1px solid red';"
145
+
146
+ value = evaluate_script "window.innerHeight"
147
+
148
+ accept_alert do
149
+ click_link 'Show Alert'
150
+ end
151
+
152
+ dismiss_confirm do
153
+ click_link 'Show Confirm'
154
+ end
10
155
 
156
+ message = accept_prompt with: 'Linda Liukas' do
157
+ click_link 'Author Quiz!'
158
+ end
159
+ message = 'Who is the author of Hello Ruby?'
11
160
 
12
- ## Deps
161
+ has_selector? 'table tr'
162
+ has_no_selector? 'table tr'
13
163
 
14
- https://github.com/SeleniumHQ/selenium/blob/master/rb/CHANGES
15
- https://github.com/teamcapybara/capybara/blob/master/History.md
164
+ has_selector? :xpath, './/table/tr'
16
165
 
166
+ has_xpath? './/table/tr'
167
+ has_no_xpath? './/table/tr'
168
+ has_css? 'table tr.foo'
169
+ has_no_css? 'table tr.foo'
17
170
 
18
- ## Releasing
171
+ has_content? 'foo'
172
+ has_no_content? 'foo'
173
+ has_text? 'foo'
174
+ has_no_text? 'foo'
19
175
 
176
+ fill_in 'First Name', with: 'Johwn'
177
+ choose 'A Radio Button'
178
+ check 'A Checkbox'
179
+ uncheck 'A Checkbox'
180
+ attach_file 'Image', File.join(Dir.pwd,'image.jpg')
181
+ select 'Option', from: 'Select Box'
20
182
  ```
21
- $ rake release
22
- ```
data/bin/console CHANGED
@@ -5,7 +5,6 @@ require_relative "../lib/superbara"
5
5
  require_relative "../lib/superbara/dsl"
6
6
 
7
7
  visit "http://www.example.com"
8
- h1 = find "h1"
9
- h1.highlight
8
+ find "h1"
10
9
 
11
10
  Pry.start
@@ -3,11 +3,11 @@ version: '3.6'
3
3
  services:
4
4
  superbara:
5
5
  image: mattipaksula/superbara
6
- command: e2e
7
6
  environment:
8
7
  - SUPERBARA_FRONTEND=noninteractive
8
+ - CHROME_URL=http://chrome:4444/wd/hub
9
9
  volumes:
10
- - ./e2e:/tests/e2e
10
+ - ./e2e:/e2e
11
11
  depends_on:
12
12
  - chrome
13
13
  chrome:
data/e2e/example.rb ADDED
@@ -0,0 +1,7 @@
1
+ wait 5 do
2
+ visit "example.com"
3
+ end
4
+
5
+ wait 5 do
6
+ has_text? "Example Domain"
7
+ end
data/e2e/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ webapp = Superbara::Web.new access_log: false, server_bind: '0.0.0.0'
2
+ webapp.run_async!
data/e2e/main.rb CHANGED
@@ -1,8 +1,17 @@
1
- if ENV["CHROME_URL"]
2
- Capybara.default_driver = :chrome_remote
1
+ run "init", once: true
2
+ run "vars"
3
+
4
+ visit "#{$test_host}:4567"
5
+ wait "3" do
6
+ has_text? "Superbara"
3
7
  end
4
8
 
5
- visit "http://www.example.com"
9
+ run "wait"
10
+ run "prompt"
11
+ run "type"
12
+
13
+ run "example", once: true do
14
+ visit "example.com"
15
+ end
6
16
 
7
- h1 = find "h1"
8
- h1.highlight
17
+ find "h1"
data/e2e/prompt.rb ADDED
@@ -0,0 +1,7 @@
1
+ visit "/__superbara/prompt"
2
+
3
+ message = accept_prompt with: 'Linda Liukas' do
4
+ click_link 'Author Quiz!'
5
+ end
6
+
7
+ fail unless message == 'Who is the author of Hello Ruby?'
data/e2e/type.rb ADDED
@@ -0,0 +1,4 @@
1
+ visit "/"
2
+
3
+ textarea = find "textarea"
4
+ textarea.type "hello", :backspace, :backspace, "sinki", :enter
data/e2e/vars.rb ADDED
@@ -0,0 +1,5 @@
1
+ $test_host = if ENV["CHROME_URL"]
2
+ "superbara"
3
+ else
4
+ "localhost"
5
+ end
data/e2e/wait.rb ADDED
@@ -0,0 +1,7 @@
1
+ visit "/__superbara/wait"
2
+
3
+ fail if has_text? "500ms"
4
+
5
+ wait 0.8 do
6
+ has_text? "500ms"
7
+ end
data/exe/superbara CHANGED
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- base_path = File.dirname(File.dirname(__FILE__))
4
+ # add lib to libpath (only needed when running from the sources)
5
+ require 'pathname'
6
+ lib_path = File.expand_path('../../lib', Pathname.new(__FILE__).realpath)
7
+ $LOAD_PATH.unshift lib_path unless $LOAD_PATH.include?(lib_path)
4
8
 
5
- Process.exec "#{base_path}/lib/supershell #{ARGV.join(' ')}"
9
+ STDOUT.sync = true
10
+
11
+ require 'superbara'
12
+ Superbara::CLI.run!
@@ -1,49 +1,140 @@
1
+ module Superbara
2
+ module CapybaraMonkey
3
+ module Node
4
+ class Element
5
+ module Includes
6
+ def type(*text)
7
+ self.native.type(*text)
8
+ end
9
+
10
+ def show(styles: nil, remove_highlight: 0.1)
11
+ execute_script "scrollTo(#{self.native.location.x}, #{self.native.location.y-200})"
12
+ styles = [
13
+ {
14
+ "border" => "20px dashed Aqua"
15
+ }
16
+ ] unless styles
17
+
18
+ for style in styles
19
+ Superbara::Helpers.highlight_element(self, style, remove_highlight)
20
+ if styles.size > 1
21
+ sleep 0.05
22
+ end
23
+ end
24
+
25
+ self
26
+ end
27
+ end #Includes
28
+
29
+ module Prepends
30
+ def click(*keys, **offset)
31
+ if Superbara.visual?
32
+ sleep 0.1
33
+ self.show(styles: [{"border" => "10px dashed GreenYellow"}], remove_highlight: 0.1)
34
+ end
35
+ Superbara.output "click #{self.tag_name} '#{self.text}'"
36
+ super *keys, **offset
37
+ end
38
+ end
39
+ end #Element
40
+ end #Node
41
+
42
+ class Result
43
+ module Includes
44
+ def second
45
+ self[1]
46
+ end
47
+ def third
48
+ self[2]
49
+ end
50
+ def fourth
51
+ self[3]
52
+ end
53
+ def fifth
54
+ self[4]
55
+ end
56
+ # active support stops herew
57
+ def sixth
58
+ self[5]
59
+ end
60
+ def seventh
61
+ self[6]
62
+ end
63
+ def eight
64
+ self[7]
65
+ end
66
+ def ninth
67
+ self[8]
68
+ end
69
+ def tenth
70
+ self[9]
71
+ end
72
+ # also
73
+ def random
74
+ self[rand(self.size)]
75
+ end
76
+ def middle
77
+ self[self.size/2]
78
+ end
79
+
80
+ def show(styles=nil)
81
+ for e in self
82
+ e.show styles
83
+ end
84
+ self
85
+ end
86
+
87
+ def click_random(show: false, once: true)
88
+ unless self.any?
89
+ return false
90
+ end
91
+
92
+ index = if once
93
+ @__superbara_clicked ||= []
94
+ if @__superbara_clicked.size == self.size
95
+ return false
96
+ end
97
+
98
+ selected_index = nil
99
+ possible_index = nil
100
+ loop do
101
+ possible_index = rand(self.size)
102
+ next if @__superbara_clicked.include? possible_index
103
+ selected_index = possible_index
104
+ @__superbara_clicked << selected_index
105
+ break
106
+ end
107
+
108
+ selected_index
109
+ else
110
+ rand(self.size)
111
+ end
112
+
113
+ element = self[index]
114
+ element.show if show
115
+ element.click
116
+ end
117
+ end #Includes
118
+ end #Result
119
+ end #Capybara
120
+ end #Superbara
121
+
1
122
  module Capybara
123
+ module DSL
124
+ def self.included(base)
125
+ #warn "including Capybara::DSL in the global scope is not recommended!" if base == Object
126
+ #super
127
+ end
128
+ end
129
+
2
130
  module Node
3
131
  class Element
4
- def highlight
5
- for color in ["DeepPink", "GreenYellow", "Aqua", "Red", "Yellow"]
6
- Superbara::Helpers.highlight_element(self, {color: color})
7
- sleep 0.1
8
- end
9
- "did you see it?"
10
- end
132
+ include Superbara::CapybaraMonkey::Node::Element::Includes
133
+ prepend Superbara::CapybaraMonkey::Node::Element::Prepends
11
134
  end
12
135
  end
13
136
 
14
137
  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
138
+ include Superbara::CapybaraMonkey::Result::Includes
48
139
  end
49
140
  end
data/lib/pry_monkey.rb CHANGED
@@ -1,21 +1,45 @@
1
1
  require "pry-byebug"
2
2
  require "binding_of_caller"
3
3
 
4
- class Pry
5
- class Command::Whereami < Pry::ClassCommand
6
- alias_method :process_orig, :process
7
- def process
8
- if $supress_pry_whereami
9
- $supress_pry_whereami = false
10
- puts ""
11
- nil
12
- else
13
- process_orig
4
+ module Superbara
5
+ module PryMonkey
6
+ class Command
7
+ class Exit < Pry::ClassCommand
8
+ module Prepends
9
+ def process
10
+ Superbara.shell_disable!
11
+ Superbara.visual_disable!
12
+ super
13
+ end
14
+ end
15
+ end
16
+
17
+ class Whereami < Pry::ClassCommand
18
+ module Prepends
19
+ def process
20
+ if $__superbara_supress_pry_whereami
21
+ $__superbara_supress_pry_whereami = false
22
+ puts ""
23
+ nil
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end
14
29
  end
15
30
  end
16
31
  end
17
32
  end
18
33
 
34
+ class Pry
35
+ class Command::Exit < Pry::ClassCommand
36
+ prepend ::Superbara::PryMonkey::Command::Exit::Prepends
37
+ end
38
+ class Command::Whereami < Pry::ClassCommand
39
+ prepend ::Superbara::PryMonkey::Command::Whereami::Prepends
40
+ end
41
+ end
42
+
19
43
  Pry.config.prompt = proc {
20
44
  prefix = "\n==[ console ]== (".colorize(:black).on_white
21
45
 
@@ -47,27 +71,26 @@ Pry.commands.alias_command 'n', 'next'
47
71
  Pry.commands.alias_command 'h', 'help'
48
72
 
49
73
  Pry::Commands.command /^e$/, "edit" do
50
- puts "Opening #{$superbara_current_file} ..."
51
- begin
52
- `superbara edit #{$superbara_current_file}`
53
- rescue Exception => ex
54
- puts "[development mode edit]"
55
- `exe/superbara edit #{$superbara_current_file}`
56
- end
74
+ puts "Opening #{Superbara.project_path} ..."
75
+ `superbara edit #{Superbara.project_path}`
57
76
  end
58
77
 
59
78
  Pry::Commands.command /^help$/, "help" do
60
-
61
79
  capybara_help_help = '''
62
- e = find "h1", text: "Example Domain"
80
+ e = find "h1"
63
81
  e = find "h1", text: /xample Dom/
64
82
  e.click
65
83
 
66
84
  e = wait 2 do
67
- find "p", text: "Added to the cart"
85
+ find "span", text: "Added to the cart"
68
86
  end
69
87
  e.click
70
88
 
89
+ think 2..4
90
+ scroll 50
91
+ scroll -10, duration: 4
92
+ focus
93
+
71
94
  more: https://github.com/teamcapybara/capybara#the-dsl'''
72
95
 
73
96
  capybara_help_header_prefix = "== HELP "
@@ -84,7 +107,7 @@ Pry::Commands.command /^q$/, "abort" do
84
107
  end
85
108
 
86
109
  Pry::Commands.command /^r$/, "retry" do
87
- exit 2
110
+ _pry_.run_command "exit"
88
111
  end
89
112
 
90
113
  Pry::Commands.command /^$/, "repeat last command if stepping" do