gondola 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -24,7 +24,7 @@ Jeweler::Tasks.new do |gem|
24
24
  }
25
25
  gem.email = "mperry@agoragames.com"
26
26
  gem.authors = ["Matthew Perry"]
27
- gem.version = Gondola::Version::STRING
27
+ gem.version = Gondola::VERSION
28
28
  # Dependencies in GemFile
29
29
  end
30
30
  Jeweler::RubygemsDotOrgTasks.new
@@ -53,7 +53,7 @@ task :default => :test
53
53
 
54
54
  require 'rake/rdoctask'
55
55
  Rake::RDocTask.new do |rdoc|
56
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
56
+ version = File.exist?('VERSION') ? File.read('VERSION') : Gondola::VERSION
57
57
 
58
58
  rdoc.rdoc_dir = 'rdoc'
59
59
  rdoc.title = "gondola #{version}"
data/bin/gondola CHANGED
@@ -16,7 +16,7 @@ require 'gondola'
16
16
  # Command parsing stuff
17
17
  cmd = CmdParse::CommandParser.new(true, true)
18
18
  cmd.program_name = "gondola"
19
- cmd.program_version = Gondola::Version::STRING
19
+ cmd.program_version = Gondola::VERSION
20
20
  cmd.add_command(CmdParse::HelpCommand.new)
21
21
  cmd.add_command(CmdParse::VersionCommand.new)
22
22
 
@@ -34,9 +34,6 @@ class RunCommand < CmdParse::Command
34
34
  opt.on('-r', '--recursive', 'Execute all sub suites') do |r|
35
35
  @opts[:recursive] = true
36
36
  end
37
- opt.on('-l', '--legacy', 'Allow legacy Gondola suites') do |l|
38
- @opts[:legacy] = true
39
- end
40
37
  end
41
38
  end
42
39
 
data/gondola.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gondola}
8
- s.version = "1.1.3"
8
+ s.version = "1.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Matthew Perry"]
@@ -37,6 +37,8 @@ Gem::Specification.new do |s|
37
37
  "gondola.gemspec",
38
38
  "lib/gondola.rb",
39
39
  "lib/gondola/converter.rb",
40
+ "lib/gondola/html_converter.rb",
41
+ "lib/gondola/legacy_converter.rb",
40
42
  "lib/gondola/tester.rb",
41
43
  "lib/gondola/testrunner.rb",
42
44
  "lib/gondola/version.rb",
@@ -1,13 +1,13 @@
1
1
  # Gondola - converter.rb:
2
- # Function definition for turning Selenium HTML into
3
- # webdriver ruby code
2
+ # Class definition for turning one format into
3
+ # another
4
4
 
5
5
  module Gondola
6
6
  class Converter
7
- # Constructor that opens an HTML file
7
+ # Constructor that opens a file
8
8
  def initialize(filename, sel="@sel")
9
9
  File.open(filename, "r") do |f|
10
- @html = f.read
10
+ @body = f.read
11
11
  end
12
12
  @s_obj = sel
13
13
  ruby()
@@ -17,197 +17,19 @@ module Gondola
17
17
  # Returns the name of this test case
18
18
  def name
19
19
  unless @name
20
- @name = /<title>(.*)<\/title>/.match(@html)[1]
20
+ @name = "Abstract Converter"
21
21
  end
22
22
  @name
23
23
  end
24
24
 
25
25
  # Function: ruby
26
- # This function parses the selenium
27
- # HTML file and sends commands to the
28
- # html_to_ruby helper function
26
+ # This function parses the given file
27
+ # and returns valid selenium ruby code
29
28
  def ruby
30
29
  unless @ruby
31
- @ruby = ""
32
- # Get body of commands from flattened html
33
- cmd_body = /<tbody>(.*)<\/tbody>/.match(@html.split("\n").join(''))[1]
34
-
35
- # Define some patterns for the individual commands
36
- block_rxp = Regexp.new(/<tr>(.*?)<\/tr>/)
37
- cmd_rxp = Regexp.new(/<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>/)
38
-
39
- # Loop over all commands
40
- cmd_body.scan(block_rxp ) do |cmd_block|
41
- cmd_block[0].scan(cmd_rxp ) do |cmd|
42
- # Need to make sure arguements are represented
43
- # correctly
44
- if cmd[1] =~ /\$\{(.*)\}/
45
- cmd[1] = $1
46
- elsif cmd[1] != ""
47
- cmd[1] = cmd[1].inspect
48
- end
49
- if cmd[2] =~ /\$\{(.*)\}/
50
- cmd[2] = $1
51
- elsif cmd[2] != ""
52
- cmd[2] = cmd[2].inspect
53
- end
54
- # Append commands to a result string
55
- args = [ cmd[1], cmd[2] ]
56
- @ruby << html_to_ruby(cmd[0], args)
57
- @ruby << "\ncmd_inc\n"
58
- end
59
- end
30
+ @ruby = "puts 'This is an abstract converter, do not use this.'"
60
31
  end
