wist 0.3.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile +1 -2
- data/Gemfile.lock +45 -44
- data/Rakefile +2 -4
- data/lib/wist.rb +32 -66
- data/test/test_helper.rb +2 -2
- data/test/tests/wist_test.rb +4 -21
- data/wist.gemspec +2 -1
- metadata +18 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f50d2a4e813ee0d298dfd8c1bc146178d502100547924ce6c98c87d86f689efe
|
4
|
+
data.tar.gz: 479e8e67c13dc4c3f008e0300bdc9b1cc64b1fab8a8b8dc6cd5ea989b0bf9705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe381784ced54fa784608bba42ff0ed9fe38f85ff52e06916f5e1314c059ebffe7f4e01e44aca1fed743e2ff0d31e4152b11a386e45344a391effd86ed128775
|
7
|
+
data.tar.gz: 314c75cbb6cc1265fbaa9160d96cd0b334211928d483b14ff5bb2b694a6bfc817363491bf4b779406bf08ac97cf041d2bf59acc01256c39c6af05ef959d512d4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,71 +1,72 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
wist (0.
|
4
|
+
wist (0.6.0)
|
5
5
|
capybara
|
6
|
+
common_assert
|
6
7
|
selenium-webdriver
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: http://rubygems.org/
|
10
11
|
specs:
|
12
|
+
addressable (2.8.0)
|
13
|
+
public_suffix (>= 2.0.2, < 5.0)
|
11
14
|
ansi (1.5.0)
|
12
15
|
builder (3.2.2)
|
13
|
-
capybara (
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
capybara (3.36.0)
|
17
|
+
addressable
|
18
|
+
matrix
|
19
|
+
mini_mime (>= 0.1.3)
|
20
|
+
nokogiri (~> 1.8)
|
21
|
+
rack (>= 1.6.0)
|
22
|
+
rack-test (>= 0.6.3)
|
23
|
+
regexp_parser (>= 1.5, < 3.0)
|
24
|
+
xpath (~> 3.2)
|
25
|
+
childprocess (4.1.0)
|
26
|
+
coderay (1.1.2)
|
27
|
+
common_assert (0.0.1)
|
28
|
+
matrix (0.4.2)
|
29
|
+
method_source (0.9.2)
|
30
|
+
mini_mime (1.1.2)
|
31
|
+
mini_portile2 (2.7.1)
|
27
32
|
minitest (5.5.1)
|
28
33
|
minitest-reporters (1.0.11)
|
29
34
|
ansi
|
30
35
|
builder
|
31
36
|
minitest (>= 5.0)
|
32
37
|
ruby-progressbar
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
rack (>= 1.0)
|
48
|
-
rake (10.1.0)
|
38
|
+
nokogiri (1.13.1)
|
39
|
+
mini_portile2 (~> 2.7.0)
|
40
|
+
racc (~> 1.4)
|
41
|
+
pry (0.12.2)
|
42
|
+
coderay (~> 1.1.0)
|
43
|
+
method_source (~> 0.9.0)
|
44
|
+
public_suffix (4.0.6)
|
45
|
+
racc (1.6.0)
|
46
|
+
rack (2.2.3)
|
47
|
+
rack-test (1.1.0)
|
48
|
+
rack (>= 1.0, < 3)
|
49
|
+
rake (13.0.6)
|
50
|
+
regexp_parser (2.2.0)
|
51
|
+
rexml (3.2.5)
|
49
52
|
ruby-progressbar (1.7.1)
|
50
|
-
rubyzip (
|
51
|
-
selenium-webdriver (
|
52
|
-
childprocess (
|
53
|
-
|
54
|
-
rubyzip (
|
55
|
-
|
56
|
-
|
57
|
-
websocket (1.2.2)
|
58
|
-
websocket-driver (0.4.0)
|
59
|
-
xpath (2.0.0)
|
60
|
-
nokogiri (~> 1.3)
|
53
|
+
rubyzip (2.3.2)
|
54
|
+
selenium-webdriver (4.1.0)
|
55
|
+
childprocess (>= 0.5, < 5.0)
|
56
|
+
rexml (~> 3.2, >= 3.2.5)
|
57
|
+
rubyzip (>= 1.2.2)
|
58
|
+
xpath (3.2.0)
|
59
|
+
nokogiri (~> 1.8)
|
61
60
|
|
62
61
|
PLATFORMS
|
63
62
|
ruby
|
64
63
|
|
65
64
|
DEPENDENCIES
|
66
|
-
capybara (=
|
65
|
+
capybara (= 3.36.0)
|
67
66
|
minitest-reporters
|
68
|
-
poltergeist (= 1.5.1)
|
69
67
|
pry
|
70
68
|
rake
|
71
69
|
wist!
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
2.3.5
|
data/Rakefile
CHANGED
@@ -6,9 +6,7 @@ Rake::TestTask.new('test') do |t|
|
|
6
6
|
end
|
7
7
|
|
8
8
|
task 'test:all' do
|
9
|
-
|
10
|
-
|
11
|
-
%w(chrome poltergeist).each do |browser|
|
9
|
+
%w(selenium_chrome_headless).each do |browser|
|
12
10
|
ENV['BROWSER'] = browser
|
13
11
|
Rake::Task['test'].execute
|
14
12
|
end
|
@@ -19,4 +17,4 @@ task :build do
|
|
19
17
|
`rm -rf build`
|
20
18
|
`mkdir build`
|
21
19
|
`mv *.gem build`
|
22
|
-
end
|
20
|
+
end
|
data/lib/wist.rb
CHANGED
@@ -2,51 +2,34 @@ module Wist
|
|
2
2
|
require 'selenium-webdriver'
|
3
3
|
require 'cgi'
|
4
4
|
require 'capybara'
|
5
|
+
require 'common_assert'
|
6
|
+
|
7
|
+
def self.included(klass)
|
8
|
+
klass.include CommonAssert
|
9
|
+
end
|
5
10
|
|
6
11
|
Capybara.register_driver :chrome do |app|
|
7
12
|
Capybara::Selenium::Driver.new(app, browser: :chrome)
|
8
13
|
end
|
9
14
|
|
10
15
|
class << self
|
11
|
-
attr_accessor(:
|
12
|
-
|
13
|
-
|
16
|
+
attr_accessor(:wait_time_method)
|
17
|
+
end
|
18
|
+
|
19
|
+
self.wait_time_method = if defined?(Capybara.default_max_wait_time)
|
20
|
+
:default_max_wait_time
|
21
|
+
else
|
22
|
+
:default_wait_time
|
14
23
|
end
|
15
24
|
|
16
25
|
module Helpers
|
17
26
|
module_function
|
18
27
|
|
19
|
-
def detect_assert_syntax
|
20
|
-
return if Wist.assert_syntax_detected
|
21
|
-
|
22
|
-
if defined?(RSpec)
|
23
|
-
if RSpec.configuration.expect_with[0].configuration.syntax.include?(:expect)
|
24
|
-
Wist.rspec_expect = true
|
25
|
-
else
|
26
|
-
Wist.rspec_should = true
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
Wist.assert_syntax_detected = true
|
31
|
-
end
|
32
|
-
|
33
28
|
def blank?(obj)
|
34
29
|
obj.respond_to?(:empty?) ? obj.empty? : !obj
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
38
|
-
def wist_assert(value, expected)
|
39
|
-
Helpers.detect_assert_syntax
|
40
|
-
|
41
|
-
if Wist.rspec_expect
|
42
|
-
expect(value).to eq(expected)
|
43
|
-
elsif Wist.rspec_should
|
44
|
-
value.should == expected
|
45
|
-
else
|
46
|
-
assert_equal(expected, value)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
33
|
def wait_until(timeout: false)
|
51
34
|
do_instantly do
|
52
35
|
Selenium::WebDriver::Wait.new(timeout: timeout || @old_wait_time).until do
|
@@ -59,15 +42,8 @@ module Wist
|
|
59
42
|
end
|
60
43
|
end
|
61
44
|
|
62
|
-
def click(
|
63
|
-
find(
|
64
|
-
end
|
65
|
-
|
66
|
-
def set_cookie(k, v)
|
67
|
-
page.execute_script <<-eos
|
68
|
-
(function (e,t,n){var r=new Date;r.setDate(r.getDate()+n);var i=escape(t)+(n==null?"":"; expires="+r.toUTCString());document.cookie=e+"="+i}
|
69
|
-
(#{k.to_json}, #{v.to_json}));
|
70
|
-
eos
|
45
|
+
def click(...)
|
46
|
+
find(...).click
|
71
47
|
end
|
72
48
|
|
73
49
|
def set_value_and_trigger_evts(selector, val)
|
@@ -78,7 +54,7 @@ module Wist
|
|
78
54
|
def verify_tweet_button(text)
|
79
55
|
share_button_src = nil
|
80
56
|
wait_until { share_button_src = find('.twitter-share-button')[:src] }
|
81
|
-
|
57
|
+
common_assert_equal(CGI.parse(URI.parse(share_button_src.gsub('#', '?')).query)['text'][0], text)
|
82
58
|
end
|
83
59
|
|
84
60
|
def driver
|
@@ -167,32 +143,18 @@ module Wist
|
|
167
143
|
end
|
168
144
|
|
169
145
|
%w(first all).each do |finder|
|
170
|
-
define_method("#{finder}_with_wait") do |*args|
|
171
|
-
has_css?(*args)
|
172
|
-
send(finder.to_sym, *args)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
def visit_with_retries(url, retries: 5, wait_time: 10)
|
177
|
-
raise 'only works with poltergeist' unless Capybara.javascript_driver == :poltergeist
|
178
|
-
status = nil
|
179
|
-
|
180
|
-
retries.times do |i|
|
181
|
-
status = visit(url)['status']
|
182
|
-
break if status == 'success'
|
183
|
-
puts "visiting #{url} failed, attempting retry #{i + 1}/#{retries} in #{wait_time} second(s)"
|
184
|
-
sleep wait_time
|
146
|
+
define_method("#{finder}_with_wait") do |*args, **kwargs|
|
147
|
+
has_css?(*args, **kwargs)
|
148
|
+
send(finder.to_sym, *args, **kwargs)
|
185
149
|
end
|
186
|
-
|
187
|
-
raise "visit #{url} failed" unless status == 'success'
|
188
150
|
end
|
189
151
|
|
190
152
|
def assert_text(text, el_or_selector)
|
191
|
-
|
153
|
+
common_assert_equal(process_el_or_selector(el_or_selector).text, text)
|
192
154
|
end
|
193
155
|
|
194
156
|
def assert_text_include(text, el)
|
195
|
-
|
157
|
+
common_assert_equal(el.text.include?(text), true)
|
196
158
|
end
|
197
159
|
|
198
160
|
def parent(el)
|
@@ -209,31 +171,35 @@ module Wist
|
|
209
171
|
%w(has has_no).each do |prefix|
|
210
172
|
define_method("assert_#{prefix}_css") do |selector, opt = {}|
|
211
173
|
opt[:visible] = true if opt[:visible].nil?
|
212
|
-
|
174
|
+
common_assert_equal(send("#{prefix}_css?", selector, **opt), true)
|
213
175
|
end
|
214
176
|
end
|
215
177
|
|
216
|
-
def has_css_instant?(
|
217
|
-
do_instantly { has_css?(
|
178
|
+
def has_css_instant?(...)
|
179
|
+
do_instantly { has_css?(...) }
|
180
|
+
end
|
181
|
+
|
182
|
+
def get_capybara_wait_time
|
183
|
+
Capybara.public_send(Wist.wait_time_method)
|
218
184
|
end
|
219
185
|
|
220
186
|
def do_instantly
|
221
187
|
lambda do
|
222
|
-
|
223
|
-
@old_wait_time =
|
188
|
+
default_max_wait_time = get_capybara_wait_time
|
189
|
+
@old_wait_time = default_max_wait_time if default_max_wait_time > 0
|
224
190
|
end.()
|
225
|
-
Capybara.
|
191
|
+
Capybara.public_send("#{Wist.wait_time_method}=", 0)
|
226
192
|
|
227
193
|
begin
|
228
194
|
yield
|
229
195
|
rescue => e
|
230
196
|
raise(e)
|
231
197
|
ensure
|
232
|
-
Capybara.
|
198
|
+
Capybara.public_send("#{Wist.wait_time_method}=", @old_wait_time)
|
233
199
|
end
|
234
200
|
end
|
235
201
|
|
236
202
|
def assert_el_has_link(selector, link)
|
237
|
-
|
203
|
+
common_assert_equal(get_js("$('#{selector}').attr('href')"), link)
|
238
204
|
end
|
239
205
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'wist'
|
2
|
-
require 'capybara/poltergeist'
|
3
2
|
require 'pry'
|
4
3
|
require "minitest/autorun"
|
5
4
|
require "minitest/reporters"
|
5
|
+
require 'capybara/minitest'
|
6
6
|
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
|
7
7
|
|
8
8
|
class CapybaraTestCase < Minitest::Test
|
@@ -17,4 +17,4 @@ class CapybaraTestCase < Minitest::Test
|
|
17
17
|
def teardown
|
18
18
|
Capybara.reset_sessions!
|
19
19
|
end
|
20
|
-
end
|
20
|
+
end
|
data/test/tests/wist_test.rb
CHANGED
@@ -39,7 +39,7 @@ class WistTest < CapybaraTestCase
|
|
39
39
|
|
40
40
|
wait_until(&wait_until_test(button))
|
41
41
|
# make sure default wait time is back to normal
|
42
|
-
assert_equal(2,
|
42
|
+
assert_equal(2, get_capybara_wait_time)
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_verify_tweet_button
|
@@ -126,12 +126,6 @@ class WistTest < CapybaraTestCase
|
|
126
126
|
assert_equal('changed', get_val('#test_set_value_and_trigger_evts'))
|
127
127
|
end
|
128
128
|
|
129
|
-
def test_set_cookie
|
130
|
-
return if Capybara.javascript_driver == :chrome
|
131
|
-
set_cookie('foo', 'bar')
|
132
|
-
assert_equal('bar', page.evaluate_script("$.cookie('foo')"))
|
133
|
-
end
|
134
|
-
|
135
129
|
def test_set_input_and_press_enter
|
136
130
|
alert_accept('enter pressed') do
|
137
131
|
set_input_and_press_enter('#test_set_input_and_press_enter', 'bar')
|
@@ -154,17 +148,6 @@ class WistTest < CapybaraTestCase
|
|
154
148
|
assert_equal('finder_with_wait', all_with_wait('.done', visible: true)[0][:id])
|
155
149
|
end
|
156
150
|
|
157
|
-
def test_visit_with_retries
|
158
|
-
return unless Capybara.javascript_driver == :poltergeist
|
159
|
-
|
160
|
-
assert_raise RuntimeError do
|
161
|
-
visit_with_retries('a.bc', retries: 2, wait_time: 1)
|
162
|
-
end
|
163
|
-
|
164
|
-
visit_with_retries("file://#{Dir.pwd}/test/test0.html")
|
165
|
-
verify_test_page(0)
|
166
|
-
end
|
167
|
-
|
168
151
|
def test_assert_text
|
169
152
|
assert_text('foo', find('#click_test'))
|
170
153
|
end
|
@@ -193,19 +176,19 @@ class WistTest < CapybaraTestCase
|
|
193
176
|
end
|
194
177
|
|
195
178
|
def test_do_instantly
|
196
|
-
old_time =
|
179
|
+
old_time = get_capybara_wait_time
|
197
180
|
new_time = nil
|
198
181
|
|
199
182
|
begin
|
200
183
|
do_instantly do
|
201
|
-
new_time =
|
184
|
+
new_time = get_capybara_wait_time
|
202
185
|
raise
|
203
186
|
end
|
204
187
|
rescue
|
205
188
|
end
|
206
189
|
|
207
190
|
assert_equal(0, new_time)
|
208
|
-
assert_equal(old_time,
|
191
|
+
assert_equal(old_time, get_capybara_wait_time)
|
209
192
|
end
|
210
193
|
|
211
194
|
def test_interact_with_confirm
|
data/wist.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = 'wist'
|
3
|
-
gem.version = '0.
|
3
|
+
gem.version = '0.6.0'
|
4
4
|
gem.summary = 'capybara helpers'
|
5
5
|
gem.author = 'Lihan Li'
|
6
6
|
gem.email = 'frankieteardrop@gmail.com'
|
@@ -9,6 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
|
10
10
|
gem.add_dependency 'capybara'
|
11
11
|
gem.add_dependency 'selenium-webdriver'
|
12
|
+
gem.add_dependency 'common_assert'
|
12
13
|
|
13
14
|
gem.files = `git ls-files`.split("\n")
|
14
15
|
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lihan Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: common_assert
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description:
|
42
56
|
email: frankieteardrop@gmail.com
|
43
57
|
executables: []
|
@@ -79,17 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
93
|
- !ruby/object:Gem::Version
|
80
94
|
version: '0'
|
81
95
|
requirements: []
|
82
|
-
|
83
|
-
rubygems_version: 2.4.5
|
96
|
+
rubygems_version: 3.2.32
|
84
97
|
signing_key:
|
85
98
|
specification_version: 4
|
86
99
|
summary: capybara helpers
|
87
|
-
test_files:
|
88
|
-
- test/jquery.cookie.js
|
89
|
-
- test/jquery.js
|
90
|
-
- test/test.css
|
91
|
-
- test/test.js
|
92
|
-
- test/test0.html
|
93
|
-
- test/test1.html
|
94
|
-
- test/test_helper.rb
|
95
|
-
- test/tests/wist_test.rb
|
100
|
+
test_files: []
|