page_magic 0.11.0.alpha7 → 0.11.0.alpha8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/VERSION +1 -1
- data/lib/page_magic/element_context.rb +2 -6
- data/lib/page_magic/session.rb +32 -13
- data/spec/page_magic/element_context_spec.rb +28 -11
- data/spec/page_magic/session_spec.rb +65 -31
- metadata +1 -2
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b3b5bae4a08579ffe198524fb160791d40c75d0
|
4
|
+
data.tar.gz: cfbcade44965019d6614dbd8a397cb717d0d608b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9802999ea9cafdbe9c1104784047ae65734cfc5bef00f6da87b0da30c4b143c3add0e5cd0be4fd1e1655ce39290ce3884d53816e61c2c3f979fdad9a47312bc2
|
7
|
+
data.tar.gz: 1382773ba5e71d48604da93565ff477eaf3bdc901a1735ad6eca8859bb968bcc9b67704c81c53a7398cc28794200786c63714222bfd9282ec6603131e934d9d6
|
data/README.md
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
#PageMagic
|
1
|
+
#PageMagic
|
3
2
|
PageMagic is an API for testing web applications.
|
4
3
|
|
5
4
|
It has a simple but powerful DSL which makes modelling and interacting with your pages easy.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.11.0.
|
1
|
+
0.11.0.alpha8
|
@@ -28,19 +28,15 @@ module PageMagic
|
|
28
28
|
element_locator = element_locator_factory.call(@page_element, *args)
|
29
29
|
end
|
30
30
|
|
31
|
-
result = element_locator.browser_element
|
32
|
-
|
33
|
-
return element_locator if element_locator.section?
|
34
|
-
|
35
31
|
[:set, :select_option, :unselect_option, :click].each do |action_method|
|
36
|
-
apply_hooks(page_element:
|
32
|
+
apply_hooks(page_element: element_locator.browser_element,
|
37
33
|
capybara_method: action_method,
|
38
34
|
before_hook: element_locator.before,
|
39
35
|
after_hook: element_locator.after,
|
40
36
|
)
|
41
37
|
end
|
42
38
|
|
43
|
-
|
39
|
+
element_locator.section? ? element_locator : element_locator.browser_element
|
44
40
|
end
|
45
41
|
|
46
42
|
def apply_hooks(options)
|
data/lib/page_magic/session.rb
CHANGED
@@ -1,34 +1,53 @@
|
|
1
1
|
require 'wait'
|
2
2
|
module PageMagic
|
3
3
|
class Session
|
4
|
-
attr_accessor :current_page, :raw_session
|
4
|
+
attr_accessor :current_page, :raw_session, :transitions
|
5
5
|
|
6
6
|
def initialize browser
|
7
7
|
@raw_session = browser
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def define_page_mappings transitions
|
11
11
|
@transitions = transitions
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
14
|
+
def current_page
|
15
|
+
if transitions
|
16
|
+
mapping = find_mapped_page(current_path)
|
17
|
+
@current_page = mapping.new(self) if mapping
|
18
|
+
end
|
19
|
+
@current_page
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_mapped_page path
|
23
|
+
mapping = transitions.keys.find do |key|
|
24
|
+
string_matches?(path, key)
|
25
|
+
end
|
26
|
+
transitions[mapping]
|
27
|
+
end
|
28
|
+
|
29
|
+
def string_matches?(string, matcher)
|
30
|
+
if matcher.is_a?(Regexp)
|
31
|
+
string =~ matcher
|
32
|
+
elsif matcher.is_a?(String)
|
33
|
+
string == matcher
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def visit(page, url: nil)
|
40
|
+
raw_session.visit url || page.url
|
16
41
|
@current_page = page.new self
|
17
42
|
self
|
18
43
|
end
|
19
44
|
|
20
45
|
def current_path
|
21
|
-
|
46
|
+
raw_session.current_path
|
22
47
|
end
|
23
48
|
|
24
49
|
def current_url
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
def move_to page_class
|
29
|
-
page_class = eval(page_class) if page_class.is_a?(String)
|
30
|
-
@current_page = page_class.new self
|
31
|
-
wait_until { raw_session.current_url == page_class.url }
|
50
|
+
raw_session.current_url
|
32
51
|
end
|
33
52
|
|
34
53
|
def wait_until &block
|
@@ -37,7 +56,7 @@ module PageMagic
|
|
37
56
|
end
|
38
57
|
|
39
58
|
def method_missing name, *args, &block
|
40
|
-
|
59
|
+
current_page.send(name, *args, &block)
|
41
60
|
end
|
42
61
|
|
43
62
|
end
|
@@ -87,23 +87,40 @@ describe PageMagic::ElementContext do
|
|
87
87
|
|
88
88
|
describe 'hooks' do
|
89
89
|
|
90
|
+
subject(:page) do
|
91
|
+
elements_page.new.tap do|p|
|
92
|
+
p.visit
|
93
|
+
end
|
94
|
+
end
|
90
95
|
|
91
|
-
|
92
|
-
# page = elements_page.new
|
93
|
-
#end
|
94
|
-
|
95
|
-
it 'should execute a before and after action that gives access to the browser' do
|
96
|
-
|
97
|
-
page = elements_page.new
|
98
|
-
page.visit
|
99
|
-
|
100
|
-
selector = {text: 'a link'}
|
96
|
+
before do
|
101
97
|
browser = page.browser
|
102
98
|
browser.should_receive(:call_in_before_hook)
|
103
99
|
browser.should_receive(:call_in_after_before_hook)
|
100
|
+
end
|
104
101
|
|
105
102
|
|
106
|
-
|
103
|
+
context 'section' do
|
104
|
+
it 'applies the hooks' do
|
105
|
+
|
106
|
+
elements_page.section(:form, id: 'form') do
|
107
|
+
link :form_link, id: 'form_link'
|
108
|
+
|
109
|
+
before do |page_browser|
|
110
|
+
page_browser.call_in_before_hook
|
111
|
+
end
|
112
|
+
|
113
|
+
after do |page_browser|
|
114
|
+
page_browser.call_in_after_before_hook
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
described_class.new(page, page.browser, self).form.click
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
it 'should execute a before and after action that gives access to the browser' do
|
123
|
+
elements_page.link(:create, text: 'a link') do
|
107
124
|
before do |page_browser|
|
108
125
|
page_browser.call_in_before_hook
|
109
126
|
end
|
@@ -3,7 +3,7 @@ describe PageMagic::Session do
|
|
3
3
|
let(:page) do
|
4
4
|
Class.new do
|
5
5
|
include PageMagic
|
6
|
-
url
|
6
|
+
url '/page1'
|
7
7
|
|
8
8
|
def my_method
|
9
9
|
:called
|
@@ -20,48 +20,82 @@ describe PageMagic::Session do
|
|
20
20
|
|
21
21
|
let(:browser) { double('browser', current_url: 'url') }
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
describe '#current_page' do
|
24
|
+
subject do
|
25
|
+
PageMagic::Session.new(browser).tap do |session|
|
26
|
+
session.define_page_mappings '/another_page1' => another_page_class
|
27
|
+
end
|
28
|
+
end
|
29
|
+
context 'page url has not changed' do
|
30
|
+
it 'returns the original page' do
|
31
|
+
browser.should_receive(:visit).with(page.url)
|
32
|
+
allow(browser).to receive(:current_path).and_return('/page1')
|
33
|
+
subject.visit(page)
|
34
|
+
expect(subject.current_page).to be_an_instance_of(page)
|
35
|
+
end
|
36
|
+
end
|
28
37
|
|
29
|
-
|
30
|
-
|
31
|
-
|
38
|
+
context 'page url has changed' do
|
39
|
+
it 'returns the mapped page object' do
|
40
|
+
browser.should_receive(:visit).with(page.url)
|
41
|
+
subject.visit(page)
|
42
|
+
allow(browser).to receive(:current_path).and_return('/another_page1')
|
43
|
+
expect(subject.current_page).to be_an_instance_of(another_page_class)
|
44
|
+
end
|
45
|
+
end
|
32
46
|
end
|
33
47
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
48
|
+
describe '#find_mapped_page' do
|
49
|
+
subject do
|
50
|
+
described_class.new(nil).tap do |session|
|
51
|
+
session.define_page_mappings '/page' => :mapped_page_using_string, /page\d/ => :mapped_page_using_regex
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'mapping is string' do
|
56
|
+
it 'returns the page class' do
|
57
|
+
expect(subject.find_mapped_page('/page')).to be(:mapped_page_using_string)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
context 'mapping is regex' do
|
61
|
+
it 'returns the page class' do
|
62
|
+
expect(subject.find_mapped_page('/page2')).to be(:mapped_page_using_regex)
|
63
|
+
end
|
39
64
|
end
|
40
|
-
end
|
41
65
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
page_magic_session.current_page.should be_a(another_page_class)
|
66
|
+
context 'mapping is not found' do
|
67
|
+
it 'returns nil' do
|
68
|
+
expect(subject.find_mapped_page('/fake_page')).to be(nil)
|
69
|
+
end
|
47
70
|
end
|
71
|
+
end
|
48
72
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
73
|
+
describe '#visit' do
|
74
|
+
context 'url supplied' do
|
75
|
+
it 'uses this url instead of the one defined on the page class' do
|
76
|
+
expect(browser).to receive(:visit).with(:custom_url)
|
77
|
+
session = PageMagic::Session.new(browser).visit(page, url: :custom_url)
|
78
|
+
session.current_page.should be_a(page)
|
53
79
|
end
|
80
|
+
end
|
54
81
|
|
55
|
-
|
56
|
-
|
57
|
-
|
82
|
+
it 'visits the url on defined on the page class' do
|
83
|
+
browser.should_receive(:visit).with(page.url)
|
84
|
+
session = PageMagic::Session.new(browser).visit(page)
|
85
|
+
session.current_page.should be_a(page)
|
58
86
|
end
|
87
|
+
end
|
59
88
|
|
60
|
-
|
61
|
-
|
62
|
-
|
89
|
+
it 'should return the current url' do
|
90
|
+
session = PageMagic::Session.new(browser)
|
91
|
+
session.current_url.should == 'url'
|
92
|
+
end
|
63
93
|
|
64
|
-
|
94
|
+
context 'method_missing' do
|
95
|
+
it 'should delegate to current page' do
|
96
|
+
browser.stub(:visit)
|
97
|
+
session = PageMagic::Session.new(browser).visit(page)
|
98
|
+
session.my_method.should be(:called)
|
65
99
|
end
|
66
100
|
end
|
67
101
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.0.
|
4
|
+
version: 0.11.0.alpha8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Davis
|
@@ -104,7 +104,6 @@ files:
|
|
104
104
|
- ".rspec"
|
105
105
|
- ".ruby-gemset"
|
106
106
|
- ".ruby-version"
|
107
|
-
- ".travis.yml"
|
108
107
|
- Gemfile
|
109
108
|
- Gemfile.lock
|
110
109
|
- Guardfile
|
data/.travis.yml
DELETED