geordi 0.15.7 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + "/../lib/geordi/setup_firefox_for_selenium"
2
+ require File.dirname(__FILE__) + "/../lib/geordi/firefox_for_selenium"
3
3
  require 'tempfile'
4
4
 
5
- Geordi::SetupFirefoxForSelenium.run
5
+ Geordi::FirefoxForSelenium.install
data/lib/geordi/cuc.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require "rubygems"
2
- require File.join(File.dirname(__FILE__), 'setup_firefox_for_selenium')
2
+ require File.join(File.dirname(__FILE__), 'firefox_for_selenium')
3
3
  require 'tempfile'
4
4
 
5
5
  module Geordi
@@ -82,7 +82,7 @@ module Geordi
82
82
 
83
83
 
84
84
  def use_firefox_for_selenium
85
- "PATH=#{Geordi::SetupFirefoxForSelenium::FIREFOX_FOR_SELENIUM_PATH}:$PATH"
85
+ "PATH=#{Geordi::FirefoxForSelenium.path_from_config}:$PATH"
86
86
  end
87
87
 
88
88
 
@@ -0,0 +1,211 @@
1
+ require 'pathname'
2
+
3
+ module Geordi
4
+ module FirefoxForSelenium
5
+
6
+ FIREFOX_FOR_SELENIUM_BASE_PATH = Pathname.new('~/bin/firefoxes').expand_path
7
+ FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'
8
+ DEFAULT_FIREFOX_VERSION = "5.0.1"
9
+ VERSION_SPECIFICATION_FILE = Pathname.new(".firefox-version")
10
+
11
+ def self.install
12
+ Installer.new.run
13
+ end
14
+
15
+ def self.path_from_config
16
+ PathFromConfig.new.run
17
+ end
18
+
19
+ def self.path(version)
20
+ FIREFOX_FOR_SELENIUM_BASE_PATH.join(version)
21
+ end
22
+
23
+ def self.binary(version, name = "firefox")
24
+ path(version).join(name)
25
+ end
26
+
27
+
28
+ class PathFromConfig
29
+
30
+ def run
31
+ get_version
32
+ validate_install
33
+ path
34
+ end
35
+
36
+ private
37
+
38
+ def path
39
+ FirefoxForSelenium.path(@version)
40
+ end
41
+
42
+ def get_version
43
+ @version = version_from_cuc_file || default_version
44
+ end
45
+
46
+ def default_version
47
+ puts "No firefox version given, defaulting to #{DEFAULT_FIREFOX_VERSION}."
48
+ puts "Specify a version by putting it in a file named \"#{VERSION_SPECIFICATION_FILE}\"."
49
+ puts
50
+ DEFAULT_FIREFOX_VERSION
51
+ end
52
+
53
+ def validate_install
54
+ unless FirefoxForSelenium.binary(@version).exist?
55
+ puts "Firefox #{@version} not found."
56
+ puts "Install it with"
57
+ puts " setup-firefox-for-selenium #{@version}"
58
+ puts
59
+ puts "Press ENTER to continue anyway or press CTRL+C to abort."
60
+ gets
61
+ end
62
+ end
63
+
64
+ def version_from_cuc_file
65
+ File.read(VERSION_SPECIFICATION_FILE).strip if VERSION_SPECIFICATION_FILE.exist?
66
+ end
67
+
68
+ end
69
+
70
+
71
+ class Installer
72
+
73
+ def run
74
+ parse_version
75
+ say_hello
76
+ check_if_run_before
77
+ download_firefox
78
+ create_separate_profile # do this before the patching because the patched binary calls firefox with a profile that does not yet exist
79
+ patch_old_firefox
80
+ configure_old_firefox
81
+ kkthxbb
82
+ end
83
+
84
+
85
+ private
86
+
87
+ def execute_command(cmd)
88
+ system(cmd) or raise "Error while executing command: #{cmd}"
89
+ end
90
+
91
+ def run_firefox_for_selenium(args = '')
92
+ execute_command("PATH=#{path}:$PATH firefox #{args}")
93
+ end
94
+
95
+ def die(message)
96
+ puts message
97
+ puts
98
+ exit(1)
99
+ end
100
+
101
+ def path
102
+ FirefoxForSelenium.path(@version)
103
+ end
104
+
105
+ def download_url
106
+ "ftp://ftp.mozilla.org/pub/firefox/releases/#{@version}/"
107
+ end
108
+
109
+ def binary
110
+ FirefoxForSelenium.binary(@version)
111
+ end
112
+
113
+ def original_binary
114
+ FirefoxForSelenium.binary(@version, "firefox-original")
115
+ end
116
+
117
+ def parse_version
118
+ @version = ARGV.pop
119
+ @version or die("Usage: setup_firefox_for_selenium VERSION")
120
+ end
121
+
122
+ def say_hello
123
+ execute_command('clear')
124
+ puts "Whenever Firefox updates, Selenium breaks. This is annoying."
125
+ puts "This script will help you create an unchanging version of Firefox for your Selenium tests."
126
+ puts
127
+ puts "In particular, this new copy of Firefox will have the following properties:"
128
+ puts
129
+ puts "- It won't update itself with a newer version"
130
+ puts "- It can co-exist with your regular Firefox installation (which you can update at will)"
131
+ puts "- It will use a profile separate from the one you use for regular Firefox browsing"
132
+ puts "- It will not try to re-use existing Firefox windows"
133
+ puts "- It will automatically be used for your Selenium scenarios if you run your Cucumber using the cuc binary from the geordi gem."
134
+ puts "- It will live in #{path}"
135
+ puts
136
+ puts "Press ENTER when you're ready to begin."
137
+ gets
138
+ end
139
+
140
+ def check_if_run_before
141
+ if original_binary.exist?
142
+ puts "This version seems to be already installed."
143
+ puts
144
+ puts "Press ENTER to continue anyway or press CTRL+C to abort."
145
+ gets
146
+ end
147
+ end
148
+
149
+ def download_firefox
150
+ path.mkpath
151
+ puts "Please download an old version of Firefox from #{download_url} and unpack it to #{path}."
152
+ puts "Don't create an extra #{path.join("firefox")} directory."
153
+ puts
154
+ puts "Press ENTER when you're done."
155
+ gets
156
+ File.file?(binary) or raise "Could not find #{binary}"
157
+ end
158
+
159
+ def create_separate_profile
160
+ puts "Creating a separate profile named '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}' so your own profile will be safe..."
161
+ # don't use the patched firefox binary for this, we don't want to give a -p parameter here
162
+ execute_command("PATH=#{path}:$PATH firefox -no-remote -CreateProfile #{FIREFOX_FOR_SELENIUM_PROFILE_NAME}")
163
+ puts
164
+ end
165
+
166
+ def patch_old_firefox
167
+ puts "Patching #{binary} so it uses the new profile and never re-uses windows from other Firefoxes..."
168
+ execute_command("mv #{binary} #{original_binary}")
169
+ execute_command("mv #{binary}-bin #{original_binary}-bin")
170
+ patched_binary = Tempfile.new('firefox')
171
+ patched_binary.write <<eos
172
+ #!/usr/bin/env ruby
173
+ exec('#{original_binary}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
174
+ eos
175
+ patched_binary.close
176
+ execute_command("mv #{patched_binary.path} #{binary}")
177
+ execute_command("chmod +x #{binary}")
178
+ puts
179
+ end
180
+
181
+ def configure_old_firefox
182
+ puts "This script will now open the patched copy of Firefox."
183
+ puts
184
+ puts "Please perform the following steps manually:"
185
+ puts
186
+ puts "- Disable the default browser check when Firefox launches"
187
+ puts "- Check that the version number is correct (#{@version})"
188
+ puts "- Disable all automatic updates under Edit / Preferences / Advanced / Update (do this quickly or Firefox will already have updated)"
189
+ puts "- You should not see your bookmarks, addons, plugins from your regular Firefox profile"
190
+ puts
191
+ puts "Press ENTER when you're ready to open Firefox and perform these steps."
192
+ gets
193
+ run_firefox_for_selenium
194
+ end
195
+
196
+ def kkthxbb
197
+ puts "Congratulations, you're done!"
198
+ puts
199
+ puts "Your patched copy of Firefox will be used when you run Cucumber using the cuc binary that comes with the geordi gem."
200
+ puts "If you prefer to run Cucumber on your own, you must call it like this:"
201
+ puts
202
+ puts " PATH=#{path}:$PATH cucumber"
203
+ puts
204
+ puts "Enjoy!"
205
+ puts
206
+ end
207
+
208
+ end
209
+ end
210
+ end
211
+
@@ -1,3 +1,3 @@
1
1
  module Geordi
2
- VERSION = '0.15.7'
2
+ VERSION = '0.16.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geordi
3
3
  version: !ruby/object:Gem::Version
4
- hash: 45
4
+ hash: 95
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 15
9
- - 7
10
- version: 0.15.7
8
+ - 16
9
+ - 0
10
+ version: 0.16.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henning Koch
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2013-08-23 00:00:00 +02:00
18
+ date: 2013-10-10 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -89,8 +89,8 @@ files:
89
89
  - lib/geordi/capistrano.rb
90
90
  - lib/geordi/cuc.rb
91
91
  - lib/geordi/dump_loader.rb
92
+ - lib/geordi/firefox_for_selenium.rb
92
93
  - lib/geordi/gitpt.rb
93
- - lib/geordi/setup_firefox_for_selenium.rb
94
94
  - lib/geordi/version.rb
95
95
  has_rdoc: true
96
96
  homepage: http://makandra.com
@@ -1,119 +0,0 @@
1
- module Geordi
2
- class SetupFirefoxForSelenium
3
-
4
- FIREFOX_FOR_SELENIUM_PATH = '/opt/firefox-for-selenium'
5
- FIREFOX_FOR_SELENIUM_BINARY = "#{FIREFOX_FOR_SELENIUM_PATH}/firefox"
6
- ORIGINAL_FIREFOX_BINARY = "#{FIREFOX_FOR_SELENIUM_PATH}/firefox-original"
7
- FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'
8
-
9
- class << self
10
-
11
- def execute_command(cmd)
12
- system(cmd) or raise "Error while executing command: #{cmd}"
13
- end
14
-
15
- def run_firefox_for_selenium(args = '')
16
- execute_command("PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH firefox #{args}")
17
- end
18
-
19
- def say_hello
20
- execute_command('clear')
21
- puts "Whenever Firefox updates, Selenium breaks. This is annoying."
22
- puts "This script will help you create an unchanging version of Firefox for your Selenium tests."
23
- puts
24
- puts "In particular, this new copy of Firefox will have the following properties:"
25
- puts
26
- puts "- It won't update itself with a newer version"
27
- puts "- It can co-exist with your regular Firefox installation (which you can update at will)"
28
- puts "- It will use a profile separate from the one you use for regular Firefox browsing"
29
- puts "- It will not try to re-use existing Firefox windows"
30
- puts "- It will automatically be used for your Selenium scenarios if you run your Cucumber using the cuc binary from the geordi gem."
31
- puts "- It will live in #{FIREFOX_FOR_SELENIUM_PATH}"
32
- puts
33
- puts "At some point, this script will ask you for your user password, because some operations need to be run as root."
34
- puts
35
- puts "Press ENTER when you're ready to begin."
36
- gets
37
- end
38
-
39
- def check_if_run_before
40
- if File.exists?(ORIGINAL_FIREFOX_BINARY)
41
- puts "It looks like you have run this script before. No good can come from running this script a second time on the same copy of Firefox."
42
- puts
43
- puts "Press ENTER to continue anyway or press CTRL+C to abort."
44
- gets
45
- end
46
- end
47
-
48
- def download_old_firefox
49
- puts "Please download an old version of Firefox from ftp://ftp.mozilla.org/pub/firefox/releases/5.0.1/ and unpack it to #{FIREFOX_FOR_SELENIUM_PATH}"
50
- puts
51
- puts "Press ENTER when you're done."
52
- gets
53
- File.file?(FIREFOX_FOR_SELENIUM_BINARY) or raise "Could not find #{FIREFOX_FOR_SELENIUM_BINARY}"
54
- end
55
-
56
- def create_separate_profile
57
- puts "Creating a separate profile named '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}' so your own profile will be safe..."
58
- # don't use the patched firefox binary for this, we don't want to give a -p parameter here
59
- execute_command("PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH firefox -no-remote -CreateProfile #{FIREFOX_FOR_SELENIUM_PROFILE_NAME}")
60
- puts
61
- end
62
-
63
- def patch_old_firefox
64
- puts "Patching #{FIREFOX_FOR_SELENIUM_BINARY} so it uses the new profile and never re-uses windows from other Firefoxes..."
65
- execute_command("sudo mv #{FIREFOX_FOR_SELENIUM_BINARY} #{ORIGINAL_FIREFOX_BINARY}")
66
- execute_command("sudo mv #{FIREFOX_FOR_SELENIUM_BINARY}-bin #{ORIGINAL_FIREFOX_BINARY}-bin")
67
- patched_binary = Tempfile.new('firefox')
68
- patched_binary.write <<eos
69
- #!/usr/bin/env ruby
70
- exec('#{ORIGINAL_FIREFOX_BINARY}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
71
- eos
72
- patched_binary.close
73
- execute_command("sudo mv #{patched_binary.path} #{FIREFOX_FOR_SELENIUM_BINARY}")
74
- execute_command("sudo chmod +x #{FIREFOX_FOR_SELENIUM_BINARY}")
75
- execute_command("sudo chmod +x #{FIREFOX_FOR_SELENIUM_BINARY}")
76
- puts
77
- end
78
-
79
- def configure_old_firefox
80
- puts "This script will now open the patched copy of Firefox."
81
- puts
82
- puts "Please perform the following steps manually:"
83
- puts
84
- puts "- Disable the default browser check when Firefox launches"
85
- puts "- Check that the version number is that of the old Firefox version you copied to #{FIREFOX_FOR_SELENIUM_PATH}"
86
- puts "- Disable all automatic updates under Edit / Preferences / Advanced / Update (do this quickly or Firefox will already have updated)"
87
- puts "- You should not see your bookmarks, addons, plugins from your regular Firefox profile"
88
- puts
89
- puts "Press ENTER when you're ready to open Firefox and perform these steps."
90
- gets
91
- run_firefox_for_selenium
92
- end
93
-
94
- def kkthxbb
95
- puts "Congratulations, you're done!"
96
- puts
97
- puts "Your patched copy of Firefox will be used when you run Cucumber using the cuc binary that comes with the geordi gem."
98
- puts "If you prefer to run Cucumber on your own, you must call it like this:"
99
- puts
100
- puts " PATH=#{FIREFOX_FOR_SELENIUM_PATH}:$PATH cucumber"
101
- puts
102
- puts "Enjoy!"
103
- puts
104
- end
105
-
106
- def run
107
- say_hello
108
- check_if_run_before
109
- download_old_firefox
110
- create_separate_profile # do this before the patching because the patched binary calls firefox with a profile that does not yet exist
111
- patch_old_firefox
112
- configure_old_firefox
113
- kkthxbb
114
- end
115
-
116
- end
117
- end
118
- end
119
-