lite_page 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lite_page.rb +3 -19
- data/lib/lite_page/element_factory.rb +21 -0
- data/lib/lite_page/version.rb +1 -1
- data/test/class_methods_test.rb +0 -37
- data/test/element_factory_test.rb +42 -0
- data/test/lite_page_test.rb +2 -2
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70dd796f0dfb46bd35e6b9c9958096cb03812a09
|
4
|
+
data.tar.gz: 4675fc3ac77f01e2adeb5779becf01650a533a86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 564ca2b0f8821524b7eaa69a4e06ef278d23888849d615ddd09d6a1f302e2426ebc5020296f8aebc180a307d336ad84500c9d422fc7781a6eb76884dc41f3f0d
|
7
|
+
data.tar.gz: 9dfb69473224e2467dd688669a93dc76f26a8bfaae0c0213ce321a91e9ca6dd4d4f8b95a4a4e707aeaaa907c70aaabb2c3c30eb609161620852a819375698cfe
|
data/lib/lite_page.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'lite_page/
|
2
|
+
require 'lite_page/element_factory'
|
3
3
|
require 'lite_page/page_initializers'
|
4
|
+
require 'lite_page/version'
|
4
5
|
|
5
6
|
module LitePage
|
6
7
|
# Extends the including class with the ElementFactory and ClassMethods modules.
|
7
8
|
def self.included(base)
|
8
9
|
base.extend(ClassMethods)
|
10
|
+
base.extend(ElementFactory)
|
9
11
|
end
|
10
12
|
|
11
13
|
# Initializes the page instance and sets the browser instance
|
@@ -37,23 +39,5 @@ module LitePage
|
|
37
39
|
uri.to_s
|
38
40
|
end
|
39
41
|
end
|
40
|
-
|
41
|
-
# Provides convenient method for concisely defining element getters
|
42
|
-
#
|
43
|
-
# @param root_elem_var_name [Symbol] the name of the instance variable
|
44
|
-
# containing the element on which methods should be caleld
|
45
|
-
# (typically the browser instance).
|
46
|
-
# @param element_definitions [Hash] the hash used to define element getters
|
47
|
-
# on the class instance where each key represents the name of the method
|
48
|
-
# to be defined and whose value is an array containing first, the
|
49
|
-
# element tag name and second, the selectors with which to locate it.
|
50
|
-
def def_elements(root_elem_var_name, element_definitions = {})
|
51
|
-
element_definitions.each do |name, definition|
|
52
|
-
define_method(name) do |other_selectors = {}|
|
53
|
-
definition[1].merge!(other_selectors)
|
54
|
-
instance_variable_get(root_elem_var_name.to_sym).send(*definition)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
42
|
end
|
59
43
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module LitePage
|
2
|
+
module ElementFactory
|
3
|
+
# Provides convenient method for concisely defining element getters
|
4
|
+
#
|
5
|
+
# @param root_elem_var_name [Symbol] the name of the instance variable
|
6
|
+
# containing the element on which methods should be caleld
|
7
|
+
# (typically the browser instance).
|
8
|
+
# @param element_definitions [Hash] the hash used to define element getters
|
9
|
+
# on the class instance where each key represents the name of the method
|
10
|
+
# to be defined and whose value is an array containing first, the
|
11
|
+
# element tag name and second, the selectors with which to locate it.
|
12
|
+
def def_elements(root_elem_var_name, element_definitions = {})
|
13
|
+
element_definitions.each do |name, definition|
|
14
|
+
define_method(name) do |other_selectors = {}|
|
15
|
+
definition[1].merge!(other_selectors)
|
16
|
+
instance_variable_get(root_elem_var_name.to_sym).send(*definition)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/lite_page/version.rb
CHANGED
data/test/class_methods_test.rb
CHANGED
@@ -53,42 +53,5 @@ class ClassMethodsTest < Minitest::Spec
|
|
53
53
|
page.new.page_url(:baz => 'qux', :fizz => 'buzz').must_equal('http://www.example.com?foo=bar&baz=qux&fizz=buzz')
|
54
54
|
end
|
55
55
|
end
|
56
|
-
|
57
|
-
describe '#def_elements' do
|
58
|
-
before do
|
59
|
-
class Browser
|
60
|
-
def echo_args(*args)
|
61
|
-
args
|
62
|
-
end
|
63
|
-
|
64
|
-
alias_method :button, :echo_args
|
65
|
-
alias_method :div, :echo_args
|
66
|
-
end
|
67
|
-
|
68
|
-
class Page
|
69
|
-
extend LitePage::ClassMethods
|
70
|
-
|
71
|
-
def initialize
|
72
|
-
@my_browser = Browser.new
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should define getters for all of the given definitions' do
|
78
|
-
Page.def_elements(:@my_browser, {
|
79
|
-
:foo => [:button, :id => 'foo-element'],
|
80
|
-
:bar => [:div, :class => 'bar-element']
|
81
|
-
})
|
82
|
-
|
83
|
-
Page.new.foo.must_equal([:id => 'foo-element'])
|
84
|
-
Page.new.bar.must_equal([:class => 'bar-element'])
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'should define getters that accept additional selectors' do
|
88
|
-
Page.def_elements(:@my_browser, :foo => [:button, :id => 'foo-element'])
|
89
|
-
result = Page.new.foo(:text => /blah/)
|
90
|
-
result.must_equal([:id => 'foo-element', :text => /blah/])
|
91
|
-
end
|
92
|
-
end
|
93
56
|
end
|
94
57
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ElementFactoryTest < Minitest::Spec
|
4
|
+
describe LitePage::ElementFactory do
|
5
|
+
before do
|
6
|
+
class Browser
|
7
|
+
def echo_args(*args)
|
8
|
+
args
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :button, :echo_args
|
12
|
+
alias_method :div, :echo_args
|
13
|
+
end
|
14
|
+
|
15
|
+
class Page
|
16
|
+
extend LitePage::ElementFactory
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@my_browser = Browser.new
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#def_elements' do
|
25
|
+
it 'should define getters for all of the given definitions' do
|
26
|
+
Page.def_elements(:@my_browser, {
|
27
|
+
:foo => [:button, :id => 'foo-element'],
|
28
|
+
:bar => [:div, :class => 'bar-element']
|
29
|
+
})
|
30
|
+
|
31
|
+
Page.new.foo.must_equal([:id => 'foo-element'])
|
32
|
+
Page.new.bar.must_equal([:class => 'bar-element'])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should define getters that accept additional selectors' do
|
36
|
+
Page.def_elements(:@my_browser, :foo => [:button, :id => 'foo-element'])
|
37
|
+
result = Page.new.foo(:text => /blah/)
|
38
|
+
result.must_equal([:id => 'foo-element', :text => /blah/])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/test/lite_page_test.rb
CHANGED
@@ -4,10 +4,10 @@ class LitePageTest < Minitest::Spec
|
|
4
4
|
describe LitePage do
|
5
5
|
let(:page) { Class.new { include LitePage } }
|
6
6
|
|
7
|
-
|
8
7
|
describe '::included' do
|
9
|
-
it 'should extend the class with ClassMethods' do
|
8
|
+
it 'should extend the class with ClassMethods and ElementFactory' do
|
10
9
|
page.is_a?(LitePage::ClassMethods).must_equal(true)
|
10
|
+
page.is_a?(LitePage::ElementFactory).must_equal(true)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite_page
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Clark
|
@@ -126,10 +126,12 @@ files:
|
|
126
126
|
- README.md
|
127
127
|
- Rakefile
|
128
128
|
- lib/lite_page.rb
|
129
|
+
- lib/lite_page/element_factory.rb
|
129
130
|
- lib/lite_page/page_initializers.rb
|
130
131
|
- lib/lite_page/version.rb
|
131
132
|
- lite_page.gemspec
|
132
133
|
- test/class_methods_test.rb
|
134
|
+
- test/element_factory_test.rb
|
133
135
|
- test/lite_page_test.rb
|
134
136
|
- test/page_initializers_test.rb
|
135
137
|
- test/test_helper.rb
|
@@ -159,6 +161,7 @@ specification_version: 4
|
|
159
161
|
summary: A Page Object Model DSL for watir-webdriver
|
160
162
|
test_files:
|
161
163
|
- test/class_methods_test.rb
|
164
|
+
- test/element_factory_test.rb
|
162
165
|
- test/lite_page_test.rb
|
163
166
|
- test/page_initializers_test.rb
|
164
167
|
- test/test_helper.rb
|