capybara-page-object 0.3.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +83 -0
- data/VERSION +1 -1
- data/capybara-page-object.gemspec +17 -10
- data/lib/capybara-page-object.rb +4 -4
- data/lib/collections.rb +11 -5
- data/lib/delegators.rb +14 -0
- data/lib/element.rb +14 -11
- data/lib/element/TODO.md +11 -0
- data/lib/element/anchor.rb +1 -5
- data/lib/element/form.rb +6 -10
- data/lib/element/form_field.rb +4 -9
- data/lib/element/head.rb +15 -0
- data/lib/element/image.rb +6 -11
- data/lib/element/input.rb +8 -13
- data/lib/element/list.rb +1 -15
- data/lib/element/list_item.rb +7 -0
- data/lib/element/meta.rb +2 -7
- data/lib/element/select.rb +1 -13
- data/lib/element/table.rb +11 -4
- data/lib/element/table_header.rb +4 -0
- data/lib/element/table_row.rb +7 -0
- data/lib/element/text_based_input.rb +16 -0
- data/lib/element/textarea.rb +5 -11
- data/lib/html5_data.rb +3 -7
- data/lib/key_value.rb +1 -1
- data/lib/node.rb +9 -54
- data/lib/page.rb +40 -0
- data/spec/common_spec.rb +13 -21
- data/spec/element/anchor_spec.rb +2 -2
- data/spec/element/base_spec.rb +2 -2
- data/spec/element/form_field_spec.rb +4 -4
- data/spec/element/form_spec.rb +26 -25
- data/spec/element/head_spec.rb +24 -0
- data/spec/element/image_spec.rb +5 -5
- data/spec/element/input_spec.rb +52 -17
- data/spec/element/list_item_spec.rb +19 -0
- data/spec/element/list_spec.rb +3 -20
- data/spec/element/meta_spec.rb +3 -2
- data/spec/element/select_spec.rb +4 -29
- data/spec/element/table_row_spec.rb +19 -0
- data/spec/element/table_spec.rb +35 -5
- data/spec/element/textarea_spec.rb +14 -4
- data/spec/node_spec.rb +14 -37
- data/spec/page_spec.rb +37 -0
- metadata +31 -24
- data/README.rdoc +0 -18
- data/lib/element/listitem.rb +0 -7
- data/lib/extractor/common.rb +0 -42
- data/lib/extractor/page_level.rb +0 -15
- data/lib/navigation.rb +0 -16
- data/spec/element/listitem_spec.rb +0 -25
data/README.markdown
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[![Build Status](https://secure.travis-ci.org/andyw8/capybara-page-object.png)](http://travis-ci.org/andyw8/capybara-page-object)
|
2
|
+
|
3
|
+
# capybara-page-object #
|
4
|
+
|
5
|
+
Page Objects for Capybara
|
6
|
+
|
7
|
+
## Installation ##
|
8
|
+
|
9
|
+
Gemfile
|
10
|
+
|
11
|
+
gem 'capybara-page-object'
|
12
|
+
|
13
|
+
## Getting Started ##
|
14
|
+
|
15
|
+
features/catalog.feature
|
16
|
+
|
17
|
+
```gherkin
|
18
|
+
Feature: Catalog
|
19
|
+
|
20
|
+
Scenario: Products available
|
21
|
+
|
22
|
+
Given the products:
|
23
|
+
| iPhone |
|
24
|
+
| iPad |
|
25
|
+
When I visit the store
|
26
|
+
Then those products should be listed
|
27
|
+
```
|
28
|
+
|
29
|
+
features/step_definitions/product_steps.rb
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
Given /^the products:$/ do |table|
|
33
|
+
@products = []
|
34
|
+
table.raw.flatten.each do |p|
|
35
|
+
@products << Product.create!(:title => p)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
When /^I visit the store$/ do
|
40
|
+
@page = Pages::Products::Index.visit
|
41
|
+
end
|
42
|
+
|
43
|
+
Then /^those products should be listed$/ do
|
44
|
+
@page.product_titles.should == @products.collect{ |p| p.title }
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
features/support/pages/products/index.rb
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
module Pages
|
52
|
+
module Products
|
53
|
+
class Index < CapybaraPageObject::Page
|
54
|
+
def path
|
55
|
+
'/products'
|
56
|
+
end
|
57
|
+
|
58
|
+
def product_titles
|
59
|
+
all('.products .title').collect(&:text)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
## Demo Project ##
|
67
|
+
|
68
|
+
[Depot](https://github.com/andyw8/depot)
|
69
|
+
|
70
|
+
## Contributing to capybara-page-object ##
|
71
|
+
|
72
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
73
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
74
|
+
* Fork the project
|
75
|
+
* Start a feature/bugfix branch
|
76
|
+
* Commit and push until you are happy with your contribution
|
77
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
78
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
79
|
+
|
80
|
+
## Copyright ##
|
81
|
+
|
82
|
+
Copyright (c) 2012 Andy Waite. See LICENSE.txt for
|
83
|
+
further details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
@@ -5,62 +5,69 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{capybara-page-object}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.5.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = [%q{Andy Waite}]
|
12
|
-
s.date = %q{2012-04-
|
12
|
+
s.date = %q{2012-04-08}
|
13
13
|
s.description = %q{Page Objects for Capybara}
|
14
14
|
s.email = %q{andy@andywaite.com}
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
"Gemfile",
|
22
22
|
"Gemfile.lock",
|
23
23
|
"LICENSE.txt",
|
24
|
-
"README.
|
24
|
+
"README.markdown",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"capybara-page-object.gemspec",
|
28
28
|
"lib/capybara-page-object.rb",
|
29
29
|
"lib/collections.rb",
|
30
|
+
"lib/delegators.rb",
|
30
31
|
"lib/element.rb",
|
32
|
+
"lib/element/TODO.md",
|
31
33
|
"lib/element/anchor.rb",
|
32
34
|
"lib/element/form.rb",
|
33
35
|
"lib/element/form_field.rb",
|
36
|
+
"lib/element/head.rb",
|
34
37
|
"lib/element/image.rb",
|
35
38
|
"lib/element/input.rb",
|
36
39
|
"lib/element/list.rb",
|
37
|
-
"lib/element/
|
40
|
+
"lib/element/list_item.rb",
|
38
41
|
"lib/element/meta.rb",
|
39
42
|
"lib/element/select.rb",
|
40
43
|
"lib/element/table.rb",
|
44
|
+
"lib/element/table_header.rb",
|
45
|
+
"lib/element/table_row.rb",
|
46
|
+
"lib/element/text_based_input.rb",
|
41
47
|
"lib/element/textarea.rb",
|
42
|
-
"lib/extractor/common.rb",
|
43
|
-
"lib/extractor/page_level.rb",
|
44
48
|
"lib/html5_data.rb",
|
45
49
|
"lib/key_value.rb",
|
46
|
-
"lib/navigation.rb",
|
47
50
|
"lib/node.rb",
|
51
|
+
"lib/page.rb",
|
48
52
|
"spec/common_spec.rb",
|
49
53
|
"spec/element/anchor_spec.rb",
|
50
54
|
"spec/element/base_spec.rb",
|
51
55
|
"spec/element/form_field_spec.rb",
|
52
56
|
"spec/element/form_spec.rb",
|
57
|
+
"spec/element/head_spec.rb",
|
53
58
|
"spec/element/image_spec.rb",
|
54
59
|
"spec/element/input_spec.rb",
|
60
|
+
"spec/element/list_item_spec.rb",
|
55
61
|
"spec/element/list_spec.rb",
|
56
|
-
"spec/element/listitem_spec.rb",
|
57
62
|
"spec/element/meta_spec.rb",
|
58
63
|
"spec/element/select_spec.rb",
|
64
|
+
"spec/element/table_row_spec.rb",
|
59
65
|
"spec/element/table_spec.rb",
|
60
66
|
"spec/element/textarea_spec.rb",
|
61
67
|
"spec/fixtures/node.html",
|
62
68
|
"spec/helper.rb",
|
63
|
-
"spec/node_spec.rb"
|
69
|
+
"spec/node_spec.rb",
|
70
|
+
"spec/page_spec.rb"
|
64
71
|
]
|
65
72
|
s.homepage = %q{http://github.com/andyw8/capybara-page-object}
|
66
73
|
s.licenses = [%q{MIT}]
|
data/lib/capybara-page-object.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'capybara'
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
2
|
+
require 'node'
|
3
|
+
require 'element'
|
4
|
+
require 'html5_data'
|
5
|
+
require 'page'
|
5
6
|
|
6
7
|
module Capybara
|
7
8
|
module Node
|
8
9
|
class Simple
|
9
|
-
include Extractor::PageLevel
|
10
10
|
include CapybaraPageObject::HTML5Data
|
11
11
|
end
|
12
12
|
end
|
data/lib/collections.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
module CapybaraPageObject
|
2
2
|
module Collections
|
3
|
-
def tables
|
4
|
-
|
3
|
+
def tables
|
4
|
+
all('table').each_with_object({}) do |e, hash|
|
5
|
+
t = CapybaraPageObject::Table.new(e)
|
6
|
+
hash[t.key] = t
|
7
|
+
end
|
5
8
|
end
|
6
9
|
|
7
|
-
def forms
|
8
|
-
|
10
|
+
def forms
|
11
|
+
all('form').each_with_object({}) do |e, hash|
|
12
|
+
f = CapybaraPageObject::Form.new(e)
|
13
|
+
hash[f.key] = f
|
14
|
+
end
|
9
15
|
end
|
10
16
|
end
|
11
|
-
end
|
17
|
+
end
|
data/lib/delegators.rb
ADDED
data/lib/element.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
1
|
+
require 'element/anchor'
|
2
|
+
require 'element/form'
|
3
|
+
require 'element/image'
|
4
|
+
require 'element/form_field'
|
5
|
+
require 'element/head'
|
6
|
+
require 'element/input'
|
7
|
+
require 'element/list'
|
8
|
+
require 'element/list_item'
|
9
|
+
require 'element/meta'
|
10
|
+
require 'element/select'
|
11
|
+
require 'element/table'
|
12
|
+
require 'element/table_row'
|
13
|
+
require 'element/table_header'
|
14
|
+
require 'element/textarea'
|
data/lib/element/TODO.md
ADDED
data/lib/element/anchor.rb
CHANGED
data/lib/element/form.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module CapybaraPageObject
|
2
2
|
class Form < CapybaraPageObject::Node
|
3
|
-
|
4
3
|
def fields
|
5
4
|
r = {}
|
6
5
|
r.merge! inputs
|
@@ -22,8 +21,8 @@ module CapybaraPageObject
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def respond_to?(sym)
|
25
|
-
|
26
|
-
|
24
|
+
fields.has_key?(sym.to_s) || super(sym)
|
25
|
+
end
|
27
26
|
|
28
27
|
def method_missing(sym, *args, &block)
|
29
28
|
return fields[sym.to_s] if fields.has_key?(sym.to_s)
|
@@ -33,17 +32,15 @@ module CapybaraPageObject
|
|
33
32
|
private
|
34
33
|
|
35
34
|
def inputs
|
36
|
-
|
37
|
-
all('input').each do |input_tag|
|
35
|
+
all('input').each_with_object do |input_tag, hash|
|
38
36
|
input = Input.new(input_tag)
|
39
37
|
next if input.button?
|
40
38
|
if input.checkable?
|
41
|
-
|
39
|
+
hash[input.key] = !! input.checked?
|
42
40
|
else
|
43
|
-
|
41
|
+
hash[input.key] = input_tag.value
|
44
42
|
end
|
45
43
|
end
|
46
|
-
r
|
47
44
|
end
|
48
45
|
|
49
46
|
def textareas
|
@@ -56,8 +53,7 @@ module CapybaraPageObject
|
|
56
53
|
def selects
|
57
54
|
all('select').inject({}) do |result, element|
|
58
55
|
select = Select.new(element)
|
59
|
-
|
60
|
-
result.merge select.key => element.value
|
56
|
+
result.merge select.key => select.value
|
61
57
|
end
|
62
58
|
end
|
63
59
|
end
|
data/lib/element/form_field.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
module CapybaraPageObject
|
2
2
|
class FormField < CapybaraPageObject::Node
|
3
|
-
|
4
3
|
def key
|
5
|
-
|
4
|
+
source[:name]
|
6
5
|
end
|
7
6
|
|
8
|
-
def
|
9
|
-
|
7
|
+
def value
|
8
|
+
source.value
|
10
9
|
end
|
11
10
|
|
12
11
|
def blank?
|
13
|
-
'' == value
|
14
|
-
end
|
15
|
-
|
16
|
-
def value
|
17
|
-
root_node.value
|
12
|
+
value.nil? || '' == value
|
18
13
|
end
|
19
14
|
end
|
20
15
|
end
|
data/lib/element/head.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module CapybaraPageObject
|
2
|
+
class Head < CapybaraPageObject::Node
|
3
|
+
def title
|
4
|
+
find('title').text
|
5
|
+
end
|
6
|
+
|
7
|
+
def meta_description
|
8
|
+
find('meta[@name="description"]')['content']
|
9
|
+
end
|
10
|
+
|
11
|
+
def meta_keywords
|
12
|
+
find('meta[@name="keywords"]')['content'].split(',').collect(&:strip)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/element/image.rb
CHANGED
@@ -1,20 +1,15 @@
|
|
1
1
|
module CapybaraPageObject
|
2
2
|
class Image < CapybaraPageObject::Node
|
3
|
-
|
4
|
-
def element_names
|
5
|
-
['img']
|
6
|
-
end
|
7
|
-
|
8
|
-
def alt
|
9
|
-
root_node[:alt].strip
|
10
|
-
end
|
11
|
-
|
12
3
|
def key
|
13
4
|
alt
|
14
5
|
end
|
15
|
-
|
6
|
+
|
16
7
|
def value
|
17
|
-
URI(
|
8
|
+
URI(source[:src])
|
9
|
+
end
|
10
|
+
|
11
|
+
def alt
|
12
|
+
source[:alt].strip
|
18
13
|
end
|
19
14
|
end
|
20
15
|
end
|
data/lib/element/input.rb
CHANGED
@@ -1,27 +1,22 @@
|
|
1
|
+
require 'element/text_based_input'
|
2
|
+
|
1
3
|
module CapybaraPageObject
|
2
|
-
class Input < CapybaraPageObject::
|
4
|
+
class Input < CapybaraPageObject::FormField
|
5
|
+
include TextBasedInput
|
3
6
|
|
4
7
|
BUTTON_TYPES = ['submit', 'reset', 'button']
|
5
8
|
CHECKABLE_TYPES = ['radio', 'checkbox']
|
6
9
|
|
7
|
-
def element_names
|
8
|
-
['input']
|
9
|
-
end
|
10
|
-
|
11
|
-
def key
|
12
|
-
root_node[:name]
|
13
|
-
end
|
14
|
-
|
15
10
|
def untyped?
|
16
|
-
|
11
|
+
source[:type].nil?
|
17
12
|
end
|
18
|
-
|
13
|
+
|
19
14
|
def button?
|
20
|
-
BUTTON_TYPES.include?(
|
15
|
+
BUTTON_TYPES.include?(source[:type])
|
21
16
|
end
|
22
17
|
|
23
18
|
def checkable?
|
24
|
-
type =
|
19
|
+
type = source[:type]
|
25
20
|
type && CHECKABLE_TYPES.include?(type)
|
26
21
|
end
|
27
22
|
end
|
data/lib/element/list.rb
CHANGED
@@ -1,21 +1,7 @@
|
|
1
1
|
module CapybaraPageObject
|
2
2
|
class List < CapybaraPageObject::Node
|
3
|
-
|
4
|
-
# TODO what about DL ?
|
5
|
-
def element_names
|
6
|
-
['ul', 'ol']
|
7
|
-
end
|
8
|
-
|
9
|
-
def child_node
|
10
|
-
'li'
|
11
|
-
end
|
12
|
-
|
13
3
|
def items(*args)
|
14
|
-
|
15
|
-
end
|
16
|
-
|
17
|
-
def key
|
18
|
-
root_node[:id]
|
4
|
+
all('li').map { |e| ListItem.new(e) }
|
19
5
|
end
|
20
6
|
end
|
21
7
|
end
|