page_magic 1.2.6 → 2.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +19 -3
- data/.simplecov +5 -3
- data/.zsh_config +6 -0
- data/Dockerfile +10 -0
- data/Gemfile +12 -12
- data/Gemfile.lock +133 -126
- data/Makefile +13 -0
- data/README.md +78 -14
- data/Rakefile +12 -2
- data/VERSION +1 -1
- data/circle.yml +4 -2
- data/lib/active_support/core_ext/object/to_query.rb +84 -0
- data/lib/page_magic.rb +7 -4
- data/lib/page_magic/class_methods.rb +4 -1
- data/lib/page_magic/driver.rb +3 -0
- data/lib/page_magic/drivers.rb +6 -5
- data/lib/page_magic/drivers/poltergeist.rb +2 -0
- data/lib/page_magic/drivers/rack_test.rb +3 -1
- data/lib/page_magic/drivers/selenium.rb +4 -2
- data/lib/page_magic/element.rb +19 -10
- data/lib/page_magic/element/locators.rb +4 -1
- data/lib/page_magic/element/query.rb +33 -33
- data/lib/page_magic/element/query_builder.rb +61 -0
- data/lib/page_magic/element/selector.rb +3 -0
- data/lib/page_magic/element/selector_methods.rb +3 -0
- data/lib/page_magic/element_context.rb +9 -12
- data/lib/page_magic/element_definition_builder.rb +10 -4
- data/lib/page_magic/elements.rb +51 -8
- data/lib/page_magic/exceptions.rb +4 -33
- data/lib/page_magic/instance_methods.rb +6 -1
- data/lib/page_magic/matcher.rb +12 -3
- data/lib/page_magic/session.rb +7 -5
- data/lib/page_magic/session_methods.rb +2 -0
- data/lib/page_magic/utils/string.rb +14 -0
- data/lib/page_magic/wait_methods.rb +3 -0
- data/lib/page_magic/watcher.rb +2 -0
- data/lib/page_magic/watchers.rb +4 -1
- data/page_magic.gemspec +19 -13
- data/spec/element_spec.rb +2 -0
- data/spec/lib/active_support/core_ext/object/to_query_test.rb +78 -0
- data/spec/page_magic/class_methods_spec.rb +2 -0
- data/spec/page_magic/driver_spec.rb +2 -0
- data/spec/page_magic/drivers/poltergeist_spec.rb +2 -0
- data/spec/page_magic/drivers/rack_test_spec.rb +2 -0
- data/spec/page_magic/drivers/selenium_spec.rb +2 -0
- data/spec/page_magic/drivers_spec.rb +2 -0
- data/spec/page_magic/element/locators_spec.rb +2 -0
- data/spec/page_magic/element/query_builder_spec.rb +110 -0
- data/spec/page_magic/element/query_spec.rb +35 -77
- data/spec/page_magic/element/selector_spec.rb +14 -7
- data/spec/page_magic/element_context_spec.rb +5 -10
- data/spec/page_magic/element_definition_builder_spec.rb +3 -1
- data/spec/page_magic/elements_spec.rb +19 -5
- data/spec/page_magic/instance_methods_spec.rb +2 -0
- data/spec/page_magic/matcher_spec.rb +3 -1
- data/spec/page_magic/session_methods_spec.rb +2 -0
- data/spec/page_magic/session_spec.rb +3 -4
- data/spec/page_magic/utils/string_spec.rb +36 -0
- data/spec/page_magic/wait_methods_spec.rb +5 -3
- data/spec/page_magic/watchers_spec.rb +2 -0
- data/spec/page_magic_spec.rb +5 -7
- data/spec/spec_helper.rb +3 -0
- data/spec/support/shared_contexts.rb +3 -1
- data/spec/support/shared_contexts/files_context.rb +2 -0
- data/spec/support/shared_contexts/nested_elements_html_context.rb +2 -0
- data/spec/support/shared_contexts/rack_application_context.rb +2 -0
- data/spec/support/shared_contexts/webapp_fixture_context.rb +3 -1
- data/spec/support/shared_examples.rb +2 -0
- data/spec/watcher_spec.rb +3 -0
- metadata +62 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4eec3ec93f7cd6ba430ba78860160822632cdc8949da2aea83afddc3366ea3d3
|
4
|
+
data.tar.gz: e3b3634979f0499bd0db1012a209a2d12cce94b7c0b870b1e91d3f8048e3f92b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afe8591e16f7afaa2e464b48ac9eabff046a140df8558dee5bb51aa3eac0ccb43c43cbb43eb7af9d7a2529f242f1cc87b7f63160c5c70decb3bbc9d2cd8d060a
|
7
|
+
data.tar.gz: 95802bd6ab8e1acca9f0d8142452469a743177cdbbf3a44e679016960a23bfe56b453ad53db758bd9ce9edc82f388f90a03c72f76341c24ff517995678e9f2eb
|
data/.rubocop.yml
CHANGED
@@ -2,8 +2,10 @@ Metrics/LineLength:
|
|
2
2
|
Max: 120
|
3
3
|
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion: 2.
|
5
|
+
TargetRubyVersion: 2.7
|
6
6
|
Exclude:
|
7
|
+
- 'lib/active_support/**/*'
|
8
|
+
- 'spec/lib/active_support/**/*'
|
7
9
|
- 'pkg/**/*'
|
8
10
|
- 'vendor/**/*'
|
9
11
|
- 'coverage/**/*'
|
@@ -16,5 +18,19 @@ Metrics/ParameterLists:
|
|
16
18
|
Metrics/MethodLength:
|
17
19
|
Max: 11
|
18
20
|
|
19
|
-
Style/MethodMissing:
|
20
|
-
Enabled: false
|
21
|
+
#Style/MethodMissing:
|
22
|
+
# Enabled: false
|
23
|
+
|
24
|
+
Metrics/BlockLength:
|
25
|
+
Enabled: true
|
26
|
+
Exclude:
|
27
|
+
- 'spec/**/*'
|
28
|
+
|
29
|
+
Style/PercentLiteralDelimiters:
|
30
|
+
PreferredDelimiters:
|
31
|
+
default: ()
|
32
|
+
'%i': '[]'
|
33
|
+
'%I': '[]'
|
34
|
+
'%r': '{}'
|
35
|
+
'%w': '[]'
|
36
|
+
'%W': '[]'
|
data/.simplecov
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'pullreview/coverage'
|
2
|
-
require "codeclimate-test-reporter"
|
3
4
|
|
4
|
-
SimpleCov.formatters
|
5
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, PullReview::Coverage::Formatter]
|
5
6
|
|
6
7
|
SimpleCov.start do
|
7
8
|
add_filter '/spec/'
|
8
|
-
|
9
|
+
add_filter '/lib/active_support/core_ext/object/to_query.rb'
|
10
|
+
end
|
data/.zsh_config
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
#alias bundle="docker run -v ${HOME}/.gitconfig:/root/.gitconfig -v $(pwd):/page_magic -t lvl-up/page-magic bundle"
|
3
|
+
#alias ruby="bundle exec ruby"
|
4
|
+
#alias rake="bundle exec rake"
|
5
|
+
#alias rubocop="bundle exec rubocop"
|
6
|
+
#alias gem="docker run -v $(pwd):/page_magic -t lvl-up/page-magic gem"
|
data/Dockerfile
ADDED
data/Gemfile
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
|
-
gem '
|
4
|
-
gem '
|
5
|
+
gem 'activesupport'
|
6
|
+
gem 'capybara', ">=3.0"
|
5
7
|
|
6
8
|
group :test do
|
7
|
-
gem '
|
8
|
-
gem 'sinatra'
|
9
|
+
gem 'poltergeist'
|
9
10
|
gem 'rspec', require: 'rspec/core/rake_task'
|
10
11
|
gem 'simplecov', require: false
|
11
|
-
gem '
|
12
|
-
gem '
|
13
|
-
gem 'pullreview-coverage', require: false
|
14
|
-
gem 'arbre'
|
12
|
+
gem 'sinatra'
|
13
|
+
gem 'watir'
|
15
14
|
end
|
16
15
|
|
17
16
|
group :development do
|
18
|
-
gem '
|
19
|
-
gem '
|
17
|
+
gem 'github-markup'
|
18
|
+
gem 'jeweler'
|
19
|
+
gem 'redcarpet'
|
20
|
+
gem 'rubocop', require: 'rubocop/rake_task'
|
21
|
+
gem 'ruby-debug-ide', require: false
|
20
22
|
gem 'yard', '~> 0.8'
|
21
|
-
gem 'redcarpet', '~> 3.3'
|
22
|
-
gem 'github-markup', '~> 1.4'
|
23
23
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,167 +1,174 @@
|
|
1
1
|
GEM
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activesupport (
|
5
|
-
|
6
|
-
|
7
|
-
minitest (
|
8
|
-
|
9
|
-
|
4
|
+
activesupport (6.1.3.1)
|
5
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
6
|
+
i18n (>= 1.6, < 2)
|
7
|
+
minitest (>= 5.1)
|
8
|
+
tzinfo (~> 2.0)
|
9
|
+
zeitwerk (~> 2.3)
|
10
10
|
addressable (2.4.0)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
builder (3.2.2)
|
15
|
-
capybara (2.7.1)
|
11
|
+
ast (2.4.2)
|
12
|
+
builder (3.2.4)
|
13
|
+
capybara (3.35.3)
|
16
14
|
addressable
|
17
|
-
|
18
|
-
nokogiri (
|
19
|
-
rack (>= 1.
|
20
|
-
rack-test (>= 0.
|
21
|
-
|
22
|
-
|
23
|
-
childprocess (0.
|
24
|
-
ffi (~> 1.0, >= 1.0.11)
|
15
|
+
mini_mime (>= 0.1.3)
|
16
|
+
nokogiri (~> 1.8)
|
17
|
+
rack (>= 1.6.0)
|
18
|
+
rack-test (>= 0.6.3)
|
19
|
+
regexp_parser (>= 1.5, < 3.0)
|
20
|
+
xpath (~> 3.2)
|
21
|
+
childprocess (3.0.0)
|
25
22
|
cliver (0.3.2)
|
26
|
-
|
27
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
23
|
+
concurrent-ruby (1.1.8)
|
28
24
|
descendants_tracker (0.0.4)
|
29
25
|
thread_safe (~> 0.3, >= 0.3.1)
|
30
|
-
diff-lcs (1.
|
31
|
-
docile (1.
|
26
|
+
diff-lcs (1.4.4)
|
27
|
+
docile (1.3.5)
|
32
28
|
faraday (0.9.2)
|
33
29
|
multipart-post (>= 1.2, < 3)
|
34
|
-
|
35
|
-
|
36
|
-
github-markup (
|
37
|
-
github_api (0.
|
30
|
+
git (1.8.1)
|
31
|
+
rchardet (~> 1.8)
|
32
|
+
github-markup (4.0.0)
|
33
|
+
github_api (0.16.0)
|
38
34
|
addressable (~> 2.4.0)
|
39
35
|
descendants_tracker (~> 0.0.4)
|
40
36
|
faraday (~> 0.8, < 0.10)
|
41
37
|
hashie (>= 3.4)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
38
|
+
mime-types (>= 1.16, < 3.0)
|
39
|
+
oauth2 (~> 1.0)
|
40
|
+
hashie (4.1.0)
|
41
|
+
highline (2.0.3)
|
42
|
+
i18n (1.8.10)
|
43
|
+
concurrent-ruby (~> 1.0)
|
44
|
+
jeweler (2.3.9)
|
47
45
|
builder
|
48
|
-
bundler
|
46
|
+
bundler
|
49
47
|
git (>= 1.2.5)
|
50
|
-
github_api
|
48
|
+
github_api (~> 0.16.0)
|
51
49
|
highline (>= 1.6.15)
|
52
50
|
nokogiri (>= 1.5.10)
|
51
|
+
psych
|
53
52
|
rake
|
54
53
|
rdoc
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
nokogiri (1.
|
67
|
-
mini_portile2 (~> 2.
|
68
|
-
|
69
|
-
oauth2 (1.
|
70
|
-
faraday (>= 0.8, < 0
|
71
|
-
jwt (
|
54
|
+
semver2
|
55
|
+
jwt (2.2.2)
|
56
|
+
mime-types (2.99.3)
|
57
|
+
mini_mime (1.1.0)
|
58
|
+
mini_portile2 (2.5.0)
|
59
|
+
minitest (5.14.4)
|
60
|
+
multi_json (1.15.0)
|
61
|
+
multi_xml (0.6.0)
|
62
|
+
multipart-post (2.1.1)
|
63
|
+
mustermann (1.1.1)
|
64
|
+
ruby2_keywords (~> 0.0.1)
|
65
|
+
nokogiri (1.11.3)
|
66
|
+
mini_portile2 (~> 2.5.0)
|
67
|
+
racc (~> 1.4)
|
68
|
+
oauth2 (1.4.7)
|
69
|
+
faraday (>= 0.8, < 2.0)
|
70
|
+
jwt (>= 1.0, < 3.0)
|
72
71
|
multi_json (~> 1.3)
|
73
72
|
multi_xml (~> 0.5)
|
74
|
-
rack (
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
poltergeist (1.
|
79
|
-
capybara (
|
73
|
+
rack (>= 1.2, < 3)
|
74
|
+
parallel (1.20.1)
|
75
|
+
parser (3.0.1.0)
|
76
|
+
ast (~> 2.4.1)
|
77
|
+
poltergeist (1.18.1)
|
78
|
+
capybara (>= 2.1, < 4)
|
80
79
|
cliver (~> 0.3.1)
|
81
80
|
websocket-driver (>= 0.2.0)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
rack (1.6.4)
|
87
|
-
rack-protection (1.5.3)
|
81
|
+
psych (3.3.1)
|
82
|
+
racc (1.5.2)
|
83
|
+
rack (2.2.3)
|
84
|
+
rack-protection (2.1.0)
|
88
85
|
rack
|
89
|
-
rack-test (
|
90
|
-
rack (>= 1.0)
|
91
|
-
rainbow (
|
92
|
-
rake (
|
93
|
-
|
94
|
-
|
95
|
-
redcarpet (3.
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
rspec-
|
100
|
-
|
101
|
-
rspec-
|
102
|
-
rspec-
|
86
|
+
rack-test (1.1.0)
|
87
|
+
rack (>= 1.0, < 3)
|
88
|
+
rainbow (3.0.0)
|
89
|
+
rake (13.0.3)
|
90
|
+
rchardet (1.8.0)
|
91
|
+
rdoc (6.3.0)
|
92
|
+
redcarpet (3.5.1)
|
93
|
+
regexp_parser (2.1.1)
|
94
|
+
rexml (3.2.5)
|
95
|
+
rspec (3.10.0)
|
96
|
+
rspec-core (~> 3.10.0)
|
97
|
+
rspec-expectations (~> 3.10.0)
|
98
|
+
rspec-mocks (~> 3.10.0)
|
99
|
+
rspec-core (3.10.1)
|
100
|
+
rspec-support (~> 3.10.0)
|
101
|
+
rspec-expectations (3.10.1)
|
103
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
104
|
-
rspec-support (~> 3.
|
105
|
-
rspec-mocks (3.
|
103
|
+
rspec-support (~> 3.10.0)
|
104
|
+
rspec-mocks (3.10.2)
|
106
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
107
|
-
rspec-support (~> 3.
|
108
|
-
rspec-support (3.
|
109
|
-
rubocop (
|
110
|
-
|
111
|
-
|
112
|
-
rainbow (>=
|
106
|
+
rspec-support (~> 3.10.0)
|
107
|
+
rspec-support (3.10.2)
|
108
|
+
rubocop (1.12.1)
|
109
|
+
parallel (~> 1.10)
|
110
|
+
parser (>= 3.0.0.0)
|
111
|
+
rainbow (>= 2.2.2, < 4.0)
|
112
|
+
regexp_parser (>= 1.8, < 3.0)
|
113
|
+
rexml
|
114
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
113
115
|
ruby-progressbar (~> 1.7)
|
114
|
-
unicode-display_width (
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
simplecov
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
116
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
117
|
+
rubocop-ast (1.4.1)
|
118
|
+
parser (>= 2.7.1.5)
|
119
|
+
ruby-debug-ide (0.7.2)
|
120
|
+
rake (>= 0.8.1)
|
121
|
+
ruby-progressbar (1.11.0)
|
122
|
+
ruby2_keywords (0.0.4)
|
123
|
+
rubyzip (2.3.0)
|
124
|
+
selenium-webdriver (3.142.7)
|
125
|
+
childprocess (>= 0.5, < 4.0)
|
126
|
+
rubyzip (>= 1.2.2)
|
127
|
+
semver2 (3.4.2)
|
128
|
+
simplecov (0.21.2)
|
129
|
+
docile (~> 1.1)
|
130
|
+
simplecov-html (~> 0.11)
|
131
|
+
simplecov_json_formatter (~> 0.1)
|
132
|
+
simplecov-html (0.12.3)
|
133
|
+
simplecov_json_formatter (0.1.2)
|
134
|
+
sinatra (2.1.0)
|
135
|
+
mustermann (~> 1.0)
|
136
|
+
rack (~> 2.2)
|
137
|
+
rack-protection (= 2.1.0)
|
138
|
+
tilt (~> 2.0)
|
139
|
+
thread_safe (0.3.6)
|
140
|
+
tilt (2.0.10)
|
141
|
+
tzinfo (2.0.4)
|
142
|
+
concurrent-ruby (~> 1.0)
|
143
|
+
unicode-display_width (2.0.0)
|
144
|
+
watir (6.19.1)
|
145
|
+
regexp_parser (>= 1.2, < 3)
|
146
|
+
selenium-webdriver (>= 3.142.7)
|
147
|
+
websocket-driver (0.7.3)
|
140
148
|
websocket-extensions (>= 0.1.0)
|
141
|
-
websocket-extensions (0.1.
|
142
|
-
xpath (2.0
|
143
|
-
nokogiri (~> 1.
|
144
|
-
yard (0.9.
|
149
|
+
websocket-extensions (0.1.5)
|
150
|
+
xpath (3.2.0)
|
151
|
+
nokogiri (~> 1.8)
|
152
|
+
yard (0.9.26)
|
153
|
+
zeitwerk (2.4.2)
|
145
154
|
|
146
155
|
PLATFORMS
|
147
156
|
ruby
|
148
157
|
|
149
158
|
DEPENDENCIES
|
150
|
-
activesupport
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
github-markup (~> 1.4)
|
155
|
-
jeweler (~> 2.0)
|
159
|
+
activesupport
|
160
|
+
capybara (>= 3.0)
|
161
|
+
github-markup
|
162
|
+
jeweler
|
156
163
|
poltergeist
|
157
|
-
|
158
|
-
redcarpet (~> 3.3)
|
164
|
+
redcarpet
|
159
165
|
rspec
|
160
|
-
rubocop
|
166
|
+
rubocop
|
167
|
+
ruby-debug-ide
|
161
168
|
simplecov
|
162
169
|
sinatra
|
163
|
-
watir
|
170
|
+
watir
|
164
171
|
yard (~> 0.8)
|
165
172
|
|
166
173
|
BUNDLED WITH
|
167
|
-
1.
|
174
|
+
2.1.4
|
data/Makefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
.PHONY: help
|
2
|
+
DOCKER_IMAGE = lvl-up/page-magic
|
3
|
+
|
4
|
+
help:
|
5
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
6
|
+
|
7
|
+
build: ## build project docker image
|
8
|
+
docker build -t $(DOCKER_IMAGE) .
|
9
|
+
|
10
|
+
test: ## Run tests
|
11
|
+
docker run -v $(PWD):/usr/src/app -t $(DOCKER_IMAGE) bundle exec rspec
|
12
|
+
|
13
|
+
all: test
|
data/README.md
CHANGED
@@ -20,14 +20,34 @@ Well PageMagic might just be the answer!
|
|
20
20
|
|
21
21
|
Give it a try and let us know what you think! There will undoubtedly be things that can be improved and issues that
|
22
22
|
we are not aware of so your feedback/pull requests are greatly appreciated!
|
23
|
+
|
24
|
+
##Under the hood
|
25
|
+
Under the hood PageMagic uses the totally brilliant [Capybara](https://github.com/teamcapybara/capybara) to benefit from its amazing cross browser support.
|
26
|
+
|
27
|
+
PageMagic builds on top of Capybara to build resuable models for webpages and website structure.
|
28
|
+
|
29
|
+
##What about the other PageObject frameworks out there?
|
30
|
+
PageMagic isn't the first [PageObject](https://martinfowler.com/bliki/PageObject.html) framework to be written, indeed there are others out there that are totaly awesome e.g:
|
31
|
+
- [PageObject](https://github.com/cheezy/page-object)
|
32
|
+
- [SitePrism](https://github.com/natritmeyer/site_prism)
|
33
|
+
|
34
|
+
Whilst these APIs are great, PageMagic goes much further in the power it provides for:
|
35
|
+
- [modelling pages](defining-pages) and page components
|
36
|
+
- defining the [wait logic](#hooks) and [watchers](#watchers) that are required to build robust page objects that work reliably with javascript rich webpages.
|
37
|
+
- Supporting [page transitions](#page-mapping)
|
38
|
+
|
39
|
+
Check it out :)
|
40
|
+
|
41
|
+
|
23
42
|
# Contents
|
24
43
|
|
25
44
|
- [Installation](#installation)
|
26
45
|
- [Quick Start](#quick-start)
|
27
46
|
- [Defining Pages](#defining-pages)
|
28
47
|
- [Elements](#elements)
|
48
|
+
- [Singlular Results](#singular-results)
|
49
|
+
- [Multiple Results](#multiple-results)
|
29
50
|
- [Interacting with elements](#interacting-with-elements)
|
30
|
-
- [Multple Results](#multiple-results)
|
31
51
|
- [Sub elements](#sub-elements)
|
32
52
|
- [Custom elements](#custom-elements)
|
33
53
|
- [Hooks](#hooks)
|
@@ -95,7 +115,12 @@ class Github
|
|
95
115
|
end
|
96
116
|
```
|
97
117
|
## Elements
|
98
|
-
Defining elements is easy.
|
118
|
+
Defining elements is easy. Just give the:
|
119
|
+
- element_type
|
120
|
+
- id to refer to it by
|
121
|
+
- selector to find it in the page
|
122
|
+
|
123
|
+
The following example defines a text field called 'search_field' that can be found using its name which is 'q'
|
99
124
|
|
100
125
|
```ruby
|
101
126
|
class Github
|
@@ -105,27 +130,66 @@ class Github
|
|
105
130
|
end
|
106
131
|
```
|
107
132
|
|
108
|
-
|
109
|
-
|
110
|
-
|
133
|
+
Element types supported by PageMagic are:
|
134
|
+
- text_field
|
135
|
+
- button
|
136
|
+
- link
|
137
|
+
- checkbox
|
138
|
+
- select_list
|
139
|
+
- radio
|
140
|
+
- textarea
|
111
141
|
|
112
|
-
|
142
|
+
PageMagic is very powerful and provides a number of different ways to define a page element so for more details please look at the [API](http://www.rubydoc.info/gems/page_magic/PageMagic%2FElements:element)
|
113
143
|
|
114
|
-
|
115
|
-
|
116
|
-
```
|
144
|
+
### Singular Results
|
145
|
+
The element types written above are the method names you need to use in order to define elements of those types on your pages.
|
117
146
|
|
118
|
-
|
119
|
-
|
147
|
+
Using them as they are written above will tell PageMagic to expect to find only one element using the selector you supply. Finding more than one result will cause PageMagic to raise an `AmbiguousQueryException`
|
148
|
+
|
149
|
+
### Multiple Results
|
150
|
+
Applying an 's' to the end of the element definition method name will tell PageMagic that more than one result can be returned using the given selector.
|
151
|
+
|
152
|
+
results are returned in an `Array`.
|
120
153
|
```ruby
|
121
154
|
class ResultsPage
|
122
155
|
include PageMagic
|
123
|
-
|
156
|
+
elements :results, css: '.repo-list-item'
|
124
157
|
end
|
125
158
|
|
126
159
|
page.results #=> Array<Element>
|
127
160
|
```
|
128
161
|
|
162
|
+
|
163
|
+
### Interacting with elements
|
164
|
+
```ruby
|
165
|
+
class Github
|
166
|
+
include PageMagic
|
167
|
+
|
168
|
+
text_field :search_field, name: 'q'
|
169
|
+
end
|
170
|
+
```
|
171
|
+
Elements are defined with an id which is the name of the method you will use to reference it. In the above example,
|
172
|
+
the text field was defined with the id `:search_field`.
|
173
|
+
|
174
|
+
After visiting a page you are will get a `Session` object. Elements can be accessed through the session itself.
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
page.search_field.set 'page_magic'
|
178
|
+
```
|
179
|
+
PageMagic sits on top of [Capybara](https://github.com/teamcapybara/capybara) and ultimately returns capybara elements elements for you interact with. Interacting with the element types above is done by calling the following methods:
|
180
|
+
|
181
|
+
element | method
|
182
|
+
--- | ---
|
183
|
+
text_field | set(String)
|
184
|
+
checkbox | set(Boolean)
|
185
|
+
radio | choose(String)
|
186
|
+
link | click
|
187
|
+
text_area | set(String)
|
188
|
+
select_list | select(String)
|
189
|
+
|
190
|
+
Typically you will not need to know much about Capybara itself but there will be times when you want to interact with elements at a lower level.In this case please see Capybara's [API](http://www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Element) For more information.
|
191
|
+
|
192
|
+
|
129
193
|
### Sub Elements
|
130
194
|
If your pages are complex you can use PageMagic to compose pages, their elements and subelements to as many levels as
|
131
195
|
you need to.
|
@@ -251,13 +315,13 @@ end
|
|
251
315
|
In the above example the selector looks for an element that has a link containing text that includes that organisation.
|
252
316
|
The example uses a named parameter and is invoked as follows.
|
253
317
|
```ruby
|
254
|
-
page.results(organisation: '
|
318
|
+
page.results(organisation: 'lvlup')
|
255
319
|
```
|
256
320
|
|
257
321
|
# Starting a session
|
258
322
|
To start a PageMagic session simply decide what browser you want to use and pass it to PageMagic's `.session` method
|
259
323
|
```ruby
|
260
|
-
session = PageMagic.session(browser: :chrome, url: 'https://www.github.com)
|
324
|
+
session = PageMagic.session(browser: :chrome, url: 'https://www.github.com')
|
261
325
|
```
|
262
326
|
|
263
327
|
Your session won't do much besides navigating to the given url until you have [mapped pages](#page-mapping) to it, so
|