watir-page-helper 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +24 -0
- data/.rspec +1 -0
- data/.rvmrc +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +20 -0
- data/README.md +88 -0
- data/Rakefile +6 -0
- data/features/README.md +47 -0
- data/features/simple_elements/README.md +13 -0
- data/features/simple_elements/div.feature +27 -0
- data/features/simple_elements/h1.feature +27 -0
- data/features/simple_elements/h2.feature +27 -0
- data/features/simple_elements/h3.feature +27 -0
- data/features/simple_elements/h4.feature +27 -0
- data/features/simple_elements/h5.feature +27 -0
- data/features/simple_elements/h6.feature +27 -0
- data/features/simple_elements/p.feature +27 -0
- data/features/simple_elements/span.feature +27 -0
- data/features/step_definitions/steps.rb +11 -0
- data/features/support/env.rb +32 -0
- data/history.md +10 -0
- data/lib/watir-page-helper.rb +231 -0
- data/lib/watir-page-helper/commands.rb +64 -0
- data/lib/watir-page-helper/generated.rb +388 -0
- data/script/generate +39 -0
- data/script/templates/generated.rb.erb +90 -0
- data/script/templates/simple_element.feature.erb +27 -0
- data/script/templates/test.html.erb +10 -0
- data/spec/example1.rb +19 -0
- data/spec/example2.rb +12 -0
- data/spec/helper.rb +12 -0
- data/spec/iframe.html +9 -0
- data/spec/image.png +0 -0
- data/spec/pages.rb +118 -0
- data/spec/test.html +103 -0
- data/spec/test.png +0 -0
- data/spec/watir-page-helper/pages/my_page.rb +9 -0
- data/spec/watir-page-helper/pages/nested_table_page.rb +8 -0
- data/spec/watir-page-helper_spec.rb +235 -0
- data/watir-page-helper.gemspec +35 -0
- metadata +189 -0
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# rubymine
|
18
|
+
.idea
|
19
|
+
|
20
|
+
# chromedriver
|
21
|
+
chromedriver.log
|
22
|
+
|
23
|
+
# generated by script/generate
|
24
|
+
features/support/test.html
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
watir-page-helper (1.0.3)
|
5
|
+
watir-webdriver
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: http://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.2)
|
11
|
+
builder (3.1.3)
|
12
|
+
childprocess (0.3.5)
|
13
|
+
ffi (~> 1.0, >= 1.0.6)
|
14
|
+
cucumber (1.2.1)
|
15
|
+
builder (>= 2.1.2)
|
16
|
+
diff-lcs (>= 1.1.3)
|
17
|
+
gherkin (~> 2.11.0)
|
18
|
+
json (>= 1.4.6)
|
19
|
+
diff-lcs (1.1.3)
|
20
|
+
ffi (1.1.5)
|
21
|
+
gherkin (2.11.2)
|
22
|
+
json (>= 1.4.6)
|
23
|
+
gherkin (2.11.2-x86-mingw32)
|
24
|
+
json (>= 1.4.6)
|
25
|
+
json (1.7.5)
|
26
|
+
libwebsocket (0.1.5)
|
27
|
+
addressable
|
28
|
+
multi_json (1.3.6)
|
29
|
+
rake (0.9.2.2)
|
30
|
+
rspec (2.11.0)
|
31
|
+
rspec-core (~> 2.11.0)
|
32
|
+
rspec-expectations (~> 2.11.0)
|
33
|
+
rspec-mocks (~> 2.11.0)
|
34
|
+
rspec-core (2.11.1)
|
35
|
+
rspec-expectations (2.11.3)
|
36
|
+
diff-lcs (~> 1.1.3)
|
37
|
+
rspec-mocks (2.11.2)
|
38
|
+
rubyzip (0.9.9)
|
39
|
+
selenium-webdriver (2.25.0)
|
40
|
+
childprocess (>= 0.2.5)
|
41
|
+
libwebsocket (~> 0.1.3)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
rubyzip
|
44
|
+
watir-webdriver (0.6.1)
|
45
|
+
selenium-webdriver (>= 2.18.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
x86-mingw32
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
cucumber
|
53
|
+
rake
|
54
|
+
rspec
|
55
|
+
watir-page-helper!
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Alister Scott & Mark Ryall
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
THIS GEM HAS BEEN DEPRECATED.
|
2
|
+
|
3
|
+
# watir-page-helper
|
4
|
+
|
5
|
+
This is a page helper for Watir-WebDriver that allows use easy access to elements, and a way to interactively create page objects.
|
6
|
+
|
7
|
+
## Example using Page Classes
|
8
|
+
|
9
|
+
Simply define a page such as:
|
10
|
+
|
11
|
+
require 'watir-webdriver'
|
12
|
+
require 'watir-page-helper/commands'
|
13
|
+
|
14
|
+
class MyPage < WatirPageHelper::Page
|
15
|
+
direct_url "http://www.google.com"
|
16
|
+
expected_element :text_field, :name => "q"
|
17
|
+
expected_title "Google"
|
18
|
+
text_field :search_box, :name => "q"
|
19
|
+
button :search, :name => "btnG"
|
20
|
+
end
|
21
|
+
|
22
|
+
include WatirPageHelper::Commands
|
23
|
+
|
24
|
+
WatirPageHelper.create
|
25
|
+
visit MyPage do |page|
|
26
|
+
page.search_box = "Watirmelon"
|
27
|
+
page.search
|
28
|
+
end
|
29
|
+
WatirPageHelper.close
|
30
|
+
|
31
|
+
## Example using Page Modules
|
32
|
+
|
33
|
+
First create a file under watir-page-helper/pages named my_page.rb
|
34
|
+
|
35
|
+
module WatirPageHelper::MyPage
|
36
|
+
extend WatirPageHelper::ClassMethods
|
37
|
+
|
38
|
+
direct_url "http://www.google.com"
|
39
|
+
expected_element :text_field, :name => "q"
|
40
|
+
expected_title "Google"
|
41
|
+
text_field :search_box, :name => "q"
|
42
|
+
button :search, :name => "btnG"
|
43
|
+
end
|
44
|
+
|
45
|
+
Now, you can simply use this page in your script
|
46
|
+
|
47
|
+
$: << File.dirname(__FILE__)
|
48
|
+
require 'watir-webdriver'
|
49
|
+
require 'watir-page-helper/commands'
|
50
|
+
|
51
|
+
include WatirPageHelper::Commands
|
52
|
+
|
53
|
+
WatirPageHelper.create
|
54
|
+
visit :my_page do |page|
|
55
|
+
page.search_box = "Watirmelon"
|
56
|
+
page.search
|
57
|
+
end
|
58
|
+
WatirPageHelper.close
|
59
|
+
|
60
|
+
|
61
|
+
## Main Methods that the Watir Page Helper provides
|
62
|
+
|
63
|
+
### Page Methods
|
64
|
+
* direct_url: allows you to navigate to a page upon initialization, if visit is set to true
|
65
|
+
* expected_title: allows you to automatically assert the expected title of the page when it is initialized
|
66
|
+
* expected_element: allows you to initialize the page by looking for a certain element. This is useful for pages that load dynamic content.
|
67
|
+
|
68
|
+
### Element Methods
|
69
|
+
* Element methods for a majority of the Watir-WebDriver supported elements which generate useful helper methods.
|
70
|
+
* For example: text_field, select_list, radio_button, form, div, span, h1..h6 etc.
|
71
|
+
|
72
|
+
## Credits
|
73
|
+
|
74
|
+
Thanks to Jeff Morgan: http://www.cheezyworld.com/ and Mark Ryall http://mark.ryall.name/blog/
|
75
|
+
|
76
|
+
## Contributing to watir-page-helper
|
77
|
+
|
78
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
79
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
80
|
+
* Fork the project
|
81
|
+
* Start a feature/bugfix branch
|
82
|
+
* Commit and push until you are happy with your contribution
|
83
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
84
|
+
* 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.
|
85
|
+
|
86
|
+
## Copyright
|
87
|
+
|
88
|
+
Copyright (c) 2011 Alister Scott & Mark Ryall. See LICENSE.txt for further details.
|
data/Rakefile
ADDED
data/features/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Watir Page Helper
|
2
|
+
|
3
|
+
This is a ruby gem that assists in creating page model
|
4
|
+
abstractions for maintainable browser automation.
|
5
|
+
|
6
|
+
It provides helper methods to allow expressive and easy access to elements.
|
7
|
+
|
8
|
+
# Example
|
9
|
+
|
10
|
+
Simply define a page such as:
|
11
|
+
|
12
|
+
require 'watir-webdriver'
|
13
|
+
require 'watir-page-helper'
|
14
|
+
|
15
|
+
class MyPage
|
16
|
+
include WatirPageHelper
|
17
|
+
|
18
|
+
direct_url 'http://www.google.com'
|
19
|
+
expected_element :text_field, :name => 'q'
|
20
|
+
expected_title 'Google'
|
21
|
+
text_field :search_box, :name => 'q'
|
22
|
+
button :search, :name => 'btnG'
|
23
|
+
|
24
|
+
def initialize browser, visit = false
|
25
|
+
@browser = browser
|
26
|
+
goto if visit
|
27
|
+
|
28
|
+
expected_element if respond_to? :expected_element
|
29
|
+
has_expected_title? if respond_to? :has_expected_title?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
This page can now be used in rspec specs, cucumber features or in isolation
|
34
|
+
|
35
|
+
browser = Watir::Browser.new :chrome
|
36
|
+
page = MyPage.new browser, true
|
37
|
+
page.search_box = 'Watirmelon' #This method is created by
|
38
|
+
WatirPageHelper
|
39
|
+
page.search #This method is created by WatirPageHelper also
|
40
|
+
browser.close
|
41
|
+
|
42
|
+
## Issues
|
43
|
+
|
44
|
+
This documentation is [open source](https://github.com/alisterscott/watir-page-helper/tree/master/features), and a work in progress. If you find it incomplete or confusing, please
|
45
|
+
[submit an issue](http://github.com/alisterscott/watir-page-helper/issues), or, better yet,
|
46
|
+
[a pull request](http://github.com/alisterscott/watir-page-helper).
|
47
|
+
|
@@ -0,0 +1,13 @@
|
|
1
|
+
Two helper methods are generated for simple elements (such as headings, spans):
|
2
|
+
|
3
|
+
* a *elementname* method to access the text contained by the element
|
4
|
+
* a *elementname*_*elementtype* method to access the actual watir element
|
5
|
+
|
6
|
+
For example, with the following page class definition:
|
7
|
+
|
8
|
+
class MyPage < BasePage
|
9
|
+
h1 :main_heading, :id => 'main_heading'
|
10
|
+
end
|
11
|
+
|
12
|
+
A `main_heading` method will be generated to access the h1 element with id main_heading and a
|
13
|
+
`main_heading_h1` method will be generated to access the watir element.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: div
|
2
|
+
As a web developer
|
3
|
+
I want to locate div elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithDIV < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
div :element, :id => 'div_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: div element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithDIV.new true
|
19
|
+
page.element_div.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: div text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithDIV.new true
|
26
|
+
page.element.should == 'div expected content'
|
27
|
+
"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: h1
|
2
|
+
As a web developer
|
3
|
+
I want to locate h1 elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithH1 < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
h1 :element, :id => 'h1_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: h1 element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithH1.new true
|
19
|
+
page.element_h1.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: h1 text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithH1.new true
|
26
|
+
page.element.should == 'h1 expected content'
|
27
|
+
"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: h2
|
2
|
+
As a web developer
|
3
|
+
I want to locate h2 elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithH2 < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
h2 :element, :id => 'h2_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: h2 element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithH2.new true
|
19
|
+
page.element_h2.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: h2 text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithH2.new true
|
26
|
+
page.element.should == 'h2 expected content'
|
27
|
+
"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: h3
|
2
|
+
As a web developer
|
3
|
+
I want to locate h3 elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithH3 < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
h3 :element, :id => 'h3_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: h3 element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithH3.new true
|
19
|
+
page.element_h3.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: h3 text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithH3.new true
|
26
|
+
page.element.should == 'h3 expected content'
|
27
|
+
"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: h4
|
2
|
+
As a web developer
|
3
|
+
I want to locate h4 elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithH4 < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
h4 :element, :id => 'h4_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: h4 element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithH4.new true
|
19
|
+
page.element_h4.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: h4 text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithH4.new true
|
26
|
+
page.element.should == 'h4 expected content'
|
27
|
+
"""
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: h5
|
2
|
+
As a web developer
|
3
|
+
I want to locate h5 elements
|
4
|
+
So that I can write tests that make assertions about their content
|
5
|
+
|
6
|
+
Background:
|
7
|
+
When I define a page class as:
|
8
|
+
"""
|
9
|
+
class PageWithH5 < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
h5 :element, :id => 'h5_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: h5 element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWithH5.new true
|
19
|
+
page.element_h5.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: h5 text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWithH5.new true
|
26
|
+
page.element.should == 'h5 expected content'
|
27
|
+
"""
|