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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 472e81de60d3f72173b40e0189907b1aebdb0356
4
- data.tar.gz: e710915875c2abc4eea118c9e9159f7146b4ff96
3
+ metadata.gz: 71735671e9e4181369dcfe4804f85b2a37b670ee
4
+ data.tar.gz: 8ddbf2000d882bc268da5e5804f628c80c15ca57
5
5
  SHA512:
6
- metadata.gz: ac557b2b637f0a35f5cc40f93d6076a1bc8a2d396b397c5dcbab005d8322d3897457d32022a0d0437129bab147eef6ddcce41696259908ffbe3d893c5e29d884
7
- data.tar.gz: f7347d54c3e324b1f0a014b2fe9e650ac33be8f219ecd938bce074ce07a6a7492d9da6aa9e94b87acf358b364ddd948e04eaa67e6890b31bbeb022150e23b874
6
+ metadata.gz: 896939d371bbb321f48c816e3ea5408df25849c3cdb47498d2396535bbeb2ea49ce982ccb1096de0d5c65265ebacaa73f89722d189e011f9ee934c512e899ef6
7
+ data.tar.gz: 04e2b601eb106a745717681c15a1d5db66b72b22f323c561de9111bf2bf58024493443aa652e2860ece8bb7329fa29ccf85160cd5fd66a634a341c34c9a6cf2b
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .config
5
5
  .yardoc
6
6
  Gemfile.lock
7
+ vendor/
7
8
  InstalledFiles
8
9
  _yardoc
9
10
  coverage
@@ -1 +1 @@
1
- ruby-2.1.0
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
- ## Usage
22
- If you are using cucumber, include the page initialization helper methods in the cucumber World instance.
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
- Include `LightPage` in your page objects, define a `page_url` (if you want to be able to use the `PageInitializers`), and define elements on the page.
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
- text_field(:username, :label => 'Username')
36
- text_field(:password, :label => 'Password')
37
- button(:log_in_button, :text => 'Log In')
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.username.set(username)
41
- self.password.set(password)
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
- Visit and interact with your page objects.
52
+ Interact with the page:
48
53
  ```ruby
49
- visit(LoginPage).login('afinch', 'pa55w0rd')
54
+ visit(LoginPage).log_in('afinch', 'mockingbird60')
50
55
  ```
51
56
 
52
57
  ## Contributing
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LitePage
2
- VERSION = "0.1.0"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -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
@@ -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 ElementFactory and ClassMethods' do
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: 0.1.0
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-03-09 00:00:00.000000000 Z
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/element_factory_test.rb
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.2.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/element_factory_test.rb
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
@@ -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