61
32
  @ruby
62
33
  end
63
-
64
- private
65
- # Function: html_to_ruby
66
- # cmd - the name of the command
67
- # args - array of arguements to cmd
68
- # This function turns a command that has been
69
- # extracted from a selenium HTML file into
70
- # one that can be used by the ruby-driver for
71
- # selenium
72
- def html_to_ruby(cmd, args)
73
- # Select over various command types
74
- case cmd
75
- # Assert command
76
- when /^(assert|verify)(.*)$/ then
77
- # Check to see if this is a negated assertion
78
- tester = $1
79
- string = $2
80
- if $1 =~ /(.*)Not(.*)$/
81
- string = $1 + $2
82
- tester = tester + "_not"
83
- end
84
-
85
- # Check the semantics of the command
86
- if semantic_is?(string)
87
- retval = "#{tester} #{@s_obj}.is_#{underscore(string)}"
88
- if args[0] != ""
89
- retval += "(#{args[0]}"
90
- end
91
- if args[1] != ""
92
- retval += ", #{args[1]}"
93
- end
94
- retval += ")"
95
- else
96
- var = args[0]
97
- extra = ''
98
- if args[1] != ""
99
- var = args[1]
100
- extra = "(#{args[0]})"
101
- end
102
- retval = "#{tester}_eq #{var}, #{@s_obj}.get_#{underscore(string)}" + extra
103
- end
104
-
105
- # All commands return arrays that need to be joined
106
- if string =~ /^All/
107
- retval += ".join(\",\")"
108
- end
109
- return retval
110
-
111
- # Wait For command
112
- when /^waitFor(.*)$/ then
113
- # Special case
114
- if $1 == "PageToLoad"
115
- return "#{@s_obj}.wait_for_page_to_load \"30000\""
116
- end
117
- # The expression that is checked against depends on whether
118
- # or not the command uses the "is" or the "get" semantic
119
- if semantic_is?($1)
120
- expression = "#{@s_obj}.is_#{underscore($1)}(#{args[0]}"
121
- if args[1] != ""
122
- expression += ", #{args[1]}"
123
- end
124
- expression += ")"
125
- else
126
- expression = "#{args[1]} == #{@s_obj}.get_#{underscore($1)}(#{args[1]})"
127
- end
128
- # The waitFor commands loop until something is satisfied
129
- return "assert !60.times{ break if(#{expression} rescue false); sleep 1 }"
130
-
131
- # AndWait command POSTFIX
132
- when /^(.*)AndWait$/ then
133
- # A command with a postfix of AndWait simply adds
134
- # a second command which waits a certain time
135
- firstPart = html_to_ruby($1, args)
136
- secondPart = "\n#{@s_obj}.wait_for_page_to_load \"30000\""
137
- return firstPart + secondPart
138
-
139
- # store command
140
- when /^store(.*)$/ then
141
- string = $1
142
- # Store by itself doesnt use any selenium functions
143
- # its the same as a regular assignment
144
- if $1 == ""
145
- # Arguements have quotes by default
146
- # they need to be stripped for LHS assignments
147
- args[1] = args[1].match(/"(.*)"/)[1]
148
- return "#{args[1]} = #{args[0]}"
149
- end
150
-
151
- # Otherwise, a store command takes the result of the
152
- # cmd and stores it somewhere
153
- var = args[0]
154
- extra = ""
155
- if args[1] != ""
156
- var = args[1]
157
- extra = "(#{args[0]})"
158
- end
159
- # Arguements have quotes by default
160
- # they need to be stripped for LHS assignments
161
- var = var.match(/"(.*)"/)[1]
162
- if semantic_is?(string)
163
- return "#{var} = #{@s_obj}.is_#{underscore(string)}" + extra
164
- else
165
- return "#{var} = #{@s_obj}.get_#{underscore(string)}" + extra
166
- end
167
-
168
- # Pause is directly translated
169
- when /^pause$/ then
170
- convert = args[0].to_f * 0.001
171
- return "sleep #{convert}"
172
-
173
- # Default case
174
- else
175
- # Most commands just need to be converted to
176
- # underscore_case and have their arguements
177
- # appeneded
178
- cmd_new = underscore(cmd)
179
- add = ""
180
- if args[1] != ""
181
- add = ", #{args[1]}"
182
- end
183
- return "#{@s_obj}.#{cmd_new} #{args[0]}" + add
184
- end
185
- end
186
-
187
- # Function to turn CamelCase into underscore_case
188
- def underscore(str)
189
- str.gsub(/(.)([A-Z])/,'\1_\2').downcase
190
- end
191
-
192
- # Function to weed out 11 special functions that
193
- # use an "is" semantic
194
- def semantic_is?(str)
195
- case str
196
- when /Present$/
197
- return true
198
- when /Checked$/
199
- return true
200
- when /Editable$/
201
- return true
202
- when /Ordered$/
203
- return true
204
- when /Selected$/
205
- return true
206
- when /Visible$/
207
- return true
208
- else
209
- return false
210
- end
211
- end
212
34
  end
