3
3
require 'cgi'
4
4
require 'json'
5
5
require 'rbconfig'
6
+ require 'yaml'
6
7
7
8
# A barebones runner for testing across multiple browsers quickly.
8
9
#
@@ -57,6 +58,26 @@ module Runner
57
58
host = RbConfig ::CONFIG [ 'host' ]
58
59
IS_WINDOWS = host . include? ( 'mswin' ) || host . include? ( 'mingw32' )
59
60
61
+ class << self
62
+ PWD = Pathname . new ( File . dirname ( __FILE__ ) )
63
+ CONFIG_FILE = PWD . join ( 'browsers.yml' )
64
+
65
+ unless CONFIG_FILE . exist?
66
+ # Copy the sample config file to an actual config file.
67
+ sample = PWD . join ( 'browsers.sample.yml' )
68
+ File . open ( CONFIG_FILE , 'w' ) do |file |
69
+ file . write ( File . read ( sample ) )
70
+ end
71
+ end
72
+
73
+ CONFIG = YAML ::load_file ( CONFIG_FILE )
74
+
75
+ def config
76
+ CONFIG
77
+ end
78
+ end
79
+
80
+
60
81
module Browsers
61
82
62
83
class Abstract
@@ -87,6 +108,15 @@ def linux?
87
108
host . include? ( 'linux' )
88
109
end
89
110
111
+ def configured_path
112
+ browsers = Runner ::config [ 'browsers' ]
113
+ browsers [ short_name . to_s ]
114
+ end
115
+
116
+ def default_path
117
+ nil
118
+ end
119
+
90
120
def visit ( url )
91
121
if windows?
92
122
system ( %Q["#{ path } " "#{ url } "] )
@@ -106,6 +136,10 @@ def name
106
136
linux? ? n . downcase : n
107
137
end
108
138
139
+ def short_name
140
+ nil
141
+ end
142
+
109
143
def escaped_name
110
144
name . gsub ( ' ' , '\ ' )
111
145
end
@@ -114,15 +148,19 @@ def path
114
148
if macos?
115
149
File . expand_path ( "/Applications/#{ name } .app" )
116
150
else
117
- @path || nil
151
+ configured_path || default_path || nil
118
152
end
119
153
end
120
154
end
121
155
122
156
class Firefox < Abstract
123
157
124
- def initialize ( path = File . join ( ENV [ 'ProgramFiles' ] || 'c:\Program Files' , '\Mozilla Firefox\firefox.exe' ) )
125
- @path = path
158
+ def short_name
159
+ :firefox
160
+ end
161
+
162
+ def default_path
163
+ 'C:\Program Files\Mozilla Firefox\firefox.exe'
126
164
end
127
165
128
166
def supported?
@@ -133,6 +171,10 @@ def supported?
133
171
134
172
class IE < Abstract
135
173
174
+ def short_name
175
+ :ie
176
+ end
177
+
136
178
def setup
137
179
require 'win32ole' if windows?
138
180
end
@@ -155,6 +197,10 @@ def visit(url)
155
197
156
198
class Safari < Abstract
157
199
200
+ def short_name
201
+ :safari
202
+ end
203
+
158
204
def supported?
159
205
macos?
160
206
end
@@ -163,8 +209,12 @@ def supported?
163
209
164
210
class Chrome < Abstract
165
211
166
- def initialize ( path = nil )
167
- @path = path || 'C:\Program Files\Google\Chrome\Application\chrome.exe'
212
+ def short_name
213
+ :chrome
214
+ end
215
+
216
+ def default_path
217
+ 'C:\Program Files\Google\Chrome\Application\chrome.exe'
168
218
end
169
219
170
220
def name
@@ -175,8 +225,12 @@ def name
175
225
176
226
class Opera < Abstract
177
227
178
- def initialize ( path = 'C:\Program Files\Opera\Opera.exe' )
179
- @path = path
228
+ def short_name
229
+ :opera
230
+ end
231
+
232
+ def default_path
233
+ 'C:\Program Files\Opera\launcher.exe'
180
234
end
181
235
182
236
end
@@ -284,6 +338,7 @@ def run(browsers=nil, tests=nil, grep=nil)
284
338
end
285
339
if !browser . installed?
286
340
puts "Skipping #{ browser . name } (not installed on this OS)"
341
+ puts " (edit test/unit/browsers.yml if this is in error)"
287
342
next
288
343
end
289
344
print "Running in #{ browser . name } ... "
0 commit comments