geordi 5.4.0 → 6.0.0.pre.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,32 +0,0 @@
1
- desc 'firefox COMMAND', 'Run a command with VNC and test browser set up (alias: chrome)'
2
- long_desc <<-LONGDESC
3
- Example: `geordi firefox b cucumber` or `geordi firefox --setup 24.0`
4
-
5
- Useful when you need Firefox for Selenium or the VNC set up, but can't use the
6
- `geordi cucumber` command. This command is aliased `chrome` for users running
7
- Selenium in Chrome.
8
- LONGDESC
9
-
10
- option :setup, banner: 'FIREFOX_VERSION',
11
- desc: 'Install a special test runner Firefox with the given version'
12
-
13
- def firefox(*command)
14
- if options.setup
15
- Interaction.fail 'Firefox version required (e.g. --setup 24.0)' if options.setup == 'setup'
16
-
17
- require 'geordi/firefox_for_selenium'
18
- Geordi::FirefoxForSelenium.install(options.setup)
19
-
20
- else
21
- require 'geordi/cucumber'
22
-
23
- Cucumber.new.setup_vnc
24
- FirefoxForSelenium.setup_firefox
25
-
26
- puts
27
- Interaction.note_cmd command.join(' ')
28
- system *command # Util.run! would reset the Firefox PATH
29
- end
30
- end
31
-
32
- map 'chrome' => 'firefox'
@@ -1,18 +0,0 @@
1
- desc 'vnc', 'Show the hidden VNC window'
2
- long_desc <<-LONGDESC
3
- Example: `geordi vnc` or `geordi vnc --setup`
4
-
5
- Launch a VNC session to the hidden screen where `geordi cucumber` runs Selenium
6
- tests.
7
- LONGDESC
8
-
9
- option :setup, type: :boolean, desc: 'Guide through the setup of VNC'
10
-
11
- def vnc
12
- if options.setup
13
- invoke_geordi :_setup_vnc
14
- else
15
- require 'geordi/cucumber'
16
- Geordi::Cucumber.new.launch_vnc_viewer
17
- end
18
- end
@@ -1,200 +0,0 @@
1
- require 'pathname'
2
- require 'tempfile'
3
- require File.expand_path('interaction', __dir__)
4
-
5
- module Geordi
6
- module FirefoxForSelenium
7
-
8
- FIREFOX_FOR_SELENIUM_BASE_PATH = Pathname.new('~/bin/firefoxes').expand_path
9
- FIREFOX_FOR_SELENIUM_PROFILE_NAME = 'firefox-for-selenium'.freeze
10
- FIREFOX_VERSION_FILE = Pathname.new('.firefox-version')
11
-
12
- def self.install(version)
13
- Installer.new(version).run
14
- end
15
-
16
- def self.path_from_config
17
- version = FIREFOX_VERSION_FILE.exist? && File.read(FIREFOX_VERSION_FILE).strip
18
-
19
- if version && (version != 'system')
20
- unless FirefoxForSelenium.binary(version).exist?
21
- Interaction.warn "Firefox #{version} not found"
22
-
23
- Interaction.note Util.strip_heredoc(<<-INSTRUCTIONS)
24
- Install it with
25
- geordi firefox --setup #{version}
26
- INSTRUCTIONS
27
-
28
- Interaction.prompt('Run tests anyway?', 'n', /y|yes/) || Interaction.fail('Cancelled.')
29
- end
30
-
31
- path(version)
32
- end
33
- end
34
-
35
- def self.path(version)
36
- FIREFOX_FOR_SELENIUM_BASE_PATH.join(version)
37
- end
38
-
39
- def self.binary(version, name = 'firefox')
40
- path(version).join(name)
41
- end
42
-
43
- def self.setup_firefox
44
- path = path_from_config
45
-
46
- if path
47
- ENV['PATH'] = "#{path}:#{ENV['PATH']}"
48
- Interaction.note 'Firefox for Selenium set up'
49
- end
50
- end
51
-
52
-
53
- class Installer
54
-
55
- def initialize(version)
56
- @version = version
57
- end
58
-
59
- def run
60
- say_hello
61
- check_if_run_before
62
- download_firefox
63
- create_separate_profile # do this before the patching because the patched binary calls firefox with a profile that does not yet exist
64
- patch_old_firefox
65
- configure_old_firefox
66
- kkthxbb
67
- end
68
-
69
-
70
- private
71
-
72
- def execute_command(cmd)
73
- system(cmd) || raise("Error while executing command: #{cmd}")
74
- end
75
-
76
- def run_firefox_for_selenium(args = '')
77
- execute_command("PATH=#{path}:$PATH firefox #{args}")
78
- end
79
-
80
- def path
81
- FirefoxForSelenium.path(@version)
82
- end
83
-
84
- def download_url
85
- "https://ftp.mozilla.org/pub/firefox/releases/#{@version}/"
86
- end
87
-
88
- def binary
89
- FirefoxForSelenium.binary(@version)
90
- end
91
-
92
- def original_binary
93
- FirefoxForSelenium.binary(@version, 'firefox-original')
94
- end
95
-
96
- def say_hello
97
- execute_command('clear')
98
-
99
- puts Util.strip_heredoc(<<-HELLO)
100
- Whenever Firefox updates, Selenium breaks. This is annoying. This
101
- script will help you create an unchanging version of Firefox for your
102
- Selenium tests.
103
-
104
- In particular, this new copy of Firefox will have the following
105
- properties:
106
-
107
- - It won't update itself with a newer version
108
- - It can co-exist with your regular Firefox installation (which you can
109
- update at will)
110
- - It will use a profile separate from the one you use for regular
111
- Firefox browsing
112
- - It will not try to re-use existing Firefox windows
113
- - It will automatically be used for your Selenium scenarios if you run
114
- your Cucumber using the cuc binary from the geordi gem.
115
- - It will live in #{path}
116
- HELLO
117
-
118
- Interaction.prompt "Press ENTER when you're ready to begin."
119
- end
120
-
121
- def check_if_run_before
122
- if original_binary.exist?
123
- Interaction.note 'This version seems to be already installed.'
124
- Interaction.prompt 'Press ENTER to continue anyway or press CTRL+C to abort.'
125
- end
126
- end
127
-
128
- def download_firefox
129
- path.mkpath
130
-
131
- puts Util.strip_heredoc(<<-INSTRUCTION)
132
- Please download an old version of Firefox from: #{download_url}
133
- Unpack it with: tar xjf firefox-#{@version}.tar.bz2 -C #{path} --strip-components=1
134
- Now #{path.join('firefox')} should be the firefox binary, not a directory.
135
- INSTRUCTION
136
- Interaction.prompt 'Continue?'
137
-
138
- File.file?(binary) || raise("Could not find #{binary}")
139
- end
140
-
141
- def create_separate_profile
142
- Interaction.note "Creating a separate profile named '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}' so your own profile will be safe..."
143
- # don't use the patched firefox binary for this, we don't want to give
144
- # a -p option here
145
- execute_command("PATH=#{path}:$PATH firefox -no-remote -CreateProfile #{FIREFOX_FOR_SELENIUM_PROFILE_NAME}")
146
- puts
147
- end
148
-
149
- def patch_old_firefox
150
- Interaction.note "Patching #{binary} so it uses the new profile and never re-uses windows from other Firefoxes..."
151
- execute_command("mv #{binary} #{original_binary}")
152
- execute_command("mv #{binary}-bin #{original_binary}-bin")
153
- patched_binary = Tempfile.new('firefox')
154
- patched_binary.write Util.strip_heredoc(<<-PATCH)
155
- #!/usr/bin/env ruby
156
- exec('#{original_binary}', '-no-remote', '-P', '#{FIREFOX_FOR_SELENIUM_PROFILE_NAME}', *ARGV)
157
- PATCH
158
- patched_binary.close
159
- execute_command("mv #{patched_binary.path} #{binary}")
160
- execute_command("chmod +x #{binary}")
161
- puts
162
- end
163
-
164
- def configure_old_firefox
165
- puts Util.strip_heredoc(<<-INSTRUCTION)
166
- You will now have to do some manual configuration.
167
-
168
- This script will open the patched copy of Firefox when you press ENTER.
169
- Please perform the following steps manually:
170
-
171
- - IMPORTANT: Quickly disable all automatic updates under Edit /
172
- Preferences / Advanced / Update
173
- - Disable the default browser check when Firefox launches
174
- - Check that the version number is correct (#{@version})
175
- - You should not see your bookmarks, add-ons, plugins from your regular
176
- Firefox profile
177
- INSTRUCTION
178
-
179
- Interaction.prompt 'Will open the patched copy of Firefox now'
180
- run_firefox_for_selenium
181
- end
182
-
183
- def kkthxbb
184
- Interaction.success "Congratulations, you're done!"
185
-
186
- puts
187
- puts Util.strip_heredoc(<<-INSTRUCTION)
188
- Your patched copy of Firefox will be used when you run Cucumber using
189
- the cucumber script that comes with the geordi gem. If you cannot use
190
- `geordi cucumber`, but still need the test browser set up, you can use:
191
-
192
- geordi firefox <any command>
193
-
194
- Enjoy!
195
- INSTRUCTION
196
- end
197
-
198
- end
199
- end
200
- end