213
35
  end
@@ -0,0 +1,206 @@
1
+ # Gondola - html_converter.rb:
2
+ # Class definition for turning Selenium HTML into
3
+ # webdriver ruby code
4
+ require 'rubygems'
5
+ require 'gondola'
6
+
7
+ module Gondola
8
+ class HtmlConverter < Converter
9
+ # Function: name
10
+ # Returns the name of this test case
11
+ def name
12
+ unless @name
13
+ @name = @body.match(/<title>(.*)<\/title>/m)[1]
14
+ end
15
+ @name
16
+ end
17
+
18
+ # Function: ruby
19
+ # This function parses the selenium
20
+ # HTML file and sends commands to the
21
+ # html_to_ruby helper function
22
+ def ruby
23
+ unless @ruby
24
+ @ruby = ""
25
+ # Get body of commands from flattened html
26
+ cmd_body = @body.match(/<tbody>(.*)<\/tbody>/m)[1]
27
+
28
+ # Define some patterns for the individual commands
29
+ block_rxp = Regexp.new(/<tr>(.*?)<\/tr>/m)
30
+ cmd_rxp = Regexp.new(/<td>(.*?)<\/td>\s*<td>(.*?)<\/td>\s*<td>(.*?)<\/td>/m)
31
+
32
+ # Loop over all commands
33
+ cmd_body.scan(block_rxp) do |cmd_block|
34
+ cmd_block[0].scan(cmd_rxp) do |cmd|
35
+ # Need to make sure arguements are represented
36
+ # correctly
37
+ if cmd[1] =~ /\$\{(.*)\}/
38
+ cmd[1] = $1
39
+ elsif cmd[1] != ""
40
+ cmd[1] = cmd[1].inspect
41
+ end
42
+ if cmd[2] =~ /\$\{(.*)\}/
43
+ cmd[2] = $1
44
+ elsif cmd[2] != ""
45
+ cmd[2] = cmd[2].inspect
46
+ end
47
+ # Append commands to a result string
48
+ args = [ cmd[1], cmd[2] ]
49
+ @ruby << html_to_ruby(cmd[0], args)
50
+ @ruby << "\ncmd_inc\n"
51
+ end
52
+ end
53
+ end
54
+ @ruby
55
+ end
56
+
57
+ private
58
+ # Function: html_to_ruby
59
+ # cmd - the name of the command
60
+ # args - array of arguements to cmd
61
+ # This function turns a command that has been
62
+ # extracted from a selenium HTML file into
63
+ # one that can be used by the ruby-driver for
64
+ # selenium
65
+ def html_to_ruby(cmd, args)
66
+ # Select over various command types
67
+ case cmd
68
+ # Assert command
69
+ when /^(assert|verify)(.*)$/ then
70
+ # Check to see if this is a negated assertion
71
+ tester = $1
72
+ string = $2
73
+ if $1 =~ /(.*)Not(.*)$/
74
+ string = $1 + $2
75
+ tester = tester + "_not"
76
+ end
77
+
78
+ # Check the semantics of the command
79
+ if semantic_is?(string)
80
+ retval = "#{tester} #{@s_obj}.is_#{underscore(string)}"
81
+ if args[0] != ""
82
+ retval += "(#{args[0]}"
83
+ end
84
+ if args[1] != ""
85
+ retval += ", #{args[1]}"
86
+ end
87
+ retval += ")"
88
+ else
89
+ var = args[0]
90
+ extra = ''
91
+ if args[1] != ""
92
+ var = args[1]
93
+ extra = "(#{args[0]})"
94
+ end
95
+ retval = "#{tester}_eq #{var}, #{@s_obj}.get_#{underscore(string)}" + extra
96
+ end
97
+
98
+ # All commands return arrays that need to be joined
99
+ if string =~ /^All/
100
+ retval += ".join(\",\")"
101
+ end
102
+ return retval
103
+
104
+ # Wait For command
105
+ when /^waitFor(.*)$/ then
106
+ # Special case
107
+ if $1 == "PageToLoad"
108
+ return "#{@s_obj}.wait_for_page_to_load \"30000\""
109
+ end
110
+ # The expression that is checked against depends on whether
111
+ # or not the command uses the "is" or the "get" semantic
112
+ if semantic_is?($1)
113
+ expression = "#{@s_obj}.is_#{underscore($1)}(#{args[0]}"
114
+ if args[1] != ""
115
+ expression += ", #{args[1]}"
116
+ end
117
+ expression += ")"
118
+ else
119
+ expression = "#{args[1]} == #{@s_obj}.get_#{underscore($1)}(#{args[1]})"
120
+ end
121
+ # The waitFor commands loop until something is satisfied
122
+ return "assert !60.times{ break if(#{expression} rescue false); sleep 1 }"
123
+
124
+ # AndWait command POSTFIX
125
+ when /^(.*)AndWait$/ then
126
+ # A command with a postfix of AndWait simply adds
127
+ # a second command which waits a certain time
128
+ firstPart = html_to_ruby($1, args)
129
+ secondPart = "\n#{@s_obj}.wait_for_page_to_load \"30000\""
130
+ return firstPart + secondPart
131
+
132
+ # store command
133
+ when /^store(.*)$/ then
134
+ string = $1
135
+ # Store by itself doesnt use any selenium functions
136
+ # its the same as a regular assignment
137
+ if $1 == ""
138
+ # Arguements have quotes by default
139
+ # they need to be stripped for LHS assignments
140
+ args[1] = args[1].match(/"(.*)"/)[1]
141
+ return "#{args[1]} = #{args[0]}"
142
+ end
143
+
144
+ # Otherwise, a store command takes the result of the
145
+ # cmd and stores it somewhere
146
+ var = args[0]
147
+ extra = ""
148
+ if args[1] != ""
149
+ var = args[1]
150
+ extra = "(#{args[0]})"
151
+ end
152
+ # Arguements have quotes by default
153
+ # they need to be stripped for LHS assignments
154
+ var = var.match(/"(.*)"/)[1]
155
+ if semantic_is?(string)
156
+ return "#{var} = #{@s_obj}.is_#{underscore(string)}" + extra
157
+ else
158
+ return "#{var} = #{@s_obj}.get_#{underscore(string)}" + extra
159
+ end
160
+
161
+ # Pause is directly translated
162
+ when /^pause$/ then
163
+ convert = args[0].to_f * 0.001
164
+ return "sleep #{convert}"
165
+
166
+ # Default case
167
+ else
168
+ # Most commands just need to be converted to
169
+ # underscore_case and have their arguements
170
+ # appeneded
171
+ cmd_new = underscore(cmd)
172
+ add = ""
173
+ if args[1] != ""
174
+ add = ", #{args[1]}"
175
+ end
176
+ return "#{@s_obj}.#{cmd_new} #{args[0]}" + add
177
+ end
178
+ end
179
+
180
+ # Function to turn CamelCase into underscore_case
181
+ def underscore(str)
182
+ str.gsub(/(.)([A-Z])/,'\1_\2').downcase
183
+ end
184
+
185
+ # Function to weed out 11 special functions that
186
+ # use an "is" semantic
187
+ def semantic_is?(str)
188
+ case str
189
+ when /Present$/
190
+ return true
191
+ when /Checked$/
192
+ return true
193
+ when /Editable$/
194
+ return true
195
+ when /Ordered$/
196
+ return true
197
+ when /Selected$/
198
+ return true
199
+ when /Visible$/
200
+ return true
201
+ else
202
+ return false
203
+ end
204
+ end
205
+ end
206
+ end
@@ -0,0 +1,41 @@
1
+ # Gondola - legacy_converter.rb
2
+ # Class definition for turning old selenium-test
3
+ # files into new ruby code for gondola
4
+ require 'rubygems'
5
+ require 'gondola'
6
+
7
+ module Gondola
8
+ class LegacyConverter < Converter
9
+ # Function: name
10
+ # Returns the name of this test case
11
+ def name
12
+ unless @name
13
+ @name = @body.match(/class(.*?)</m)[1].strip
14
+ end
15
+ @name
16
+ end
17
+
18
+ # Function: ruby
19
+ # This function parses the given legacy
20
+ # test case file and parses it into the
21
+ # new streamlined form
22
+ def ruby
23
+ unless @ruby
24
+ @ruby = ""
25
+
26
+ # Only search through relevent portions
27
+ cmd_body = @body.match(/def test_case.*end/m)
28
+ # Define a pattern for commands
29
+ cmd_rxp = Regexp.new(/^.*?@selenium.*?$/)
30
+
31
+ # Loop over all lines
32
+ cmd_body[0].scan(cmd_rxp) do |cmd|
33
+ @ruby << cmd.strip.sub(/@selenium/, "@sel")
34
+ @ruby << "\ncmd_inc\n"
35
+ end
36
+ end
37
+ @ruby
38
+ end
39
+ end
40
+ end
41
+
@@ -32,16 +32,14 @@ module Gondola
32
32
  prepend = "**/"
