page_magic 0.11.0.alpha6 → 0.11.0.alpha7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +12 -0
- data/VERSION +1 -1
- data/lib/page_magic/driver.rb +19 -0
- data/lib/page_magic/drivers/poltergeist.rb +9 -0
- data/lib/page_magic/drivers/rack_test.rb +7 -0
- data/lib/page_magic/drivers/selenium.rb +8 -0
- data/lib/page_magic/drivers.rb +31 -0
- data/lib/page_magic/session.rb +12 -31
- data/lib/page_magic.rb +19 -28
- data/page_magic.gemspec +6 -6
- data/spec/page_magic/driver_spec.rb +47 -0
- data/spec/page_magic/drivers/poltergeist_spec.rb +10 -0
- data/spec/page_magic/drivers/rack_test_spec.rb +10 -0
- data/spec/page_magic/drivers/selenium_spec.rb +10 -0
- data/spec/page_magic/drivers_spec.rb +41 -0
- data/spec/page_magic/session_spec.rb +27 -51
- data/spec/page_magic/usage/starting_a_session_spec.rb +6 -30
- data/spec/page_magic_spec.rb +44 -0
- data/spec/spec_helper.rb +15 -0
- metadata +68 -17
- data/lib/page_magic/browser.rb +0 -19
- data/spec/page_magic/browser_spec.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aea679cbb291387aa604e03d5d0e3cb5adf28141
|
4
|
+
data.tar.gz: 52fde80f96207b3632b89fbd98d4cb16e083ffb8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67be00ed38102cf53891a69fb815042020cbe51e6f8a5d82c83ca0a0041ddbe688b69061174a2ab00946410648a13202320abcc48a3311019b2019b6871c48d
|
7
|
+
data.tar.gz: 13b0e6b736234d5f48d6669b3b39a75f6c32e869c3710ec4efdffe0dde5a543bb117bdb5384b56542961416a06d8aeb977239d5bc45d7ce0cebda3f9212c927e
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,6 +1,12 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activesupport (4.2.3)
|
5
|
+
i18n (~> 0.7)
|
6
|
+
json (~> 1.7, >= 1.7.7)
|
7
|
+
minitest (~> 5.1)
|
8
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
9
|
+
tzinfo (~> 1.1)
|
4
10
|
addressable (2.3.6)
|
5
11
|
builder (3.2.2)
|
6
12
|
capybara (2.1.0)
|
@@ -38,6 +44,7 @@ GEM
|
|
38
44
|
guard (~> 2.0)
|
39
45
|
hashie (2.0.5)
|
40
46
|
highline (1.6.21)
|
47
|
+
i18n (0.7.0)
|
41
48
|
jeweler (2.0.1)
|
42
49
|
builder
|
43
50
|
bundler (>= 1.0)
|
@@ -58,6 +65,7 @@ GEM
|
|
58
65
|
method_source (0.8.2)
|
59
66
|
mime-types (1.25)
|
60
67
|
mini_portile (0.5.1)
|
68
|
+
minitest (5.7.0)
|
61
69
|
multi_json (1.7.3)
|
62
70
|
multi_xml (0.5.5)
|
63
71
|
multipart-post (1.2.0)
|
@@ -113,8 +121,11 @@ GEM
|
|
113
121
|
tilt (~> 1.3, >= 1.3.4)
|
114
122
|
slop (3.5.0)
|
115
123
|
thor (0.19.1)
|
124
|
+
thread_safe (0.3.5)
|
116
125
|
tilt (1.4.1)
|
117
126
|
timers (1.1.0)
|
127
|
+
tzinfo (1.2.2)
|
128
|
+
thread_safe (~> 0.1)
|
118
129
|
wait (0.5.1)
|
119
130
|
watir-webdriver (0.6.4)
|
120
131
|
selenium-webdriver (>= 2.18.0)
|
@@ -127,6 +138,7 @@ PLATFORMS
|
|
127
138
|
ruby
|
128
139
|
|
129
140
|
DEPENDENCIES
|
141
|
+
activesupport
|
130
142
|
capybara
|
131
143
|
guard
|
132
144
|
guard-ctags-bundler
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
0.11.0.alpha7
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PageMagic
|
2
|
+
class Driver
|
3
|
+
attr_reader :supported_browsers, :handler
|
4
|
+
def initialize(*supported_browsers, &block)
|
5
|
+
@handler = block
|
6
|
+
@supported_browsers = supported_browsers
|
7
|
+
end
|
8
|
+
|
9
|
+
def support? browser
|
10
|
+
supported_browsers.include?(browser)
|
11
|
+
end
|
12
|
+
|
13
|
+
def build(app, browser:, options:{})
|
14
|
+
options[:browser] = browser
|
15
|
+
driver_clazz = handler.call
|
16
|
+
driver_clazz.new(app, options)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'page_magic/driver'
|
2
|
+
module PageMagic
|
3
|
+
class Drivers
|
4
|
+
def all
|
5
|
+
@all ||=[]
|
6
|
+
end
|
7
|
+
|
8
|
+
def register(driver)
|
9
|
+
all << driver
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def find browser
|
14
|
+
all.find{|driver|driver.support?(browser)}
|
15
|
+
end
|
16
|
+
|
17
|
+
def load path="#{__dir__}/drivers"
|
18
|
+
require 'active_support/inflector'
|
19
|
+
|
20
|
+
Dir["#{path}/*.rb"].each do |driver_file|
|
21
|
+
require driver_file
|
22
|
+
driver_name = File.basename(driver_file)[/(.*)\.rb$/, 1]
|
23
|
+
register eval(driver_name.classify)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def == other
|
28
|
+
other.is_a?(Drivers) && other.all == other.all
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/page_magic/session.rb
CHANGED
@@ -1,53 +1,34 @@
|
|
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
|
5
5
|
|
6
6
|
def initialize browser
|
7
7
|
@raw_session = browser
|
8
8
|
end
|
9
9
|
|
10
|
-
def
|
10
|
+
def define_transitions transitions
|
11
11
|
@transitions = transitions
|
12
12
|
end
|
13
13
|
|
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
14
|
def visit page
|
40
|
-
raw_session.visit page.url
|
15
|
+
@raw_session.visit page.url
|
41
16
|
@current_page = page.new self
|
42
17
|
self
|
43
18
|
end
|
44
19
|
|
45
20
|
def current_path
|
46
|
-
raw_session.current_path
|
21
|
+
@raw_session.current_path
|
47
22
|
end
|
48
23
|
|
49
24
|
def current_url
|
50
|
-
raw_session.current_url
|
25
|
+
@raw_session.current_url
|
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 }
|
51
32
|
end
|
52
33
|
|
53
34
|
def wait_until &block
|
@@ -56,7 +37,7 @@ module PageMagic
|
|
56
37
|
end
|
57
38
|
|
58
39
|
def method_missing name, *args, &block
|
59
|
-
current_page.send(name, *args, &block)
|
40
|
+
@current_page.send(name, *args, &block)
|
60
41
|
end
|
61
42
|
|
62
43
|
end
|
data/lib/page_magic.rb
CHANGED
@@ -1,41 +1,33 @@
|
|
1
1
|
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
2
|
require 'capybara'
|
3
3
|
require 'page_magic/exceptions'
|
4
|
-
require 'page_magic/browser'
|
5
4
|
require 'page_magic/session'
|
6
5
|
require 'page_magic/elements'
|
7
6
|
require 'page_magic/element_context'
|
8
7
|
require 'page_magic/element'
|
9
8
|
require 'page_magic/page_magic'
|
9
|
+
require 'page_magic/drivers'
|
10
10
|
|
11
11
|
module PageMagic
|
12
|
+
class UnspportedBrowserException < Exception;end
|
13
|
+
|
12
14
|
class << self
|
13
|
-
def session browser=nil, options = {}
|
14
|
-
if browser.is_a?(Symbol)
|
15
|
-
application = options.delete(:application)
|
16
|
-
|
17
|
-
Capybara.register_driver browser do |app|
|
18
|
-
options[:browser] = browser
|
19
|
-
case browser
|
20
|
-
when :poltergeist
|
21
|
-
require 'capybara/poltergeist'
|
22
|
-
Capybara::Poltergeist::Driver.new(app)
|
23
|
-
when :rack_test
|
24
|
-
Capybara::RackTest::Driver.new(app, options)
|
25
|
-
else
|
26
|
-
require 'watir-webdriver'
|
27
|
-
Capybara::Selenium::Driver.new(app, options)
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
Session.new(Capybara::Session.new(browser, application))
|
33
|
-
else
|
34
|
-
Capybara.reset!
|
35
|
-
Capybara.app = browser[:application] if browser.is_a?(Hash) && browser[:application]
|
36
|
-
Session.new(Capybara.current_session)
|
37
|
-
end
|
38
15
|
|
16
|
+
def drivers
|
17
|
+
@drivers ||= Drivers.new.tap do |drivers|
|
18
|
+
drivers.load
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def session(application: nil, browser: :rack_test, options: {})
|
23
|
+
driver = drivers.find(browser)
|
24
|
+
raise UnspportedBrowserException unless driver
|
25
|
+
|
26
|
+
Capybara.register_driver browser do |app|
|
27
|
+
driver.build(app, browser: browser, options: options)
|
28
|
+
end
|
29
|
+
|
30
|
+
Session.new(Capybara::Session.new(browser, application))
|
39
31
|
end
|
40
32
|
|
41
33
|
def included clazz
|
@@ -53,11 +45,10 @@ module PageMagic
|
|
53
45
|
PageMagic.pages << clazz
|
54
46
|
end
|
55
47
|
end
|
56
|
-
|
57
48
|
end
|
58
49
|
|
59
50
|
def pages
|
60
51
|
@pages||=[]
|
61
52
|
end
|
62
53
|
end
|
63
|
-
end
|
54
|
+
end
|
data/page_magic.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "page_magic"
|
8
|
-
s.version = "0.11.0.
|
8
|
+
s.version = "0.11.0.alpha3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leon Davis"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2014-04-05"
|
13
13
|
s.description = "Framework for modeling and interacting with webpages which wraps capybara"
|
14
14
|
s.email = "info@lad-tech.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -22,12 +22,12 @@ Gem::Specification.new do |s|
|
|
22
22
|
".travis.yml",
|
23
23
|
"Gemfile",
|
24
24
|
"Gemfile.lock",
|
25
|
-
"Guardfile",
|
26
25
|
"README.md",
|
27
26
|
"Rakefile",
|
28
27
|
"VERSION",
|
29
28
|
"lib/ext/string.rb",
|
30
29
|
"lib/page_magic.rb",
|
30
|
+
"lib/page_magic/ajax_support.rb",
|
31
31
|
"lib/page_magic/browser.rb",
|
32
32
|
"lib/page_magic/element.rb",
|
33
33
|
"lib/page_magic/element_context.rb",
|
@@ -36,18 +36,18 @@ Gem::Specification.new do |s|
|
|
36
36
|
"lib/page_magic/page_magic.rb",
|
37
37
|
"lib/page_magic/session.rb",
|
38
38
|
"page_magic.gemspec",
|
39
|
+
"spec/browser_spec.rb",
|
40
|
+
"spec/element_context_spec.rb",
|
39
41
|
"spec/element_spec.rb",
|
40
42
|
"spec/helpers/capybara.rb",
|
41
43
|
"spec/member_methods_spec.rb",
|
42
|
-
"spec/page_magic/browser_spec.rb",
|
43
|
-
"spec/page_magic/element_context_spec.rb",
|
44
44
|
"spec/page_magic/elements_spec.rb",
|
45
|
-
"spec/page_magic/session_spec.rb",
|
46
45
|
"spec/page_magic/usage/defining_page_elements_spec.rb",
|
47
46
|
"spec/page_magic/usage/defining_pages_spec.rb",
|
48
47
|
"spec/page_magic/usage/include_page_magic_spec.rb",
|
49
48
|
"spec/page_magic/usage/interacting_with_pages_spec.rb",
|
50
49
|
"spec/page_magic/usage/starting_a_session_spec.rb",
|
50
|
+
"spec/session_spec.rb",
|
51
51
|
"spec/spec_helper.rb"
|
52
52
|
]
|
53
53
|
s.homepage = "https://github.com/ladtech/page_magic"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'page_magic/driver'
|
2
|
+
|
3
|
+
module PageMagic
|
4
|
+
describe Driver do
|
5
|
+
|
6
|
+
let(:driver_class) do
|
7
|
+
Class.new do
|
8
|
+
attr_reader :rack_app, :options
|
9
|
+
def initialize rack_app, options
|
10
|
+
@rack_app = rack_app
|
11
|
+
@options = options
|
12
|
+
end
|
13
|
+
def == driver
|
14
|
+
driver.rack_app == rack_app && driver.options == options
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
subject do
|
19
|
+
described_class.new :custom_browser do
|
20
|
+
driver_class
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#supports?' do
|
25
|
+
context 'browser is in supported browsers' do
|
26
|
+
it 'returns true' do
|
27
|
+
expect(subject.support?(:custom_browser)).to eq(true)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'browser is not in supported browsers' do
|
32
|
+
it 'returns false' do
|
33
|
+
expect(subject.support?(:unsupported_browser)).to eq(false)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
describe '#build' do
|
38
|
+
it 'adds the browser to the options supplied to the driver' do
|
39
|
+
expect(subject.build(:rack_app, browser: :custom_browser, options: {}).options).to eq(browser: :custom_browser)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'creates an instance of the supplied driver' do
|
43
|
+
expect(subject.build(:rack_app,browser: :custom_browser, options: {})).to eq(driver_class.new(:rack_app, {browser: :custom_browser}))
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'page_magic/drivers/poltergeist'
|
2
|
+
module PageMagic
|
3
|
+
class Drivers
|
4
|
+
describe Poltergeist do
|
5
|
+
it %q{is capybara's poltergeist driver} do
|
6
|
+
expect(described_class.build(:app, browser: :poltergeist, options:{})).to be_a(Capybara::Poltergeist::Driver)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'page_magic/drivers/rack_test'
|
2
|
+
module PageMagic
|
3
|
+
class Drivers
|
4
|
+
describe RackTest do
|
5
|
+
it %q{is capybara's rack test driver} do
|
6
|
+
expect(described_class.build(:app, browser: :rack_test, options:{})).to be_a(Capybara::RackTest::Driver)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'page_magic/drivers'
|
2
|
+
|
3
|
+
module PageMagic
|
4
|
+
|
5
|
+
describe Drivers do
|
6
|
+
subject { described_class.new }
|
7
|
+
let(:expected_driver) { Driver.new(:browser_driver) }
|
8
|
+
describe '#register' do
|
9
|
+
it 'stores the driver' do
|
10
|
+
subject.register expected_driver
|
11
|
+
expect(subject.all).to eq([expected_driver])
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#find' do
|
16
|
+
it 'returns the registered driver' do
|
17
|
+
subject.register expected_driver
|
18
|
+
expect(subject.find(:browser_driver)).to eq(expected_driver)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#load' do
|
23
|
+
include_context :files
|
24
|
+
it 'loads the drivers in the specified path' do
|
25
|
+
|
26
|
+
class_definition=<<-RUBY
|
27
|
+
class CustomDriver;
|
28
|
+
def self.support? browser
|
29
|
+
true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
RUBY
|
33
|
+
|
34
|
+
File.write("#{scratch_dir}/custom_driver.rb", class_definition )
|
35
|
+
|
36
|
+
subject.load(scratch_dir)
|
37
|
+
expect(subject.find(:custom_browser)).to be(::CustomDriver)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
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 :url
|
7
7
|
|
8
8
|
def my_method
|
9
9
|
:called
|
@@ -20,56 +20,6 @@ describe PageMagic::Session do
|
|
20
20
|
|
21
21
|
let(:browser) { double('browser', current_url: 'url') }
|
22
22
|
|
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
|
37
|
-
|
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
|
46
|
-
end
|
47
|
-
|
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
|
64
|
-
end
|
65
|
-
|
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
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
23
|
it 'should visit the given url' do
|
74
24
|
browser.should_receive(:visit).with(page.url)
|
75
25
|
session = PageMagic::Session.new(browser).visit(page)
|
@@ -88,4 +38,30 @@ describe PageMagic::Session do
|
|
88
38
|
session.my_method.should be(:called)
|
89
39
|
end
|
90
40
|
end
|
41
|
+
|
42
|
+
context 'move_to moves the session object to another page' do
|
43
|
+
it 'can take a class' do
|
44
|
+
page_magic_session = PageMagic::Session.new(double(:browser, current_url: '/another_page1'))
|
45
|
+
page_magic_session.move_to(another_page_class)
|
46
|
+
page_magic_session.current_page.should be_a(another_page_class)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'can take the name of the class as a string' do
|
50
|
+
class ThePage
|
51
|
+
include PageMagic
|
52
|
+
url '/the_page'
|
53
|
+
end
|
54
|
+
|
55
|
+
page_magic_session = PageMagic::Session.new(double(:browser, current_url: '/the_page'))
|
56
|
+
page_magic_session.move_to("ThePage")
|
57
|
+
page_magic_session.current_page.should be_a(ThePage)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should wait until the browser url has changed' do
|
61
|
+
mock_browser = double(:browser, current_url: 'a')
|
62
|
+
page_magic_session = PageMagic::Session.new(mock_browser)
|
63
|
+
|
64
|
+
expect { page_magic_session.move_to(another_page_class) }.to raise_error(Wait::ResultInvalid)
|
65
|
+
end
|
66
|
+
end
|
91
67
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
describe 'PageMagic.session' do
|
2
|
+
|
2
3
|
let(:app_class) do
|
3
4
|
Class.new do
|
4
5
|
def call env
|
@@ -11,35 +12,10 @@ describe 'PageMagic.session' do
|
|
11
12
|
Capybara.drivers[browser].call(nil)
|
12
13
|
end
|
13
14
|
|
14
|
-
context '
|
15
|
-
it '
|
16
|
-
|
17
|
-
|
18
|
-
session = PageMagic.session(:chrome)
|
19
|
-
|
20
|
-
registered_driver(:chrome).should == Capybara::Selenium::Driver.new(nil, browser: :chrome)
|
21
|
-
|
22
|
-
session.raw_session.should == :chrome_session
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'browsers' do
|
26
|
-
it 'supports poltergeist' do
|
27
|
-
session = PageMagic.session(:poltergeist, application: app_class.new)
|
28
|
-
session.raw_session.driver.is_a?(Capybara::Poltergeist::Driver).should be_true
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'supports selenium' do
|
32
|
-
session = PageMagic.session(:firefox, application: app_class.new)
|
33
|
-
session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context 'defaulting the browser used from PageMagic sessions' do
|
39
|
-
it "uses what ever Capybara's default_driver is set to" do
|
40
|
-
Capybara.default_driver = :rack_test
|
41
|
-
session = PageMagic.session
|
42
|
-
session.raw_session.mode.should == :rack_test
|
15
|
+
context 'specificying a browser' do
|
16
|
+
it 'loads the driver for the specified browser' do
|
17
|
+
session = PageMagic.session(browser: :firefox)
|
18
|
+
session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
|
43
19
|
end
|
44
20
|
end
|
45
21
|
|
@@ -52,7 +28,7 @@ describe 'PageMagic.session' do
|
|
52
28
|
end
|
53
29
|
|
54
30
|
it 'can run against an rack application using a particular browser' do
|
55
|
-
session = PageMagic.session(:rack_test, application: app_class.new)
|
31
|
+
session = PageMagic.session(browser: :rack_test, application: app_class.new)
|
56
32
|
session.raw_session.mode.should == :rack_test
|
57
33
|
session.raw_session.visit('/')
|
58
34
|
session.raw_session.text.should == 'hello world!!'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'page_magic'
|
2
|
+
|
3
|
+
describe PageMagic do
|
4
|
+
describe '::drivers' do
|
5
|
+
it 'returns loaded drivers' do
|
6
|
+
expected_drivers = described_class::Drivers.new.tap do |drivers|
|
7
|
+
drivers.load
|
8
|
+
end
|
9
|
+
|
10
|
+
expect(described_class.drivers).to eq(expected_drivers)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '::session' do
|
15
|
+
context 'specifying the browser' do
|
16
|
+
it 'loads the correct driver' do
|
17
|
+
session = described_class.session(browser: :firefox)
|
18
|
+
session.raw_session.driver.is_a?(Capybara::Selenium::Driver).should be_true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'specifying a rack application' do
|
23
|
+
it 'configures capybara to run against the app' do
|
24
|
+
session = described_class.session(application: :rack_application)
|
25
|
+
expect(session.raw_session.app).to be(:rack_application)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'specifying options' do
|
30
|
+
it 'passes the options to the browser driver' do
|
31
|
+
options = {option: :config}
|
32
|
+
session = described_class.session(options: options, browser: :chrome)
|
33
|
+
|
34
|
+
expect(session.raw_session.driver.options).to include(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'driver for browser not found' do
|
39
|
+
it 'raises an error' do
|
40
|
+
expect{described_class.session(browser: :invalid)}.to raise_exception described_class::UnspportedBrowserException
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,7 +11,22 @@ require 'page_magic'
|
|
11
11
|
require 'capybara/rspec'
|
12
12
|
require 'helpers/capybara'
|
13
13
|
|
14
|
+
shared_context :files do
|
15
|
+
require 'tmpdir'
|
16
|
+
def scratch_dir
|
17
|
+
@dir ||= Dir.mktmpdir
|
18
|
+
end
|
19
|
+
end
|
14
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
|
15
30
|
|
16
31
|
RSpec.configure do
|
17
32
|
|
metadata
CHANGED
@@ -1,55 +1,97 @@
|
|
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.alpha7
|
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-07-
|
11
|
+
date: 2015-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: wait
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- -
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
47
|
version: '0'
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- -
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: jeweler
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- -
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-ctags-bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
46
88
|
- !ruby/object:Gem::Version
|
47
89
|
version: '0'
|
48
90
|
type: :development
|
49
91
|
prerelease: false
|
50
92
|
version_requirements: !ruby/object:Gem::Requirement
|
51
93
|
requirements:
|
52
|
-
- -
|
94
|
+
- - ">="
|
53
95
|
- !ruby/object:Gem::Version
|
54
96
|
version: '0'
|
55
97
|
description: Framework for modeling and interacting with webpages which wraps capybara
|
@@ -59,10 +101,10 @@ extensions: []
|
|
59
101
|
extra_rdoc_files:
|
60
102
|
- README.md
|
61
103
|
files:
|
62
|
-
- .rspec
|
63
|
-
- .ruby-gemset
|
64
|
-
- .ruby-version
|
65
|
-
- .travis.yml
|
104
|
+
- ".rspec"
|
105
|
+
- ".ruby-gemset"
|
106
|
+
- ".ruby-version"
|
107
|
+
- ".travis.yml"
|
66
108
|
- Gemfile
|
67
109
|
- Gemfile.lock
|
68
110
|
- Guardfile
|
@@ -71,7 +113,11 @@ files:
|
|
71
113
|
- VERSION
|
72
114
|
- lib/ext/string.rb
|
73
115
|
- lib/page_magic.rb
|
74
|
-
- lib/page_magic/
|
116
|
+
- lib/page_magic/driver.rb
|
117
|
+
- lib/page_magic/drivers.rb
|
118
|
+
- lib/page_magic/drivers/poltergeist.rb
|
119
|
+
- lib/page_magic/drivers/rack_test.rb
|
120
|
+
- lib/page_magic/drivers/selenium.rb
|
75
121
|
- lib/page_magic/element.rb
|
76
122
|
- lib/page_magic/element_context.rb
|
77
123
|
- lib/page_magic/elements.rb
|
@@ -82,7 +128,11 @@ files:
|
|
82
128
|
- spec/element_spec.rb
|
83
129
|
- spec/helpers/capybara.rb
|
84
130
|
- spec/member_methods_spec.rb
|
85
|
-
- spec/page_magic/
|
131
|
+
- spec/page_magic/driver_spec.rb
|
132
|
+
- spec/page_magic/drivers/poltergeist_spec.rb
|
133
|
+
- spec/page_magic/drivers/rack_test_spec.rb
|
134
|
+
- spec/page_magic/drivers/selenium_spec.rb
|
135
|
+
- spec/page_magic/drivers_spec.rb
|
86
136
|
- spec/page_magic/element_context_spec.rb
|
87
137
|
- spec/page_magic/elements_spec.rb
|
88
138
|
- spec/page_magic/session_spec.rb
|
@@ -91,6 +141,7 @@ files:
|
|
91
141
|
- spec/page_magic/usage/include_page_magic_spec.rb
|
92
142
|
- spec/page_magic/usage/interacting_with_pages_spec.rb
|
93
143
|
- spec/page_magic/usage/starting_a_session_spec.rb
|
144
|
+
- spec/page_magic_spec.rb
|
94
145
|
- spec/spec_helper.rb
|
95
146
|
homepage: https://github.com/ladtech/page_magic
|
96
147
|
licenses:
|
@@ -102,17 +153,17 @@ require_paths:
|
|
102
153
|
- lib
|
103
154
|
required_ruby_version: !ruby/object:Gem::Requirement
|
104
155
|
requirements:
|
105
|
-
- -
|
156
|
+
- - ">="
|
106
157
|
- !ruby/object:Gem::Version
|
107
158
|
version: '0'
|
108
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
160
|
requirements:
|
110
|
-
- -
|
161
|
+
- - ">"
|
111
162
|
- !ruby/object:Gem::Version
|
112
163
|
version: 1.3.1
|
113
164
|
requirements: []
|
114
165
|
rubyforge_project:
|
115
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.2.2
|
116
167
|
signing_key:
|
117
168
|
specification_version: 4
|
118
169
|
summary: Framework for modeling and interacting with webpages
|
data/lib/page_magic/browser.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module PageMagic
|
2
|
-
module Browser
|
3
|
-
|
4
|
-
class << self
|
5
|
-
attr_writer :default
|
6
|
-
def session
|
7
|
-
@session ||= PageMagic.session(default)
|
8
|
-
end
|
9
|
-
|
10
|
-
def default
|
11
|
-
@default || :firefox
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def browser
|
16
|
-
Browser.session
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
describe PageMagic::Browser do
|
2
|
-
let(:app) { Object.new }
|
3
|
-
|
4
|
-
before do
|
5
|
-
PageMagic::Browser.instance_variable_set(:@session, nil)
|
6
|
-
app.extend PageMagic::Browser
|
7
|
-
end
|
8
|
-
|
9
|
-
describe 'default' do
|
10
|
-
it 'should be firefox' do
|
11
|
-
PageMagic::Browser.default.should == :firefox
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe 'browser' do
|
16
|
-
it 'should return the existing session' do
|
17
|
-
session_instance = app.browser
|
18
|
-
app.browser.should == session_instance
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should create a session if not already set' do
|
22
|
-
new_session = double(:new_session)
|
23
|
-
|
24
|
-
PageMagic.should_receive(:session).with(:firefox).and_return new_session
|
25
|
-
app.browser.should == new_session
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'should use custom browser' do
|
29
|
-
PageMagic.should_receive(:session).with(:custom_browser)
|
30
|
-
|
31
|
-
PageMagic::Browser.default = :custom_browser
|
32
|
-
app.browser
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|