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/script/generate
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
def path_to_template name
|
6
|
+
File.join Dir.pwd, "script/templates/#{name}.erb"
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_template name
|
10
|
+
template_content = File.read path_to_template(name)
|
11
|
+
template = ERB.new template_content, 0, "%<>"
|
12
|
+
yield template
|
13
|
+
end
|
14
|
+
|
15
|
+
simple_elements = %w{h1 h2 h3 h4 h5 h6 div span p}
|
16
|
+
texty_elements = simple_elements + %w{dl dd dt form li}
|
17
|
+
clicky_elements = %w{link button}
|
18
|
+
setty_elements = %w{text_field}
|
19
|
+
non_extended_elements = %w{table image frame}
|
20
|
+
|
21
|
+
with_template 'test.html' do |template|
|
22
|
+
File.open 'features/support/test.html', 'w' do |f|
|
23
|
+
f.puts template.result(binding)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
with_template 'simple_element.feature' do |template|
|
28
|
+
simple_elements.each do |element|
|
29
|
+
File.open "features/simple_elements/#{element}.feature", 'w' do |f|
|
30
|
+
f.puts template.result(binding)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
with_template 'generated.rb' do |template|
|
36
|
+
File.open 'lib/watir-page-helper/generated.rb', 'w' do |f|
|
37
|
+
f.puts template.result(binding)
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module WatirPageHelper
|
2
|
+
module ClassMethods
|
3
|
+
% texty_elements.each do |element|
|
4
|
+
|
5
|
+
# Generates two <%= element %> methods to:
|
6
|
+
# * return the text from a <%= element %>;
|
7
|
+
# * return the <%= element %> element.
|
8
|
+
#
|
9
|
+
# @param [Symbol] name The name of the <%= element %> element (used to generate the methods)
|
10
|
+
# @param [optional, Hash] identifier A set of key, value pairs to identify the element
|
11
|
+
# @param block
|
12
|
+
# @return [Nil]
|
13
|
+
#
|
14
|
+
# @example Specify a <%= element %> to generate methods
|
15
|
+
# <%= element %> :my_element, :id => "my_element"
|
16
|
+
# page.my_element.should == "My Element Text"
|
17
|
+
# page.my_element_<%= element %>.exist?.should be_true
|
18
|
+
def <%= element %> name, identifier=nil, &block
|
19
|
+
define_method(name) do
|
20
|
+
self.send("#{name}_<%= element %>").text
|
21
|
+
end
|
22
|
+
create_element_getter "#{name}_<%= element %>", identifier, __method__, block
|
23
|
+
end
|
24
|
+
% end
|
25
|
+
% clicky_elements.each do |element|
|
26
|
+
|
27
|
+
# Generates two <%= element %> methods to:
|
28
|
+
# * click a <%= element %>;
|
29
|
+
# * return the <%= element %> element.
|
30
|
+
#
|
31
|
+
# @param [Symbol] name The name of the <%= element %> element (used to generate the methods)
|
32
|
+
# @param [optional, Hash] identifier A set of key, value pairs to identify the element
|
33
|
+
# @param block
|
34
|
+
# @return [Nil]
|
35
|
+
#
|
36
|
+
# @example Specify a <%= element %> to generate methods
|
37
|
+
# <%= element %> :info, :text => "Information"
|
38
|
+
# page.info
|
39
|
+
# page.info_<%= element %>.exist?.should be_true
|
40
|
+
def <%= element %> name, identifier=nil, &block
|
41
|
+
define_method(name) do
|
42
|
+
self.send("#{name}_<%= element %>").click
|
43
|
+
end
|
44
|
+
create_element_getter "#{name}_<%= element %>", identifier, __method__, block
|
45
|
+
end
|
46
|
+
% end
|
47
|
+
% setty_elements.each do |element|
|
48
|
+
|
49
|
+
# Generates three <%= element %> methods to:
|
50
|
+
# * set a <%= element %>;
|
51
|
+
# * get a <%= element %>'s value; and
|
52
|
+
# * return the <%= element %> element.
|
53
|
+
#
|
54
|
+
# @param [Symbol] name The name of the <%= element %> element (used to generate the methods)
|
55
|
+
# @param [optional, Hash] identifier A set of key, value pairs to identify the element
|
56
|
+
# @param block
|
57
|
+
# @return [Nil]
|
58
|
+
#
|
59
|
+
# @example Specify a <%= element %> to generate methods
|
60
|
+
# <%= element %> first_name, :name => "firstname"
|
61
|
+
# page.first_name = "Finley" #set
|
62
|
+
# page.first_name.should == "Finley" #check
|
63
|
+
# page.first_name_<%= element %>.exists?.should be_true #object
|
64
|
+
def <%= element %> name, identifier=nil, &block
|
65
|
+
define_method(name) do
|
66
|
+
self.send("#{name}_<%= element %>").value
|
67
|
+
end
|
68
|
+
define_method("#{name}=") do |value|
|
69
|
+
self.send("#{name}_<%= element %>").set value
|
70
|
+
end
|
71
|
+
create_element_getter "#{name}_<%= element %>", identifier, __method__, block
|
72
|
+
end
|
73
|
+
% end
|
74
|
+
% non_extended_elements.each do |element|
|
75
|
+
|
76
|
+
# Generates a <%= element %> method to return a <%= element %> element.
|
77
|
+
# @param [Symbol] name The name of the <%= element %> element (used to generate the method)
|
78
|
+
# @param [optional, Hash] identifier A set of key, value pairs to identify the element
|
79
|
+
# @param block
|
80
|
+
# @return [Nil]
|
81
|
+
#
|
82
|
+
# @example Specify a <%= element %> to generate a method
|
83
|
+
# table :my_element, :id => 'my_element'
|
84
|
+
# page.my_element.exists?.should be_true
|
85
|
+
def <%= element %> name, identifier=nil, &block
|
86
|
+
create_element_getter "#{name}", identifier, __method__, block
|
87
|
+
end
|
88
|
+
% end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: <%= element %>
|
2
|
+
As a web developer
|
3
|
+
I want to locate <%= element %> 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 PageWith<%= element.upcase %> < BasePageClass
|
10
|
+
include WatirPageHelper
|
11
|
+
<%= element %> :element, :id => '<%= element %>_identifier'
|
12
|
+
end
|
13
|
+
"""
|
14
|
+
|
15
|
+
Scenario: <%= element %> element is located
|
16
|
+
Then I should be able to locate the element with the following code:
|
17
|
+
"""
|
18
|
+
page = PageWith<%= element.upcase %>.new true
|
19
|
+
page.element_<%= element %>.exists?.should be_true
|
20
|
+
"""
|
21
|
+
|
22
|
+
Scenario: <%= element %> text is extracted
|
23
|
+
Then I should be able to execute the following assertion:
|
24
|
+
"""
|
25
|
+
page = PageWith<%= element.upcase %>.new true
|
26
|
+
page.element.should == '<%= element %> expected content'
|
27
|
+
"""
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
</head>
|
4
|
+
<body>
|
5
|
+
% simple_elements.each do |element|
|
6
|
+
<<%= element %>><%= element %> unexpected content</<%= element %>>
|
7
|
+
<<%= element %> id="<%= element %>_identifier"><%= element %> expected content</<%= element %>>
|
8
|
+
% end
|
9
|
+
</body>
|
10
|
+
</html>
|
data/spec/example1.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'watir-webdriver'
|
2
|
+
require 'watir-page-helper/commands'
|
3
|
+
|
4
|
+
class MyPage < WatirPageHelper::Page
|
5
|
+
direct_url "http://www.google.com"
|
6
|
+
expected_element :text_field, :name => "q"
|
7
|
+
expected_title "Google"
|
8
|
+
text_field :search_box, :name => "q"
|
9
|
+
button :search, :name => "btnG"
|
10
|
+
end
|
11
|
+
|
12
|
+
include WatirPageHelper::Commands
|
13
|
+
|
14
|
+
WatirPageHelper.create
|
15
|
+
visit MyPage do |page|
|
16
|
+
page.search_box = "Watirmelon"
|
17
|
+
page.search
|
18
|
+
end
|
19
|
+
WatirPageHelper.close
|
data/spec/example2.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
require 'watir-webdriver'
|
3
|
+
require 'watir-page-helper/commands'
|
4
|
+
|
5
|
+
include WatirPageHelper::Commands
|
6
|
+
|
7
|
+
WatirPageHelper.create
|
8
|
+
visit :my_page do |page|
|
9
|
+
page.search_box = "Watirmelon"
|
10
|
+
page.search
|
11
|
+
end
|
12
|
+
WatirPageHelper.close
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'watir-page-helper'
|
6
|
+
require 'watir-page-helper/commands'
|
7
|
+
require 'watir-webdriver'
|
8
|
+
|
9
|
+
module CommonPage
|
10
|
+
include WatirPageHelper
|
11
|
+
direct_url "file://#{File.expand_path(File.dirname(__FILE__))}/test.html"
|
12
|
+
end
|
data/spec/iframe.html
ADDED
data/spec/image.png
ADDED
Binary file
|
data/spec/pages.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
class BaseTestPage < WatirPageHelper::Page
|
2
|
+
TEST_URL = "file://#{File.expand_path(File.dirname(__FILE__))}/test.html"
|
3
|
+
direct_url TEST_URL
|
4
|
+
end
|
5
|
+
|
6
|
+
class PageIncorrectTitle < BaseTestPage
|
7
|
+
expected_title "not expected"
|
8
|
+
end
|
9
|
+
|
10
|
+
class PageIncorrectTitleRegExp < BaseTestPage
|
11
|
+
expected_title /.*not expected.*/
|
12
|
+
end
|
13
|
+
|
14
|
+
class PageCorrectTitle < BaseTestPage
|
15
|
+
expected_title "HTML Document Title"
|
16
|
+
end
|
17
|
+
|
18
|
+
class PageCorrectTitleRegExp < BaseTestPage
|
19
|
+
expected_title /^HTML Document Title$/
|
20
|
+
end
|
21
|
+
|
22
|
+
class PageExpectElement < BaseTestPage
|
23
|
+
expected_element :text_field, :name => "firstname"
|
24
|
+
end
|
25
|
+
|
26
|
+
class PageExpectNonElement < BaseTestPage
|
27
|
+
expected_element(:text_field, {:name => "doesntexist"}, 1)
|
28
|
+
end
|
29
|
+
|
30
|
+
class PageTextFields < BaseTestPage
|
31
|
+
text_field :first_name, :name => "firstname"
|
32
|
+
end
|
33
|
+
|
34
|
+
class PageSelectList < BaseTestPage
|
35
|
+
select_list :cars, :name => "cars"
|
36
|
+
end
|
37
|
+
|
38
|
+
class PageCheckbox < BaseTestPage
|
39
|
+
checkbox :agree, :name => "agree"
|
40
|
+
end
|
41
|
+
|
42
|
+
class PageRadioButton < BaseTestPage
|
43
|
+
radio :medium, :value => "Medium"
|
44
|
+
end
|
45
|
+
|
46
|
+
class PageButton < BaseTestPage
|
47
|
+
button :submit, :value => "Submit"
|
48
|
+
end
|
49
|
+
|
50
|
+
class PageLink < BaseTestPage
|
51
|
+
link :info, :text => "Information Link"
|
52
|
+
end
|
53
|
+
|
54
|
+
class PageTable < BaseTestPage
|
55
|
+
table :test_table, :id => "myTable"
|
56
|
+
row :test_table_row_1
|
57
|
+
cell :test_table_row_1_cell_1
|
58
|
+
end
|
59
|
+
|
60
|
+
class PageDiv < BaseTestPage
|
61
|
+
div :information, :id => "myDiv"
|
62
|
+
end
|
63
|
+
|
64
|
+
class PageNestedDiv < BaseTestPage
|
65
|
+
div :my_nice_div, :id => 'myNiceDiv'
|
66
|
+
div(:my_unnamed_div) { |page| page.my_nice_div_div.div }
|
67
|
+
span(:my_unnamed_span) { |page| page.my_nice_div_div.span }
|
68
|
+
end
|
69
|
+
|
70
|
+
class PageNestedNoParams < BaseTestPage
|
71
|
+
div :my_nice_div, :id => 'myNiceDiv'
|
72
|
+
div(:my_unnamed_div) { my_nice_div_div.div }
|
73
|
+
span(:my_unnamed_span) { my_nice_div_div.span }
|
74
|
+
end
|
75
|
+
|
76
|
+
class PageSpan < BaseTestPage
|
77
|
+
span :background, :id => "mySpan"
|
78
|
+
end
|
79
|
+
|
80
|
+
class PageParagraph < BaseTestPage
|
81
|
+
p :paragraph, :id => "myP"
|
82
|
+
end
|
83
|
+
|
84
|
+
class PageDlDtDd < BaseTestPage
|
85
|
+
dl :definition_list, :id => "myDl"
|
86
|
+
dt(:definition_type) { | page | page.definition_list_dl.dt }
|
87
|
+
dd(:definition_data) { | page | page.definition_list_dl.dd }
|
88
|
+
end
|
89
|
+
|
90
|
+
class PageForm < BaseTestPage
|
91
|
+
form :main_form, :name => "myForm"
|
92
|
+
end
|
93
|
+
|
94
|
+
class PageImage < BaseTestPage
|
95
|
+
image :succulent_image, :id => "myImage"
|
96
|
+
end
|
97
|
+
|
98
|
+
class PageLi < BaseTestPage
|
99
|
+
li :blue_item, :id => "blueLi"
|
100
|
+
end
|
101
|
+
|
102
|
+
class PageHeadings < BaseTestPage
|
103
|
+
h1 :heading_one, :id => "myh1"
|
104
|
+
h2 :heading_two, :id => "myh2"
|
105
|
+
h3 :heading_three, :id => "myh3"
|
106
|
+
h4 :heading_four, :id => "myh4"
|
107
|
+
h5 :heading_five, :id => "myh5"
|
108
|
+
h6 :heading_six, :id => "myh6"
|
109
|
+
end
|
110
|
+
|
111
|
+
class PageIFrame < BaseTestPage
|
112
|
+
frame :iframe, :id => "myiframe"
|
113
|
+
link(:ilink) { |page| page.iframe.link(:text => 'Link in an iFrame') }
|
114
|
+
end
|
115
|
+
|
116
|
+
class PageFileField < BaseTestPage
|
117
|
+
file_field :upload, :id => 'upload'
|
118
|
+
end
|
data/spec/test.html
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title>HTML Document Title</title>
|
4
|
+
</head>
|
5
|
+
<body>
|
6
|
+
<a href="">Information Link</a>
|
7
|
+
<div style="color:#00FF00" id="myDiv">
|
8
|
+
<h3>This is a header</h3>
|
9
|
+
<p id="myP">This is a paragraph.</p>
|
10
|
+
</div>
|
11
|
+
<span id="mySpan">Some background text in a span.</span><br />
|
12
|
+
<div id="myNiceDiv">
|
13
|
+
<div>This div is unnamed and inside myNiceDiv.</div>
|
14
|
+
<span>This span is unnamed and inside myNiceDiv.</span>
|
15
|
+
</div>
|
16
|
+
<dl id="myDl">
|
17
|
+
<dt>Succulents</dt>
|
18
|
+
<dd>- water-retaining plants adapted to arid climates or soil conditions.</dd>
|
19
|
+
<dt>Cactus</dt>
|
20
|
+
<dd>- plants who distinctive appearance is a result of adaptations to conserve water in dry and/or hot environments.</dd>
|
21
|
+
</dl>
|
22
|
+
|
23
|
+
<form action="" name="myForm">
|
24
|
+
First name: <label>
|
25
|
+
<input type="text" name="firstname"/>
|
26
|
+
</label><br/>
|
27
|
+
Last name: <label>
|
28
|
+
<input type="text" name="lastname"/>
|
29
|
+
</label><br/>
|
30
|
+
Car model: <label>
|
31
|
+
<select name="cars">
|
32
|
+
<option value="Honda">Honda</option>
|
33
|
+
<option value="Mazda">Mazda</option>
|
34
|
+
<option value="Toyota">Toyota</option>
|
35
|
+
</select>
|
36
|
+
</label><br/>
|
37
|
+
Do you agree?: <label>
|
38
|
+
<input type="checkbox" name="agree">
|
39
|
+
</label>I agree<br/>
|
40
|
+
<label>
|
41
|
+
<input type="radio" name="group1" value="High">
|
42
|
+
</label>High<br>
|
43
|
+
<label>
|
44
|
+
<input type="radio" name="group1" value="Medium">
|
45
|
+
</label>Medium<br>
|
46
|
+
<label>
|
47
|
+
<input type="radio" name="group1" value="Low">
|
48
|
+
</label>Low<br/>
|
49
|
+
<input type="file" id="upload"/>
|
50
|
+
<input type="submit" value="Submit"/>
|
51
|
+
</form>
|
52
|
+
<table id="myTable" border="6">
|
53
|
+
<tr>
|
54
|
+
<td>
|
55
|
+
Test Table Col 1
|
56
|
+
</td>
|
57
|
+
<td>
|
58
|
+
Test Table Col 2
|
59
|
+
</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
<table id="mySecondTable" border="6">
|
63
|
+
<tr>
|
64
|
+
<td>
|
65
|
+
Test Table 2 Col 1
|
66
|
+
</td>
|
67
|
+
<td>
|
68
|
+
Test Table 2 Col 2
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
<br>
|
73
|
+
<ol id="myOl">
|
74
|
+
<li id="greenLi">
|
75
|
+
Green
|
76
|
+
</li>
|
77
|
+
<li id="redLi">
|
78
|
+
Red
|
79
|
+
</li>
|
80
|
+
<li id=blueLi>
|
81
|
+
Blue
|
82
|
+
</li>
|
83
|
+
</ol>
|
84
|
+
<br>
|
85
|
+
<h1 id="myh1">Heading One</h1>
|
86
|
+
<h2 id="myh2">Heading Two</h2>
|
87
|
+
<h3 id="myh3">Heading Three</h3>
|
88
|
+
<h4 id="myh4">Heading Four</h4>
|
89
|
+
<h5 id="myh5">Heading Five</h5>
|
90
|
+
<h6 id="myh6">Heading Six</h6>
|
91
|
+
<br>
|
92
|
+
<img src="test.png" alt="Succulents" id="myImage" />
|
93
|
+
|
94
|
+
<html>
|
95
|
+
<body>
|
96
|
+
<p>TEST IFRAME ISSUES</p>
|
97
|
+
<iframe src="iframe.html" id="myiframe" width="100%" height="200px">
|
98
|
+
</iframe>
|
99
|
+
</body>
|
100
|
+
</html>
|
101
|
+
|
102
|
+
</body>
|
103
|
+
</html>
|