test-factory 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/lib/test-factory/page_factory.rb +46 -4
- data/lib/test-factory/string_factory.rb +10 -0
- data/test-factory.gemspec +1 -1
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# The PageFactory class provides a set of methods that allow the rapid creation of page element definitions--known
|
2
|
+
# colloquially as "page objects". These elements are defined using Watir syntax. Please see www.watir.com if you are
|
3
|
+
# not familiar with Watir.
|
1
4
|
class PageFactory
|
2
5
|
|
3
6
|
# As the PageFactory will be the superclass for all your page classes, having this initialize
|
@@ -10,7 +13,8 @@ class PageFactory
|
|
10
13
|
end
|
11
14
|
|
12
15
|
# Catches any "missing" methods and passes them to the browser object--which means
|
13
|
-
# that Watir will take care of parsing them
|
16
|
+
# that Watir will take care of parsing them, so the assumption is that the method being
|
17
|
+
# passed is a valid method for the browser object.
|
14
18
|
def method_missing sym, *args, &block
|
15
19
|
@browser.send sym, *args, &block
|
16
20
|
end
|
@@ -61,8 +65,8 @@ class PageFactory
|
|
61
65
|
# Methods that take one or more parameters can be built with this as well.
|
62
66
|
#
|
63
67
|
# @example
|
64
|
-
# action(:continue) { |b| b.frm.button(:value=>"Continue").click }
|
65
|
-
# action(:select_style) { |stylename, b| b.div(:text=>/#{Regexp.escape(stylename)}/).link(:text=>"Select").click }
|
68
|
+
# action(:continue) { |b| b.frm.button(:value=>"Continue").click } #=> Creates a #continue method that clicks the Continue button
|
69
|
+
# action(:select_style) { |stylename, b| b.div(:text=>/#{Regexp.escape(stylename)}/).link(:text=>"Select").click } #=> #select_style(stylename)
|
66
70
|
#
|
67
71
|
def action method_name, &block
|
68
72
|
define_method method_name.to_s do |*thing|
|
@@ -70,6 +74,44 @@ class PageFactory
|
|
70
74
|
end
|
71
75
|
end
|
72
76
|
|
77
|
+
# Use this for links that are safe to define by their text string.
|
78
|
+
# This method will return two methods for interacting with the link:
|
79
|
+
# one that refers to the link itself, and one that clicks on it.
|
80
|
+
# Since it's assumed that the most common thing done with a link is to click it,
|
81
|
+
# the method for clicking it will be named according to the text of the link,
|
82
|
+
# and the method for the link itself will have "_link" appended to it. Any special
|
83
|
+
# characters are stripped from the string. Capital letters are made lower case.
|
84
|
+
# And spaces and dashes are converted to underscores.
|
85
|
+
#
|
86
|
+
# @example
|
87
|
+
# link("Click Me For Fun!") #=> Creates the methods #click_me_for_fun and #click_me_for_fun_link
|
88
|
+
def link(link_text)
|
89
|
+
element(damballa(link_text+"_link")) { |b| b.link(:text=>link_text) }
|
90
|
+
action(damballa(link_text)) { |b| b.frm.link(:text=>link_text).click }
|
91
|
+
end
|
92
|
+
|
93
|
+
# Use this for buttons that are safe to define by their value attribute.
|
94
|
+
# This method will return two methods for interacting with the button:
|
95
|
+
# one that refers to the button itself, and one that clicks on it.
|
96
|
+
# Since it's assumed that the most common thing done with a button is to click it,
|
97
|
+
# the method for clicking it will be named according to the value of the button,
|
98
|
+
# and the method for the button itself will have "_button" appended to it. Any special
|
99
|
+
# characters are stripped from the string. Capital letters are made lower case.
|
100
|
+
# And spaces and dashes are converted to underscores.
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# button("Click Me For Fun!") #=> Creates the methods #click_me_for_fun and #click_me_for_fun_button
|
104
|
+
def button(button_text)
|
105
|
+
element(damballa(button_text+"_button")) { |b| b.button(:value=>button_text) }
|
106
|
+
action(damballa(button_text)) { |b| b.frm.button(:value=>button_text).click }
|
107
|
+
end
|
108
|
+
|
109
|
+
# A helper method that converts the passed string into snake case. See the StringFactory
|
110
|
+
# module for more info.
|
111
|
+
def damballa(text)
|
112
|
+
StringFactory::damballa(text)
|
113
|
+
end
|
114
|
+
|
73
115
|
end
|
74
116
|
|
75
|
-
end #
|
117
|
+
end # PageFactory
|
@@ -118,4 +118,14 @@ module StringFactory
|
|
118
118
|
"#"+("%06x" % (rand * 0xffffff)).upcase
|
119
119
|
end
|
120
120
|
|
121
|
+
# Converts a string to a symbol made up of snake case. Spaces and dashes are changed to underscore. Special characters are removed.
|
122
|
+
# @example
|
123
|
+
# damballa("A String of Fun Stuff (for you)") => :a_string_of_fun_stuff_for_you
|
124
|
+
def self.damballa(text)
|
125
|
+
text.gsub(/([+=|\\\.~@#'"\?`!\{\}\[\]\$%\^&\*\(\)])/, "").
|
126
|
+
gsub(/([-\/\ ])/,"_").
|
127
|
+
downcase.
|
128
|
+
to_sym
|
129
|
+
end
|
130
|
+
|
121
131
|
end
|
data/test-factory.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
spec = Gem::Specification.new do |s|
|
2
2
|
s.name = 'test-factory'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.9'
|
4
4
|
s.summary = %q{rSmart's framework for creating automated testing scripts}
|
5
5
|
s.description = %q{This gem provides a set of modules and methods to help quickly and DRYly create a test automation framework using Ruby and Watir (or watir-webdriver).}
|
6
6
|
s.files = Dir.glob("**/**/**")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-factory
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11
|
12
|
+
date: 2012-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: watir-webdriver
|