page_magic 1.0.0.alpha13 → 1.0.0.alpha17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/.simplecov +3 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +15 -10
- data/VERSION +1 -1
- data/lib/page_magic/drivers.rb +2 -2
- data/lib/page_magic/element/method_observer.rb +13 -0
- data/lib/page_magic/element/query.rb +38 -0
- data/lib/page_magic/element/selector.rb +40 -0
- data/lib/page_magic/element/selector_methods.rb +10 -0
- data/lib/page_magic/element.rb +65 -104
- data/lib/page_magic/element_context.rb +3 -8
- data/lib/page_magic/elements.rb +31 -31
- data/lib/page_magic/exceptions.rb +9 -0
- data/lib/page_magic/page_magic.rb +7 -8
- data/lib/page_magic/session.rb +30 -35
- data/lib/page_magic.rb +14 -20
- data/spec/element_spec.rb +53 -37
- data/spec/page_magic/driver_spec.rb +3 -4
- data/spec/page_magic/element/query_spec.rb +76 -0
- data/spec/page_magic/element/selector_spec.rb +109 -0
- data/spec/page_magic/element_context_spec.rb +5 -9
- data/spec/page_magic/elements_spec.rb +150 -147
- data/spec/page_magic/page_magic_spec.rb +51 -8
- data/spec/page_magic/session_spec.rb +69 -51
- data/spec/page_magic_spec.rb +64 -6
- data/spec/spec_helper.rb +4 -96
- data/spec/support/shared_contexts/files_context.rb +7 -0
- data/spec/support/shared_contexts/rack_application_context.rb +9 -0
- data/spec/support/shared_contexts/webapp_context.rb +37 -0
- data/spec/support/shared_contexts.rb +3 -0
- metadata +13 -8
- data/lib/ext/string.rb +0 -9
- data/spec/helpers/capybara.rb +0 -10
- data/spec/page_magic/usage/defining_pages_spec.rb +0 -81
- data/spec/page_magic/usage/include_page_magic_spec.rb +0 -18
- data/spec/page_magic/usage/interacting_with_pages_spec.rb +0 -54
- data/spec/page_magic/usage/starting_a_session_spec.rb +0 -35
data/spec/page_magic_spec.rb
CHANGED
@@ -1,6 +1,45 @@
|
|
1
1
|
require 'page_magic'
|
2
2
|
|
3
3
|
describe PageMagic do
|
4
|
+
subject do
|
5
|
+
Class.new { include PageMagic }
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.included' do
|
9
|
+
it 'gives a method for defining the url' do
|
10
|
+
subject.url :url
|
11
|
+
expect(subject.url).to eq(:url)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'lets you define elements' do
|
15
|
+
expect(subject).to be_a(PageMagic::Elements)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '.inherited' do
|
20
|
+
let(:parent_page) do
|
21
|
+
Class.new do
|
22
|
+
include PageMagic
|
23
|
+
link(:next, text: 'next page')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let(:child_page) do
|
28
|
+
Class.new(parent_page)
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'children' do
|
32
|
+
it 'should inherit elements defined on the parent class' do
|
33
|
+
expect(child_page.element_definitions).to include(:next)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should pass on element definitions to their children' do
|
37
|
+
grand_child_class = Class.new(child_page)
|
38
|
+
expect(grand_child_class.element_definitions).to include(:next)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
4
43
|
describe '::drivers' do
|
5
44
|
it 'returns loaded drivers' do
|
6
45
|
expected_drivers = described_class::Drivers.new.tap(&:load)
|
@@ -10,24 +49,42 @@ describe PageMagic do
|
|
10
49
|
end
|
11
50
|
|
12
51
|
describe '::session' do
|
52
|
+
let(:url) { 'http://url.com/' }
|
53
|
+
let(:application) { rack_application.new }
|
54
|
+
|
55
|
+
before do
|
56
|
+
allow_any_instance_of(Capybara::Selenium::Driver).to receive(:visit)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "defaults to capybara's default session " do
|
60
|
+
Capybara.default_driver = :rack_test
|
61
|
+
expect(subject.new.browser.mode).to eq(:rack_test)
|
62
|
+
end
|
63
|
+
|
13
64
|
context 'specifying the browser' do
|
14
65
|
it 'loads the correct driver' do
|
15
|
-
session = described_class.session(browser: :firefox)
|
16
|
-
session.raw_session.driver.
|
66
|
+
session = described_class.session(application: rack_application.new, browser: :firefox, url: :url)
|
67
|
+
expect(session.raw_session.driver).to be_a(Capybara::Selenium::Driver)
|
17
68
|
end
|
18
69
|
end
|
19
70
|
|
71
|
+
include_context :rack_application
|
72
|
+
it 'sets the base url for the session' do
|
73
|
+
session = described_class.session(application: application, url: url)
|
74
|
+
expect(session.current_url).to eq(url)
|
75
|
+
end
|
76
|
+
|
20
77
|
context 'specifying a rack application' do
|
21
78
|
it 'configures capybara to run against the app' do
|
22
|
-
session = described_class.session(application: :
|
23
|
-
expect(session.raw_session.app).to be(
|
79
|
+
session = described_class.session(application: application, url: url)
|
80
|
+
expect(session.raw_session.app).to be(application)
|
24
81
|
end
|
25
82
|
end
|
26
83
|
|
27
84
|
context 'specifying options' do
|
28
85
|
it 'passes the options to the browser driver' do
|
29
86
|
options = { option: :config }
|
30
|
-
session = described_class.session(options: options, browser: :chrome)
|
87
|
+
session = described_class.session(options: options, browser: :chrome, url: url)
|
31
88
|
|
32
89
|
expect(session.raw_session.driver.options).to include(options)
|
33
90
|
end
|
@@ -35,7 +92,8 @@ describe PageMagic do
|
|
35
92
|
|
36
93
|
context 'driver for browser not found' do
|
37
94
|
it 'raises an error' do
|
38
|
-
|
95
|
+
expected_exception = described_class::UnspportedBrowserException
|
96
|
+
expect { described_class.session(browser: :invalid, url: url) }.to raise_exception expected_exception
|
39
97
|
end
|
40
98
|
end
|
41
99
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,99 +1,7 @@
|
|
1
1
|
Bundler.require
|
2
|
-
$LOAD_PATH.unshift("#{
|
3
|
-
if ENV['coverage']
|
4
|
-
require 'simplecov'
|
5
|
-
SimpleCov.start do
|
6
|
-
add_filter '/spec/'
|
7
|
-
end
|
8
|
-
end
|
9
|
-
require 'page_magic'
|
10
|
-
require 'capybara/rspec'
|
11
|
-
require 'helpers/capybara'
|
12
|
-
|
13
|
-
shared_context :files do
|
14
|
-
require 'tmpdir'
|
15
|
-
|
16
|
-
def scratch_dir
|
17
|
-
@dir ||= Dir.mktmpdir
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
shared_context :rack_application do
|
22
|
-
let(:rack_application) do
|
23
|
-
Class.new do
|
24
|
-
def call(_env)
|
25
|
-
[200, {}, ['hello world!!']]
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
RSpec.configure do
|
32
|
-
module PageMagic
|
33
|
-
class Element
|
34
|
-
class << self
|
35
|
-
def default_before_hook
|
36
|
-
@default_before_hook ||= proc {}
|
37
|
-
end
|
38
|
-
|
39
|
-
def default_after_hook
|
40
|
-
@default_after_hook ||= proc {}
|
41
|
-
end
|
42
|
-
end
|
43
|
-
alias_method :initialize_backup, :initialize
|
44
|
-
|
45
|
-
def initialize(*args, &block)
|
46
|
-
initialize_backup *args, &block
|
47
|
-
# @before_hook = self.class.default_before_hook
|
48
|
-
# @after_hook = self.class.default_after_hook
|
49
|
-
end
|
50
|
-
|
51
|
-
def ==(page_element)
|
52
|
-
page_element.is_a?(Element) &&
|
53
|
-
@type == page_element.type &&
|
54
|
-
@name == page_element.name &&
|
55
|
-
@selector == page_element.selector
|
56
|
-
# @before_hook == page_element.before &&
|
57
|
-
# @after_hook == page_element.after
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
2
|
+
$LOAD_PATH.unshift(__dir__, "#{__dir__}/../lib")
|
61
3
|
|
62
|
-
|
63
|
-
|
4
|
+
require 'support/shared_contexts'
|
5
|
+
require 'simplecov' if ENV['coverage']
|
64
6
|
|
65
|
-
|
66
|
-
get '/page1' do
|
67
|
-
"<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
|
68
|
-
end
|
69
|
-
|
70
|
-
get '/page2' do
|
71
|
-
'page 2 content'
|
72
|
-
end
|
73
|
-
|
74
|
-
get '/elements' do
|
75
|
-
<<-ELEMENTS
|
76
|
-
<a href='#'>a link</a>
|
77
|
-
|
78
|
-
|
79
|
-
<div id='form' class="form">
|
80
|
-
<a id='form_link' href='/page2'>link in a form</a>
|
81
|
-
<label>enter text
|
82
|
-
<input id='field_id' name='field_name' class='input_class' type='text' value='filled in'/>
|
83
|
-
</label>
|
84
|
-
<input id='form_button' type='submit' value='a button'/>
|
85
|
-
</form>
|
86
|
-
|
87
|
-
ELEMENTS
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
before :each do
|
92
|
-
Capybara.app = rack_app
|
93
|
-
end
|
94
|
-
|
95
|
-
after do
|
96
|
-
Capybara.reset!
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
7
|
+
require 'page_magic'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_context :webapp_fixture do
|
2
|
+
require 'sinatra/base'
|
3
|
+
|
4
|
+
rack_app = Class.new(Sinatra::Base) do
|
5
|
+
get '/page1' do
|
6
|
+
"<html><head><title>page1</title></head><body><a href='/page2'>next page</a></body></html>"
|
7
|
+
end
|
8
|
+
|
9
|
+
get '/page2' do
|
10
|
+
'page 2 content'
|
11
|
+
end
|
12
|
+
|
13
|
+
get '/elements' do
|
14
|
+
<<-ELEMENTS
|
15
|
+
<a href='#'>a link</a>
|
16
|
+
|
17
|
+
|
18
|
+
<div id='form' class="form">
|
19
|
+
<a id='form_link' href='/page2'>link in a form</a>
|
20
|
+
<label>enter text
|
21
|
+
<input id='field_id' name='field_name' class='input_class' type='text' value='filled in'/>
|
22
|
+
</label>
|
23
|
+
<input id='form_button' type='submit' value='a button'/>
|
24
|
+
</form>
|
25
|
+
|
26
|
+
ELEMENTS
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
before :each do
|
31
|
+
Capybara.app = rack_app
|
32
|
+
end
|
33
|
+
|
34
|
+
after do
|
35
|
+
Capybara.reset!
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: page_magic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Leon Davis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -91,12 +91,12 @@ files:
|
|
91
91
|
- ".rubocop.yml"
|
92
92
|
- ".ruby-gemset"
|
93
93
|
- ".ruby-version"
|
94
|
+
- ".simplecov"
|
94
95
|
- Gemfile
|
95
96
|
- Gemfile.lock
|
96
97
|
- README.md
|
97
98
|
- Rakefile
|
98
99
|
- VERSION
|
99
|
-
- lib/ext/string.rb
|
100
100
|
- lib/page_magic.rb
|
101
101
|
- lib/page_magic/driver.rb
|
102
102
|
- lib/page_magic/drivers.rb
|
@@ -104,6 +104,10 @@ files:
|
|
104
104
|
- lib/page_magic/drivers/rack_test.rb
|
105
105
|
- lib/page_magic/drivers/selenium.rb
|
106
106
|
- lib/page_magic/element.rb
|
107
|
+
- lib/page_magic/element/method_observer.rb
|
108
|
+
- lib/page_magic/element/query.rb
|
109
|
+
- lib/page_magic/element/selector.rb
|
110
|
+
- lib/page_magic/element/selector_methods.rb
|
107
111
|
- lib/page_magic/element_context.rb
|
108
112
|
- lib/page_magic/elements.rb
|
109
113
|
- lib/page_magic/exceptions.rb
|
@@ -111,23 +115,24 @@ files:
|
|
111
115
|
- lib/page_magic/session.rb
|
112
116
|
- page_magic.gemspec
|
113
117
|
- spec/element_spec.rb
|
114
|
-
- spec/helpers/capybara.rb
|
115
118
|
- spec/member_methods_spec.rb
|
116
119
|
- spec/page_magic/driver_spec.rb
|
117
120
|
- spec/page_magic/drivers/poltergeist_spec.rb
|
118
121
|
- spec/page_magic/drivers/rack_test_spec.rb
|
119
122
|
- spec/page_magic/drivers/selenium_spec.rb
|
120
123
|
- spec/page_magic/drivers_spec.rb
|
124
|
+
- spec/page_magic/element/query_spec.rb
|
125
|
+
- spec/page_magic/element/selector_spec.rb
|
121
126
|
- spec/page_magic/element_context_spec.rb
|
122
127
|
- spec/page_magic/elements_spec.rb
|
123
128
|
- spec/page_magic/page_magic_spec.rb
|
124
129
|
- spec/page_magic/session_spec.rb
|
125
|
-
- spec/page_magic/usage/defining_pages_spec.rb
|
126
|
-
- spec/page_magic/usage/include_page_magic_spec.rb
|
127
|
-
- spec/page_magic/usage/interacting_with_pages_spec.rb
|
128
|
-
- spec/page_magic/usage/starting_a_session_spec.rb
|
129
130
|
- spec/page_magic_spec.rb
|
130
131
|
- spec/spec_helper.rb
|
132
|
+
- spec/support/shared_contexts.rb
|
133
|
+
- spec/support/shared_contexts/files_context.rb
|
134
|
+
- spec/support/shared_contexts/rack_application_context.rb
|
135
|
+
- spec/support/shared_contexts/webapp_context.rb
|
131
136
|
homepage: https://github.com/ladtech/page_magic
|
132
137
|
licenses:
|
133
138
|
- ruby
|
data/lib/ext/string.rb
DELETED
data/spec/helpers/capybara.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
describe 'The Elements of a Page' do
|
2
|
-
describe 'instances' do
|
3
|
-
include_context :webapp
|
4
|
-
|
5
|
-
let(:my_page_class) do
|
6
|
-
Class.new do
|
7
|
-
include PageMagic
|
8
|
-
url '/page1'
|
9
|
-
link(:next, text: 'next page')
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
let(:another_page_class) do
|
14
|
-
Class.new do
|
15
|
-
include PageMagic
|
16
|
-
url '/another_page1'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
before :each do
|
21
|
-
@page = my_page_class.new
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'browser integration' do
|
25
|
-
it "should use capybara's default session if a one is not supplied" do
|
26
|
-
Capybara.default_driver = :rack_test
|
27
|
-
my_page_class.new.browser.mode.should == :rack_test
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'should copy fields on to element' do
|
32
|
-
new_page = my_page_class.new
|
33
|
-
@page.element_definitions[:next].call(@page).should_not equal(new_page.element_definitions[:next].call(new_page))
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'gives access to the page text' do
|
37
|
-
@page.visit.text.should == 'next page'
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should access a field' do
|
41
|
-
@page.visit
|
42
|
-
@page.next.click
|
43
|
-
@page.text.should == 'page 2 content'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'are registered at class level' do
|
47
|
-
PageMagic.instance_variable_set(:@pages, nil)
|
48
|
-
|
49
|
-
page = Class.new { include PageMagic }
|
50
|
-
PageMagic.pages.should == [page]
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'inheritance' do
|
55
|
-
let(:parent_page) do
|
56
|
-
Class.new do
|
57
|
-
include PageMagic
|
58
|
-
link(:next, text: 'next page')
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
let(:child_page) do
|
63
|
-
Class.new(parent_page)
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'children' do
|
67
|
-
it 'should inherit elements defined on the parent class' do
|
68
|
-
child_page.element_definitions.should include(:next)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'are added to PageMagic.pages list' do
|
72
|
-
PageMagic.pages.should include(child_page)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'should pass on element definitions to their children' do
|
76
|
-
grand_child_class = Class.new(child_page)
|
77
|
-
grand_child_class.element_definitions.should include(:next)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
describe 'including PageMagic' do
|
2
|
-
include Capybara::DSL
|
3
|
-
|
4
|
-
context 'lets you define pages' do
|
5
|
-
let :page_class do
|
6
|
-
Class.new { include PageMagic }
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'gives a method for defining the url' do
|
10
|
-
page_class.url :url
|
11
|
-
page_class.url.should == :url
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'lets you define elements' do
|
15
|
-
page_class.is_a?(PageMagic::Elements).should be_true
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
describe 'interacting with pages' do
|
2
|
-
include_context :webapp
|
3
|
-
|
4
|
-
let :page do
|
5
|
-
Class.new do
|
6
|
-
include PageMagic
|
7
|
-
link(:next_page, text: 'next page')
|
8
|
-
url '/page1'
|
9
|
-
end.new
|
10
|
-
end
|
11
|
-
|
12
|
-
before(:each) { page.visit }
|
13
|
-
|
14
|
-
describe 'visit' do
|
15
|
-
it 'goes to the class define url' do
|
16
|
-
page.visit
|
17
|
-
page.session.current_path.should == '/page1'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'session' do
|
22
|
-
it 'gives access to the page magic object wrapping the user session' do
|
23
|
-
page.session.raw_session.should == Capybara.current_session
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe 'text_on_page?' do
|
28
|
-
it 'returns true if the text is present' do
|
29
|
-
page.text_on_page?('next page').should be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'returns false if the text is not present' do
|
33
|
-
page.text_on_page?('not on page').should be_false
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe 'title' do
|
38
|
-
it 'returns the title' do
|
39
|
-
page.title.should == 'page1'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
describe 'text' do
|
44
|
-
it 'returns the text on the page' do
|
45
|
-
page.text.should == 'next page'
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe 'method_missing' do
|
50
|
-
it 'gives access to the elements defined on your page classes' do
|
51
|
-
page.next_page.tag_name.should == 'a'
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
describe 'PageMagic.session' do
|
2
|
-
let(:app_class) do
|
3
|
-
Class.new do
|
4
|
-
def call(_env)
|
5
|
-
[200, {}, ['hello world!!']]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def registered_driver(browser)
|
11
|
-
Capybara.drivers[browser].call(nil)
|
12
|
-
end
|
13
|
-
|
14
|
-
context 'specificying a browser' do
|
15
|
-
it 'loads the driver for the specified browser' do
|
16
|
-
session = PageMagic.session(browser: :firefox)
|
17
|
-
session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'testing against rack applications' do
|
22
|
-
it 'requires the app to be supplied' do
|
23
|
-
session = PageMagic.session(application: app_class.new)
|
24
|
-
session.raw_session.visit('/')
|
25
|
-
session.raw_session.text.should == 'hello world!!'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'can run against an rack application using a particular browser' do
|
29
|
-
session = PageMagic.session(browser: :rack_test, application: app_class.new)
|
30
|
-
session.raw_session.mode.should == :rack_test
|
31
|
-
session.raw_session.visit('/')
|
32
|
-
session.raw_session.text.should == 'hello world!!'
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|