Class: Conformity::Actions
- Inherits:
-
Object
- Object
- Conformity::Actions
show all
- Defined in:
- lib/conformity/actions.rb
Constant Summary
collapse
- ACTIONS =
[:visit, :find, :fill_in, :select, :check, :uncheck, :choose,
:click_on, :wait]
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#check(locator, options = {}) ⇒ Object
-
#choose(locator, options = {}) ⇒ Object
-
#click_on(locator, options = {}) ⇒ Object
-
#field(name, options = {}) ⇒ Object
-
#fill_in(locator, options = {}) ⇒ Object
-
#initialize(fields, session = Capybara.current_session) ⇒ Actions
constructor
A new instance of Actions.
-
#method_missing(name, *args, &block) ⇒ Object
-
#screenshot(name) ⇒ Object
-
#select(value, options = {}) ⇒ Object
-
#uncheck(locator, options = {}) ⇒ Object
-
#unselect(value, options = {}) ⇒ Object
Constructor Details
#initialize(fields, session = Capybara.current_session) ⇒ Actions
Returns a new instance of Actions.
8
9
10
11
|
# File 'lib/conformity/actions.rb', line 8
def initialize(fields, session = Capybara.current_session)
@fields = fields
@session = session
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/conformity/actions.rb', line 86
def method_missing(name, *args, &block)
if ACTIONS.include?(name)
session.send(name, *args, &block)
screenshot(name) if Conformity.log_screenshots
elsif [:has_status_code?, :has_content?]
else super
end
end
|
Instance Attribute Details
#fields ⇒ Object
Returns the value of attribute fields.
3
4
5
|
# File 'lib/conformity/actions.rb', line 3
def fields
@fields
end
|
#session ⇒ Object
Returns the value of attribute session.
3
4
5
|
# File 'lib/conformity/actions.rb', line 3
def session
@session
end
|
Instance Method Details
#check(locator, options = {}) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/conformity/actions.rb', line 48
def check(locator, options={})
begin
session.check(locator, options)
rescue Capybara::ElementNotFound
session.find(locator, options).set(true)
end
screenshot(:check) if Conformity.log_screenshots
end
|
#choose(locator, options = {}) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'lib/conformity/actions.rb', line 39
def choose(locator, options={})
begin
session.choose(locator, options)
rescue Capybara::ElementNotFound
session.find(locator, options).set(true)
end
screenshot(:choose) if Conformity.log_screenshots
end
|
#click_on(locator, options = {}) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/conformity/actions.rb', line 17
def click_on(locator, options={})
begin
session.click_on(locator, options)
rescue Capybara::ElementNotFound
session.find(locator, options).click
end
screenshot(:click_on) if Conformity.log_screenshots
end
|
#field(name, options = {}) ⇒ Object
13
14
15
|
# File 'lib/conformity/actions.rb', line 13
def field(name, options={})
fields.value(name)
end
|
#fill_in(locator, options = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/conformity/actions.rb', line 26
def fill_in(locator, options={})
begin
dup = options.dup
session.fill_in(locator, dup)
rescue Capybara::ElementNotFound
raise "Must pass a hash containing 'with'" if not options.is_a?(Hash) or not options.has_key?(:with)
with = options.delete(:with)
fill_options = options.delete(:fill_options)
session.find(locator, options).set(with)
end
screenshot(:fill_in) if Conformity.log_screenshots
end
|
#screenshot(name) ⇒ Object
97
98
99
100
101
|
# File 'lib/conformity/actions.rb', line 97
def screenshot(name)
file_name = "#{Time.now.to_i}_#{name}.png"
full_path = Conformity.screenshots_folder + "/" + file_name
session.send(:save_screenshot, full_path)
end
|
#select(value, options = {}) ⇒ Object
66
67
68
69
70
71
72
73
74
|
# File 'lib/conformity/actions.rb', line 66
def select(value, options={})
begin
session.select(value, options)
rescue Capybara::ElementNotFound
options.delete(:from)
session.find(value, options).select_option
end
screenshot(:select) if Conformity.log_screenshots
end
|
#uncheck(locator, options = {}) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/conformity/actions.rb', line 57
def uncheck(locator, options={})
begin
session.uncheck(locator, options)
rescue Capybara::ElementNotFound
session.find(locator, options).set(false)
end
screenshot(:uncheck) if Conformity.log_screenshots
end
|
#unselect(value, options = {}) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/conformity/actions.rb', line 76
def unselect(value, options={})
begin
session.unselect(value, options)
rescue Capybara::ElementNotFound
options.delete(:from)
session.find(value, options).unselect_option
end
screenshot(:unselect) if Conformity.log_screenshots
end
|