site_prism 2.0 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/site_prism/element_container.rb +35 -35
- data/lib/site_prism/page.rb +6 -6
- data/lib/site_prism/section.rb +6 -6
- data/lib/site_prism/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -409,6 +409,22 @@ of seconds to wait. Using the above example:
|
|
409
409
|
@home.wait_until_search_field_invisible(10)
|
410
410
|
```
|
411
411
|
|
412
|
+
#### CSS Selectors vs. XPath Expressions
|
413
|
+
|
414
|
+
While the above examples all use CSS selectors to find elements, it is
|
415
|
+
possible to use XPath expressions too. In SitePrism, everywhere that you
|
416
|
+
can use a CSS selector, you can use an XPath expression. An example:
|
417
|
+
|
418
|
+
```ruby
|
419
|
+
class Home < SitePrism::Page
|
420
|
+
# CSS Selector:
|
421
|
+
element :first_name, "div#signup input[name='first-name']"
|
422
|
+
|
423
|
+
#same thing as an XPath expression:
|
424
|
+
element :first_name, :xpath, "//div[@id='signup']//input[@name='first-name']"
|
425
|
+
end
|
426
|
+
```
|
427
|
+
|
412
428
|
#### Summary of what the element method provides:
|
413
429
|
|
414
430
|
Given:
|
@@ -1,34 +1,34 @@
|
|
1
1
|
module SitePrism::ElementContainer
|
2
2
|
|
3
|
-
def element element_name,
|
4
|
-
build element_name,
|
3
|
+
def element element_name, *find_args
|
4
|
+
build element_name, *find_args do
|
5
5
|
define_method element_name.to_s do
|
6
|
-
find_first
|
6
|
+
find_first *find_args
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def elements collection_name,
|
12
|
-
build collection_name,
|
11
|
+
def elements collection_name, *find_args
|
12
|
+
build collection_name, *find_args do
|
13
13
|
define_method collection_name.to_s do
|
14
|
-
find_all
|
14
|
+
find_all *find_args
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
alias :collection :elements
|
19
19
|
|
20
|
-
def section section_name, section_class,
|
21
|
-
build section_name,
|
20
|
+
def section section_name, section_class, *find_args
|
21
|
+
build section_name, *find_args do
|
22
22
|
define_method section_name do
|
23
|
-
section_class.new find_first
|
23
|
+
section_class.new find_first *find_args
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
def sections section_collection_name, section_class,
|
29
|
-
build section_collection_name,
|
28
|
+
def sections section_collection_name, section_class, *find_args
|
29
|
+
build section_collection_name, *find_args do
|
30
30
|
define_method section_collection_name do
|
31
|
-
find_all(
|
31
|
+
find_all(*find_args).collect do |element|
|
32
32
|
section_class.new element
|
33
33
|
end
|
34
34
|
end
|
@@ -57,73 +57,73 @@ module SitePrism::ElementContainer
|
|
57
57
|
|
58
58
|
private
|
59
59
|
|
60
|
-
def build name,
|
61
|
-
if
|
60
|
+
def build name, *find_args
|
61
|
+
if find_args.empty?
|
62
62
|
create_no_selector name
|
63
63
|
else
|
64
64
|
add_to_mapped_items name
|
65
65
|
yield
|
66
66
|
end
|
67
|
-
add_checkers_and_waiters name,
|
67
|
+
add_checkers_and_waiters name, *find_args
|
68
68
|
end
|
69
69
|
|
70
|
-
def add_checkers_and_waiters name,
|
71
|
-
create_existence_checker name,
|
72
|
-
create_waiter name,
|
73
|
-
create_visibility_waiter name,
|
74
|
-
create_invisibility_waiter name,
|
70
|
+
def add_checkers_and_waiters name, *find_args
|
71
|
+
create_existence_checker name, *find_args
|
72
|
+
create_waiter name, *find_args
|
73
|
+
create_visibility_waiter name, *find_args
|
74
|
+
create_invisibility_waiter name, *find_args
|
75
75
|
end
|
76
76
|
|
77
|
-
def build_checker_or_waiter element_name, proposed_method_name,
|
78
|
-
if
|
77
|
+
def build_checker_or_waiter element_name, proposed_method_name, *find_args
|
78
|
+
if find_args.empty?
|
79
79
|
create_no_selector element_name, proposed_method_name
|
80
80
|
else
|
81
81
|
yield
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
def create_existence_checker element_name,
|
85
|
+
def create_existence_checker element_name, *find_args
|
86
86
|
method_name = "has_#{element_name.to_s}?"
|
87
|
-
build_checker_or_waiter element_name, method_name,
|
87
|
+
build_checker_or_waiter element_name, method_name, *find_args do
|
88
88
|
define_method method_name do
|
89
89
|
Capybara.using_wait_time 0 do
|
90
|
-
element_exists?
|
90
|
+
element_exists? *find_args
|
91
91
|
end
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
def create_waiter element_name,
|
96
|
+
def create_waiter element_name, *find_args
|
97
97
|
method_name = "wait_for_#{element_name.to_s}"
|
98
|
-
build_checker_or_waiter element_name, method_name,
|
98
|
+
build_checker_or_waiter element_name, method_name, *find_args do
|
99
99
|
define_method method_name do |timeout = Capybara.default_wait_time|
|
100
100
|
Capybara.using_wait_time timeout do
|
101
|
-
element_exists?
|
101
|
+
element_exists? *find_args
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
def create_visibility_waiter element_name,
|
107
|
+
def create_visibility_waiter element_name, *find_args
|
108
108
|
method_name = "wait_until_#{element_name.to_s}_visible"
|
109
|
-
build_checker_or_waiter element_name, method_name,
|
109
|
+
build_checker_or_waiter element_name, method_name, *find_args do
|
110
110
|
define_method method_name do |timeout = Capybara.default_wait_time|
|
111
111
|
Capybara.using_wait_time timeout do
|
112
|
-
element_exists?
|
112
|
+
element_exists? *find_args
|
113
113
|
end
|
114
114
|
Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementVisibility do
|
115
|
-
sleep 0.1 until find_first(
|
115
|
+
sleep 0.1 until find_first(*find_args).visible?
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
def create_invisibility_waiter element_name,
|
121
|
+
def create_invisibility_waiter element_name, *find_args
|
122
122
|
method_name = "wait_until_#{element_name.to_s}_invisible"
|
123
|
-
build_checker_or_waiter element_name, method_name,
|
123
|
+
build_checker_or_waiter element_name, method_name, *find_args do
|
124
124
|
define_method method_name do |timeout = Capybara.default_wait_time|
|
125
125
|
Timeout.timeout timeout, SitePrism::TimeOutWaitingForElementInvisibility do
|
126
|
-
sleep 0.1 while element_exists?(
|
126
|
+
sleep 0.1 while element_exists?(*find_args) && find_first(*find_args).visible?
|
127
127
|
end
|
128
128
|
end
|
129
129
|
end
|
data/lib/site_prism/page.rb
CHANGED
@@ -49,16 +49,16 @@ module SitePrism
|
|
49
49
|
|
50
50
|
private
|
51
51
|
|
52
|
-
def find_first
|
53
|
-
first
|
52
|
+
def find_first *find_args
|
53
|
+
first *find_args
|
54
54
|
end
|
55
55
|
|
56
|
-
def find_all
|
57
|
-
all
|
56
|
+
def find_all *find_args
|
57
|
+
all *find_args
|
58
58
|
end
|
59
59
|
|
60
|
-
def element_exists?
|
61
|
-
has_selector?
|
60
|
+
def element_exists? *find_args
|
61
|
+
has_selector? *find_args
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
data/lib/site_prism/section.rb
CHANGED
@@ -24,16 +24,16 @@ module SitePrism
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
-
def find_first
|
28
|
-
root_element.first
|
27
|
+
def find_first *find_args
|
28
|
+
root_element.first *find_args
|
29
29
|
end
|
30
30
|
|
31
|
-
def find_all
|
32
|
-
root_element.all
|
31
|
+
def find_all *find_args
|
32
|
+
root_element.all *find_args
|
33
33
|
end
|
34
34
|
|
35
|
-
def element_exists?
|
36
|
-
root_element.has_selector?
|
35
|
+
def element_exists? *find_args
|
36
|
+
root_element.has_selector? *find_args
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
data/lib/site_prism/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: site_prism
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '2.
|
4
|
+
version: '2.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capybara
|