test-page 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -2
- data/.yardopts +1 -1
- data/CHANGES.md +3 -0
- data/LICENSE +2 -2
- data/README.md +48 -52
- data/Rakefile +1 -0
- data/examples/selenium/results_page.rb +1 -5
- data/examples/selenium/search_spec.rb +1 -1
- data/examples/watir/results_page.rb +1 -5
- data/examples/watir/search_spec.rb +1 -1
- data/lib/test/page.rb +0 -49
- data/lib/test/page/version.rb +1 -1
- data/spec/test/page_spec.rb +0 -43
- metadata +16 -28
- data/.coveralls.yml +0 -1
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 590ee0360bc5ef1d9d852b0c0351d29443a672ce
|
4
|
+
data.tar.gz: 5c33ccb11cc3a03b46068d4aac54ad2da31dfe93
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fd0d9b76762ea5586518f0a2dbf3dcf5f729ee5f49782abaec7d3c7e87d72fd0ccce118e8eb24177a5b2d923b77fe073a43accbef581db52b06dd94a734ff3b5
|
7
|
+
data.tar.gz: 595da631110d6fcadda2336569f39afd0e3ba45e158ed48d73ebe0e68567a48901777a0de24874042d6c217e5dd35f556509f93b84a61fd8ef23c07414f12dcc
|
data/.travis.yml
CHANGED
data/.yardopts
CHANGED
data/CHANGES.md
ADDED
data/LICENSE
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2012 Jarmo Pertman
|
1
|
+
Copyright (c) 2012-2013 Jarmo Pertman
|
2
2
|
|
3
3
|
MIT License
|
4
4
|
|
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
19
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
20
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
21
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Test::Page
|
2
|
-
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/test-page.png)](http://badge.fury.io/rb/test-page)
|
3
3
|
[![Build Status](https://secure.travis-ci.org/jarmo/test-page.png)](http://travis-ci.org/jarmo/test-page)
|
4
4
|
[![Coverage](https://coveralls.io/repos/jarmo/test-page/badge.png?branch=master)](https://coveralls.io/r/jarmo/test-page)
|
5
5
|
[![Dependency Status](https://gemnasium.com/jarmo/test-page.png)](https://gemnasium.com/jarmo/test-page)
|
6
|
-
[![Code
|
6
|
+
[![Code Climate](https://codeclimate.com/github/jarmo/test-page.png)](https://codeclimate.com/github/jarmo/test-page)
|
7
7
|
|
8
8
|
Test::Page helps you to write easily maintainable integration tests by implementing [Page Objects](https://code.google.com/p/selenium/wiki/PageObjects) pattern.
|
9
9
|
|
@@ -38,66 +38,62 @@ you like.
|
|
38
38
|
[Check out Selenium example](https://github.com/jarmo/test-page/tree/master/examples) instead, if that's your flavor of choice.
|
39
39
|
|
40
40
|
This is the spec we are trying to run:
|
41
|
+
```ruby
|
42
|
+
# spec/search_spec.rb
|
43
|
+
require "test/page"
|
44
|
+
require "watir"
|
45
|
+
require File.expand_path("search_page", File.dirname(__FILE__))
|
41
46
|
|
42
|
-
|
43
|
-
|
44
|
-
require "test/page"
|
45
|
-
require "watir"
|
46
|
-
require File.expand_path("search_page", File.dirname(__FILE__))
|
47
|
-
|
48
|
-
describe "Bing" do
|
47
|
+
describe "Bing" do
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
let(:browser) { Watir::Browser.new }
|
50
|
+
let(:search_page) { SearchPage.new }
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
52
|
+
before { Test::Page.browser = browser }
|
53
|
+
after { browser.close }
|
54
|
+
|
55
|
+
it "finds Google" do
|
56
|
+
results_page = search_page.search "google"
|
57
|
+
results_page.should have(10).results
|
58
|
+
results_page.results[0].should =~ /google/i
|
59
|
+
end
|
60
|
+
|
61
|
+
it "finds Bing itself" do
|
62
|
+
results_page = search_page.search "bing"
|
63
|
+
results_page.results.should be_any { |result| result =~ /Bing/ }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
67
|
|
68
68
|
Let's create the SearchPage object:
|
69
|
+
```ruby
|
70
|
+
# spec/support/page/search_page.rb
|
71
|
+
require File.expand_path("results_page", File.dirname(__FILE__))
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
require File.expand_path("results_page", File.dirname(__FILE__))
|
73
|
+
class SearchPage < Test::Page
|
74
|
+
element { browser.div(:id => "sbox") }
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
+
def setup
|
77
|
+
browser.goto "http://bing.com"
|
78
|
+
end
|
76
79
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
redirect_to ResultsPage, browser.ul(:id => "wg0")
|
85
|
-
end
|
86
|
-
end
|
80
|
+
def search(term)
|
81
|
+
text_field(:id => "sb_form_q").set term
|
82
|
+
button(:id => "sb_form_go").click
|
83
|
+
redirect_to ResultsPage, browser.ul(:id => "wg0")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
87
|
|
88
88
|
Let's create the ResultsPage object:
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
results.any? { |result| result =~ regexp }
|
98
|
-
}
|
99
|
-
end
|
100
|
-
end
|
89
|
+
```ruby
|
90
|
+
# spec/support/page/results_page.rb
|
91
|
+
class ResultsPage < Test::Page
|
92
|
+
def results
|
93
|
+
lis(:class => "sa_wr").map(&:text)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
```
|
101
97
|
|
102
98
|
There you have it, a fully functional spec using two page objects. Reference to the
|
103
99
|
[API documentation](http://rubydoc.info/github/jarmo/test-page/frames) for more usage information.
|
data/Rakefile
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
class ResultsPage < Test::Page
|
2
2
|
def results
|
3
|
-
|
4
|
-
:include? => proc { |term|
|
5
|
-
regexp = Regexp.new Regexp.escape term
|
6
|
-
results.any? {|result| result =~ regexp}
|
7
|
-
}
|
3
|
+
find_elements(:class => "sa_wr").map(&:text)
|
8
4
|
end
|
9
5
|
end
|
data/lib/test/page.rb
CHANGED
@@ -75,55 +75,6 @@ module Test
|
|
75
75
|
@element = element
|
76
76
|
end
|
77
77
|
|
78
|
-
# Add or modify element instance methods.
|
79
|
-
#
|
80
|
-
# When element does not have the specified method then that method will be
|
81
|
-
# added to the specific element instance.
|
82
|
-
# When element has specified method it will be invoked before invoking the
|
83
|
-
# specified method.
|
84
|
-
#
|
85
|
-
# @example Add #png? method to Watir::Image
|
86
|
-
# class Gallery < Test::Page
|
87
|
-
# def thumbnail
|
88
|
-
# image = img(:id => "thumbnail")
|
89
|
-
# modify image,
|
90
|
-
# :png? => proc { File.extname(image.src).downcase == ".png" }
|
91
|
-
# end
|
92
|
-
# end
|
93
|
-
#
|
94
|
-
# Gallery.new.thumbnail.png? # returns true for images, which have
|
95
|
-
# # the src attribute set to png.
|
96
|
-
#
|
97
|
-
# @example Modify Watir::Button#click to return new MainPage instance after click
|
98
|
-
# class LoginForm < Test::Page
|
99
|
-
# def login_button
|
100
|
-
# modify button(:id => "login"),
|
101
|
-
# :click => proc { redirect_to MainPage }
|
102
|
-
# end
|
103
|
-
# end
|
104
|
-
#
|
105
|
-
# LoginForm.new.login_button.click # performs the click and returns
|
106
|
-
# # a new MainPage instance.
|
107
|
-
#
|
108
|
-
# @param [Object] Element element to modify.
|
109
|
-
# @param [Hash<Symbol,Proc>] Hash of method name as a Symbol and body as a Proc pairs.
|
110
|
-
#
|
111
|
-
# @return [Object] Modified Element instance.
|
112
|
-
def modify(element, methods)
|
113
|
-
methods.each_pair do |meth, return_value|
|
114
|
-
element.instance_eval do
|
115
|
-
singleton = class << self; self end
|
116
|
-
|
117
|
-
singleton.send :alias_method, "__#{meth}", meth if respond_to? meth
|
118
|
-
singleton.send :define_method, meth do |*args|
|
119
|
-
self.send("__#{meth}", *args) if respond_to? "__#{meth}"
|
120
|
-
return_value.call(*args)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
element
|
125
|
-
end
|
126
|
-
|
127
78
|
# Create new {Page} object conveniently on page actions.
|
128
79
|
#
|
129
80
|
# @param [Page] Page page class to make an instance of
|
data/lib/test/page/version.rb
CHANGED
data/spec/test/page_spec.rb
CHANGED
@@ -93,49 +93,6 @@ describe Test::Page do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
-
context "#modify" do
|
97
|
-
let(:modified_page_class) do
|
98
|
-
page_class.send :define_method, :something do
|
99
|
-
modify Hash.new,
|
100
|
-
:action => proc { "hi" },
|
101
|
-
:store => proc { |a, b| a + b }
|
102
|
-
end
|
103
|
-
page_class
|
104
|
-
end
|
105
|
-
|
106
|
-
it "returns the instance of the original object" do
|
107
|
-
page = modified_page_class.new
|
108
|
-
page.something.should == {}
|
109
|
-
end
|
110
|
-
|
111
|
-
it "allows to modify default behavior of the instance's methods" do
|
112
|
-
page = modified_page_class.new
|
113
|
-
page.something.store(1, 2).should == 3
|
114
|
-
end
|
115
|
-
|
116
|
-
it "executes the original instance method too" do
|
117
|
-
page = modified_page_class.new
|
118
|
-
result = page.something
|
119
|
-
result.store 1, 2
|
120
|
-
result.should == {1 => 2}
|
121
|
-
end
|
122
|
-
|
123
|
-
it "modifies only singleton instance methods, leaving original class intact" do
|
124
|
-
page = modified_page_class.new
|
125
|
-
result = page.something
|
126
|
-
result.store(1, 2).should == 3
|
127
|
-
|
128
|
-
original_hash = Hash.new
|
129
|
-
original_hash.store(1, 2).should == 2
|
130
|
-
original_hash.should == {1 => 2}
|
131
|
-
end
|
132
|
-
|
133
|
-
it "allows to add new methods too" do
|
134
|
-
page = modified_page_class.new
|
135
|
-
page.something.action.should == "hi"
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
96
|
context "#redirect_to" do
|
140
97
|
it "returns the new page instance" do
|
141
98
|
second_page = Class.new(Test::Page)
|
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-page
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jarmo Pertman
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,65 +27,57 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: simplecov
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: yard
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: redcarpet
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - '>='
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - '>='
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rake
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - '>='
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - '>='
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '0'
|
94
83
|
description: Test::Page helps you to write easily maintainable integration tests by
|
@@ -99,11 +88,11 @@ executables: []
|
|
99
88
|
extensions: []
|
100
89
|
extra_rdoc_files: []
|
101
90
|
files:
|
102
|
-
- .coveralls.yml
|
103
91
|
- .gitignore
|
104
92
|
- .rspec
|
105
93
|
- .travis.yml
|
106
94
|
- .yardopts
|
95
|
+
- CHANGES.md
|
107
96
|
- Gemfile
|
108
97
|
- LICENSE
|
109
98
|
- README.md
|
@@ -121,27 +110,26 @@ files:
|
|
121
110
|
- test-page.gemspec
|
122
111
|
homepage: https://github.com/jarmo/test-page
|
123
112
|
licenses: []
|
113
|
+
metadata: {}
|
124
114
|
post_install_message:
|
125
115
|
rdoc_options: []
|
126
116
|
require_paths:
|
127
117
|
- lib
|
128
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
119
|
requirements:
|
131
|
-
- -
|
120
|
+
- - '>='
|
132
121
|
- !ruby/object:Gem::Version
|
133
122
|
version: '0'
|
134
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
-
none: false
|
136
124
|
requirements:
|
137
|
-
- -
|
125
|
+
- - '>='
|
138
126
|
- !ruby/object:Gem::Version
|
139
127
|
version: '0'
|
140
128
|
requirements: []
|
141
129
|
rubyforge_project:
|
142
|
-
rubygems_version:
|
130
|
+
rubygems_version: 2.0.7
|
143
131
|
signing_key:
|
144
|
-
specification_version:
|
132
|
+
specification_version: 4
|
145
133
|
summary: Test::Page helps you to write easily maintainable integration tests by using
|
146
134
|
Watir, Selenium or any other testing library.
|
147
135
|
test_files:
|
data/.coveralls.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
repo_token: DTKokhL9P3koXfPLu8BRED4PdWPc5kFQg
|