Top Level Namespace
Defined Under Namespace
Modules: Cucumber, CukePack
Classes: WaitingForElementFailure
Constant Summary
collapse
- MAX_TIMES =
20
- WAIT_TIME =
0.1
Instance Method Summary
collapse
Instance Method Details
#_wait_for_exceptions ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/cuke-pack/support/wait_for.rb', line 4
def _wait_for_exceptions
exceptions = [ Capybara::ElementNotFound ]
if defined?(Capybara::Driver::Webkit::Node::ElementNotDisplayedError)
exceptions << Capybara::Driver::Webkit::Node::ElementNotDisplayedError
end
if defined?(Selenium::WebDriver::Error::StaleElementReferenceError)
exceptions << Selenium::WebDriver::Error::StaleElementReferenceError
end
exceptions
end
|
#_wait_for_not_continue_exceptions ⇒ Object
25
26
27
28
29
30
31
32
|
# File 'lib/cuke-pack/support/wait_for.rb', line 25
def _wait_for_not_continue_exceptions
exceptions = []
if defined?(Selenium::WebDriver::Error::StaleElementReferenceError)
exceptions << Selenium::WebDriver::Error::StaleElementReferenceError
end
exceptions
end
|
#_wait_for_not_exceptions ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/cuke-pack/support/wait_for.rb', line 16
def _wait_for_not_exceptions
exceptions = [ Capybara::ElementNotFound ]
if defined?(Capybara::Driver::Webkit::NodeNotAttachedError)
exceptions << Capybara::Driver::Webkit::NodeNotAttachedError
end
exceptions
end
|
#confirm_js ⇒ Object
1
2
3
4
|
# File 'lib/cuke-pack/support/confirm_js.rb', line 1
def confirm_js
page.evaluate_script('window.confirm = function() { return true; }')
page.evaluate_script('window.alert = function() { return true; }')
end
|
#ensure_mocha ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/cuke-pack/support/mocha.rb', line 7
def ensure_mocha
return if @_mocha_ensured
begin
mocha_verify
ensure
mocha_teardown
end
@_mocha_ensured = true
end
|
#expect_field(field, value) ⇒ Object
39
40
41
|
# File 'lib/cuke-pack/support/expect_fields.rb', line 39
def expect_field(field, value)
find(".#{field}").text.should == value
end
|
#expect_fields(object, *fields, &block) ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/cuke-pack/support/expect_fields.rb', line 1
def expect_fields(object, *fields, &block)
$stderr.puts "expect_fields deprecated. Use semantic_rails_view_helpers instead."
@__expect_stack ||= 0
@__expect_stack += 1
options = {}
if fields.last.kind_of?(::Hash)
options = fields.pop.dup
end
search_type = @__expect_stack == 1 ? "#" : "."
if object.respond_to?(:each)
within "#{search_type}#{object.first.class.name.underscore.pluralize}" do
object.each_with_index do |subobject, index|
expect_fields subobject, fields, options.merge(:index => index), &block
end
end
else
finder = "#{search_type}#{object.class.name.underscore}"
if options[:index]
finder << ":eq(#{options[:index] + 1})"
end
within finder do
fields.flatten.each do |field|
expect_field field, object.send(field).to_s
end
block.call(object) if block
end
end
@__expect_stack -= 1
@__expect_stack = nil if @__expect_stack == 0
end
|
#pause ⇒ Object
1
2
3
4
5
6
7
|
# File 'lib/cuke-pack/support/pause.rb', line 1
def pause
if @pause_ok
$stdout.puts "Paused. Press [ Return ] to continue."
$stdin.getc
$stdout.puts "Resuming..."
end
end
|
#take_screenshot(name, options = {}) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/cuke-pack/support/screenshots.rb', line 9
def take_screenshot(name, options = {})
selenium = Capybara.current_session.driver.browser
if selenium.respond_to?(:manage)
options = CukePack.screenshot_options.merge(options)
selenium.manage.window.resize_to(options[:width], options[:height])
target = options[:directory]
target = File.join(target, Capybara.current_driver.to_s)
target = File.join(target, name + ".png")
FileUtils.mkdir_p File.dirname(target)
selenium.save_screenshot(target)
end
end
|
#wait_for(times = MAX_TIMES, &block) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/cuke-pack/support/wait_for.rb', line 48
def wait_for(times = MAX_TIMES, &block)
$stderr.puts "wait_for deprecated. Just use find."
1.upto(times) do
ok = false
begin
ok = block.()
rescue *_wait_for_exceptions
ok = false
end
if ok
return
else
sleep WAIT_TIME
end
end
raise WaitingForElementFailure.new(block)
end
|
#wait_for_not(times = MAX_TIMES, &block) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/cuke-pack/support/wait_for.rb', line 70
def wait_for_not(times = MAX_TIMES, &block)
$stderr.puts "wait_for_not deprecated. Just use find."
original_time = Capybara.default_wait_time
Capybara.default_wait_time = 0
1.upto(times) do
ok = false
begin
block.()
rescue *_wait_for_not_continue_exceptions
ok = false
rescue *_wait_for_not_exceptions
ok = true
end
if ok
Capybara.default_wait_time = original_time
return
else
sleep WAIT_TIME
end
end
raise WaitingForElementFailure.new(block)
end
|