33
33
  end
34
34
  files = Dir.glob(prepend + "*.html")
35
- if opts[:legacy] == true
36
- files.concat(Dir.glob(prepend + "*.rb"))
37
- end
35
+ files.concat(Dir.glob(prepend + "*.rb"))
38
36
  files.each do |file|
39
37
  conf = configure(File.expand_path(File.dirname(file)))
40
38
  run_test(file, conf)
41
39
  end
42
40
  else
43
41
  conf = configure(File.expand_path(File.dirname(test)))
44
- run_test(file, conf)
42
+ run_test(test, conf)
45
43
  end
46
44
  end
47
45
  end
@@ -84,8 +82,13 @@ module Gondola
84
82
 
85
83
  # Function to run and parallelize the given test on the given browsers
86
84
  def run_test(file, conf)
87
- # Initialize a converter object
88
- converter = Gondola::Converter.new(file)
85
+ # Initialize a converter object based on filetype
86
+ converter = nil
87
+ if File.extname(file) == '.html'
88
+ converter = Gondola::HtmlConverter.new(file)
89
+ elsif File.extname(file) == '.rb'
90
+ converter = Gondola::LegacyConverter.new(file)
91
+ end
89
92
  # Set global information
90
93
  global = {}
91
94
  global[:job_name] = converter.name
@@ -1,9 +1,3 @@
1
1
  module Gondola
2
- module Version
3
- MAJOR = 1
4
- MINOR = 1
5
- PATCH = 3
6
-
7
- STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
- end
2
+ VERSION = "1.1.4"
9
3
  end
data/lib/gondola.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'gondola/converter'
3
+ require 'gondola/html_converter'
4
+ require 'gondola/legacy_converter'
3
5
  require 'gondola/tester'
4
6
  require 'gondola/testrunner'
5
7
  require 'gondola/version'
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: gondola
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.1.3
5
+ version: 1.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Matthew Perry
@@ -91,6 +91,8 @@ files:
91
91
  - gondola.gemspec
92
92
  - lib/gondola.rb
93
93
  - lib/gondola/converter.rb
94
+ - lib/gondola/html_converter.rb
95
+ - lib/gondola/legacy_converter.rb
94
96
  - lib/gondola/tester.rb
95
97
  - lib/gondola/testrunner.rb
96
98
  - lib/gondola/version.rb
@@ -110,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
113
  - - ">="
112
114
  - !ruby/object:Gem::Version
113
- hash: -875425795
115
+ hash: -286975601
114
116
  segments:
115
117
  - 0
116
118
  version: "0"