lite_page 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/README.md +18 -13
- data/lib/lite_page.rb +18 -3
- data/lib/lite_page/version.rb +1 -1
- data/test/class_methods_test.rb +94 -0
- data/test/lite_page_test.rb +2 -52
- metadata +5 -7
- data/.ruby-gemset +0 -1
- data/lib/lite_page/element_factory.rb +0 -18
- data/test/element_factory_test.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: 71735671e9e4181369dcfe4804f85b2a37b670ee
|
4
|
+
data.tar.gz: 8ddbf2000d882bc268da5e5804f628c80c15ca57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 896939d371bbb321f48c816e3ea5408df25849c3cdb47498d2396535bbeb2ea49ce982ccb1096de0d5c65265ebacaa73f89722d189e011f9ee934c512e899ef6
|
7
|
+
data.tar.gz: 04e2b601eb106a745717681c15a1d5db66b72b22f323c561de9111bf2bf58024493443aa652e2860ece8bb7329fa29ccf85160cd5fd66a634a341c34c9a6cf2b
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.1.0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# LitePage
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/saclark/lite_page.svg?branch=master)](https://travis-ci.org/saclark/lite_page) [![Coverage Status](https://coveralls.io/repos/saclark/lite_page/badge.svg)](https://coveralls.io/r/saclark/lite_page)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/lite_page.svg)](http://badge.fury.io/rb/lite_page) [![Build Status](https://travis-ci.org/saclark/lite_page.svg?branch=master)](https://travis-ci.org/saclark/lite_page) [![Coverage Status](https://coveralls.io/repos/saclark/lite_page/badge.svg)](https://coveralls.io/r/saclark/lite_page)
|
4
4
|
|
5
5
|
A gem providing a quick, clean, and concise means of implementing the Page Object Model pattern and defining a semantic DSL for automated acceptance tests using watir-webdriver.
|
6
6
|
|
@@ -18,35 +18,40 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install lite_page
|
20
20
|
|
21
|
-
##
|
22
|
-
|
21
|
+
## Documentation
|
22
|
+
You can find comprehensive [documentation in the wiki](https://github.com/saclark/lite_page/wiki)
|
23
|
+
|
24
|
+
### Example Usage
|
25
|
+
|
26
|
+
If using cucumber, include `LitePage::PageInitializers` in the `World` instance
|
23
27
|
```ruby
|
24
28
|
World(LitePage::PageInitializers)
|
25
29
|
```
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
Page elements are defined by calling a method corresponding to the appropriate element type and passing it the name by which you wish to access the element and the selectors used to locate it.
|
31
|
+
Define a page object:
|
30
32
|
```ruby
|
31
33
|
class LoginPage
|
32
34
|
include LitePage
|
35
|
+
|
33
36
|
page_url('http://www.example.com/login')
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
+
def_elements(:@browser, {
|
39
|
+
:username_field => [:text_field, :id => 'username'],
|
40
|
+
:password_field => [:text_field, :id => 'password'],
|
41
|
+
:log_in_button => [:button, :value => 'Log In']
|
42
|
+
})
|
38
43
|
|
39
44
|
def log_in(username, password)
|
40
|
-
self.
|
41
|
-
self.
|
45
|
+
self.username_field.set(username)
|
46
|
+
self.password_field.set(password)
|
42
47
|
self.log_in_button.click
|
43
48
|
end
|
44
49
|
end
|
45
50
|
```
|
46
51
|
|
47
|
-
|
52
|
+
Interact with the page:
|
48
53
|
```ruby
|
49
|
-
visit(LoginPage).
|
54
|
+
visit(LoginPage).log_in('afinch', 'mockingbird60')
|
50
55
|
```
|
51
56
|
|
52
57
|
## Contributing
|
data/lib/lite_page.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'uri'
|
2
|
-
require 'watir-webdriver'
|
3
2
|
require 'lite_page/version'
|
4
3
|
require 'lite_page/page_initializers'
|
5
|
-
require 'lite_page/element_factory'
|
6
4
|
|
7
5
|
module LitePage
|
8
6
|
# Extends the including class with the ElementFactory and ClassMethods modules.
|
9
7
|
def self.included(base)
|
10
|
-
base.extend(ElementFactory)
|
11
8
|
base.extend(ClassMethods)
|
12
9
|
end
|
13
10
|
|
@@ -40,5 +37,23 @@ module LitePage
|
|
40
37
|
uri.to_s
|
41
38
|
end
|
42
39
|
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
|
43
58
|
end
|
44
59
|
end
|
data/lib/lite_page/version.rb
CHANGED
@@ -0,0 +1,94 @@
|
|
1
|
+
require_relative 'test_helper'
|
2
|
+
|
3
|
+
class ClassMethodsTest < Minitest::Spec
|
4
|
+
describe LitePage::ClassMethods do
|
5
|
+
let(:page) { Class.new { extend LitePage::ClassMethods } }
|
6
|
+
|
7
|
+
describe '::page_url' do
|
8
|
+
it 'should define a page url instance method' do
|
9
|
+
page.page_url('http://www.example.com')
|
10
|
+
page.new.must_respond_to(:page_url)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#page_url' do
|
15
|
+
it 'should return the url when no arguments passed' do
|
16
|
+
page.page_url('http://www.example.com')
|
17
|
+
page.new.page_url.must_equal('http://www.example.com')
|
18
|
+
|
19
|
+
page.page_url('http://www.example.com?')
|
20
|
+
page.new.page_url.must_equal('http://www.example.com?')
|
21
|
+
|
22
|
+
page.page_url('http://www.example.com?foo=bar')
|
23
|
+
page.new.page_url.must_equal('http://www.example.com?foo=bar')
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should accept query string parameters as an array or hash' do
|
27
|
+
page.page_url('http://www.example.com')
|
28
|
+
page.new.page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
29
|
+
|
30
|
+
page.page_url('http://www.example.com')
|
31
|
+
page.new.page_url([[:foo, 'bar']]).must_equal('http://www.example.com?foo=bar')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should create query string if none existed before' do
|
35
|
+
page.page_url('http://www.example.com')
|
36
|
+
page.new.page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
37
|
+
|
38
|
+
page.page_url('http://www.example.com')
|
39
|
+
page.new.page_url(:foo => 'bar', :baz => 'qux').must_equal('http://www.example.com?foo=bar&baz=qux')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should append query string parameters if some existed before' do
|
43
|
+
page.page_url('http://www.example.com?')
|
44
|
+
page.new.page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
45
|
+
|
46
|
+
page.page_url('http://www.example.com?foo=bar')
|
47
|
+
page.new.page_url(:baz => 'qux').must_equal('http://www.example.com?foo=bar&baz=qux')
|
48
|
+
|
49
|
+
page.page_url('http://www.example.com?foo=bar')
|
50
|
+
page.new.page_url(:foo => :bar).must_equal('http://www.example.com?foo=bar&foo=bar')
|
51
|
+
|
52
|
+
page.page_url('http://www.example.com?foo=bar')
|
53
|
+
page.new.page_url(:baz => 'qux', :fizz => 'buzz').must_equal('http://www.example.com?foo=bar&baz=qux&fizz=buzz')
|
54
|
+
end
|
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
|
+
end
|
94
|
+
end
|
data/test/lite_page_test.rb
CHANGED
@@ -4,9 +4,9 @@ class LitePageTest < Minitest::Spec
|
|
4
4
|
describe LitePage do
|
5
5
|
let(:page) { Class.new { include LitePage } }
|
6
6
|
|
7
|
+
|
7
8
|
describe '::included' do
|
8
|
-
it 'should extend the class with
|
9
|
-
page.is_a?(LitePage::ElementFactory).must_equal(true)
|
9
|
+
it 'should extend the class with ClassMethods' do
|
10
10
|
page.is_a?(LitePage::ClassMethods).must_equal(true)
|
11
11
|
end
|
12
12
|
end
|
@@ -17,55 +17,5 @@ class LitePageTest < Minitest::Spec
|
|
17
17
|
proc { page.new }.must_raise ArgumentError
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
describe '::ClassMethods#page_url' do
|
22
|
-
it 'should define a page url instance method' do
|
23
|
-
page.page_url('http://www.example.com')
|
24
|
-
page.new(nil).must_respond_to(:page_url)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#page_url' do
|
29
|
-
it 'should return the url when no arguments passed' do
|
30
|
-
page.page_url('http://www.example.com')
|
31
|
-
page.new(nil).page_url.must_equal('http://www.example.com')
|
32
|
-
|
33
|
-
page.page_url('http://www.example.com?')
|
34
|
-
page.new(nil).page_url.must_equal('http://www.example.com?')
|
35
|
-
|
36
|
-
page.page_url('http://www.example.com?foo=bar')
|
37
|
-
page.new(nil).page_url.must_equal('http://www.example.com?foo=bar')
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'should accept query string parameters as an array or hash' do
|
41
|
-
page.page_url('http://www.example.com')
|
42
|
-
page.new(nil).page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
43
|
-
|
44
|
-
page.page_url('http://www.example.com')
|
45
|
-
page.new(nil).page_url([[:foo, 'bar']]).must_equal('http://www.example.com?foo=bar')
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should create query string if none existed before' do
|
49
|
-
page.page_url('http://www.example.com')
|
50
|
-
page.new(nil).page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
51
|
-
|
52
|
-
page.page_url('http://www.example.com')
|
53
|
-
page.new(nil).page_url(:foo => 'bar', :baz => 'qux').must_equal('http://www.example.com?foo=bar&baz=qux')
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should append query string parameters if some existed before' do
|
57
|
-
page.page_url('http://www.example.com?')
|
58
|
-
page.new(nil).page_url(:foo => 'bar').must_equal('http://www.example.com?foo=bar')
|
59
|
-
|
60
|
-
page.page_url('http://www.example.com?foo=bar')
|
61
|
-
page.new(nil).page_url(:baz => 'qux').must_equal('http://www.example.com?foo=bar&baz=qux')
|
62
|
-
|
63
|
-
page.page_url('http://www.example.com?foo=bar')
|
64
|
-
page.new(nil).page_url(:foo => :bar).must_equal('http://www.example.com?foo=bar&foo=bar')
|
65
|
-
|
66
|
-
page.page_url('http://www.example.com?foo=bar')
|
67
|
-
page.new(nil).page_url(:baz => 'qux', :fizz => 'buzz').must_equal('http://www.example.com?foo=bar&baz=qux&fizz=buzz')
|
68
|
-
end
|
69
|
-
end
|
70
20
|
end
|
71
21
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite_page
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Clark
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: watir-webdriver
|
@@ -119,7 +119,6 @@ extra_rdoc_files: []
|
|
119
119
|
files:
|
120
120
|
- ".coveralls.yml"
|
121
121
|
- ".gitignore"
|
122
|
-
- ".ruby-gemset"
|
123
122
|
- ".ruby-version"
|
124
123
|
- ".travis.yml"
|
125
124
|
- Gemfile
|
@@ -127,11 +126,10 @@ files:
|
|
127
126
|
- README.md
|
128
127
|
- Rakefile
|
129
128
|
- lib/lite_page.rb
|
130
|
-
- lib/lite_page/element_factory.rb
|
131
129
|
- lib/lite_page/page_initializers.rb
|
132
130
|
- lib/lite_page/version.rb
|
133
131
|
- lite_page.gemspec
|
134
|
-
- test/
|
132
|
+
- test/class_methods_test.rb
|
135
133
|
- test/lite_page_test.rb
|
136
134
|
- test/page_initializers_test.rb
|
137
135
|
- test/test_helper.rb
|
@@ -155,12 +153,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
153
|
version: '0'
|
156
154
|
requirements: []
|
157
155
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.4.6
|
159
157
|
signing_key:
|
160
158
|
specification_version: 4
|
161
159
|
summary: A Page Object Model DSL for watir-webdriver
|
162
160
|
test_files:
|
163
|
-
- test/
|
161
|
+
- test/class_methods_test.rb
|
164
162
|
- test/lite_page_test.rb
|
165
163
|
- test/page_initializers_test.rb
|
166
164
|
- test/test_helper.rb
|
data/.ruby-gemset
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
LitePage
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module LitePage
|
2
|
-
# Defines a set of class methods on the including class corresponding to
|
3
|
-
# each of the instance methods available on the `Watir::Container` class.
|
4
|
-
# Each class method takes a symbol or string that will be used to
|
5
|
-
# dynamically define an instance method on the including class that takes
|
6
|
-
# any number of arguments so long as they are valid arguments for the
|
7
|
-
# corresponding `Watir::Container` instance method. When the instance method
|
8
|
-
# is called, it will call the corresponding `Watir::Container` instance method
|
9
|
-
# on the class instance's browser instance along with the parameters given
|
10
|
-
# to the class method.
|
11
|
-
module ElementFactory
|
12
|
-
Watir::Container.instance_methods.each do |tag_name|
|
13
|
-
define_method(tag_name) do |method_name, *args, &block|
|
14
|
-
define_method(method_name) { @browser.send(tag_name, *args, &block) }
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
require_relative 'test_helper'
|
2
|
-
|
3
|
-
class ElementFactoryTest < Minitest::Spec
|
4
|
-
describe LitePage::ElementFactory do
|
5
|
-
let(:page) do
|
6
|
-
Class.new do
|
7
|
-
extend LitePage::ElementFactory
|
8
|
-
def initialize(browser)
|
9
|
-
@browser = browser
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
let(:browser) do
|
15
|
-
Class.new do
|
16
|
-
def button(selectors)
|
17
|
-
"button found using #{selectors.to_s}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'should define class methods for each Watir::Container instance method' do
|
23
|
-
Watir::Container.instance_methods.each do |method_name|
|
24
|
-
page.must_respond_to method_name
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe 'page elements defined' do
|
29
|
-
it 'should create methods that call the appropriate method on the browser' do
|
30
|
-
page.button(:my_button, :id => 'my-button')
|
31
|
-
page.new(browser.new).my_button.must_equal('button found using {:id=>"my-button"}')
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|