frameworks-capybara 0.2.34 → 0.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,9 +1,3 @@
1
1
  source :rubygems
2
2
 
3
- platforms :jruby do
4
- gem "jruby-openssl"
5
- end
6
-
7
- gem "rspec-mocks", "<2.14.0"
8
-
9
3
  gemspec
data/Gemfile.lock CHANGED
@@ -1,25 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frameworks-capybara (0.2.34)
5
- capybara (~> 1.1.2)
4
+ frameworks-capybara (0.3.0.rc1)
5
+ capybara (>= 1.0.0)
6
6
  capybara-celerity
7
- capybara-mechanize (>= 0.3.0, < 1.0.0)
8
- cucumber (>= 0.10.5)
9
- headless
10
- json
11
- mechanize (= 2.7.2)
12
- mime-types (~> 1.25)
13
- nokogiri (~> 1.5.10)
14
- rubyzip (~> 0.9.9)
15
- selenium-webdriver
7
+ capybara-mechanize (>= 0.3.0)
16
8
  w3c_validators
17
9
 
18
10
  GEM
19
11
  remote: http://rubygems.org/
20
12
  specs:
21
- builder (3.2.2)
22
- capybara (1.1.4)
13
+ addressable (2.2.7)
14
+ builder (3.0.0)
15
+ capybara (1.1.2)
23
16
  mime-types (>= 1.16)
24
17
  nokogiri (>= 1.3.3)
25
18
  rack (>= 1.0.0)
@@ -33,66 +26,64 @@ GEM
33
26
  capybara (~> 1.1)
34
27
  mechanize (~> 2.3)
35
28
  celerity (0.9.2)
36
- childprocess (0.3.9)
37
- ffi (~> 1.0, >= 1.0.11)
38
- cucumber (1.3.10)
29
+ childprocess (0.3.1)
30
+ ffi (~> 1.0.6)
31
+ cucumber (1.1.9)
39
32
  builder (>= 2.1.2)
40
- diff-lcs (>= 1.1.3)
41
- gherkin (~> 2.12)
42
- multi_json (>= 1.7.5, < 2.0)
43
- multi_test (>= 0.0.2)
44
- diff-lcs (1.2.5)
45
- domain_name (0.5.15)
46
- unf (>= 0.0.5, < 1.0.0)
47
- ffi (1.9.3)
48
- gherkin (2.12.2)
49
- multi_json (~> 1.3)
50
- headless (1.0.1)
51
- http-cookie (1.0.2)
52
- domain_name (~> 0.5)
53
- json (1.8.1)
54
- mechanize (2.7.2)
33
+ diff-lcs (>= 1.1.2)
34
+ gherkin (~> 2.9.0)
35
+ json (>= 1.4.6)
36
+ term-ansicolor (>= 1.0.6)
37
+ diff-lcs (1.1.3)
38
+ domain_name (0.5.3)
39
+ unf (~> 0.0.3)
40
+ ffi (1.0.11)
41
+ gherkin (2.9.3)
42
+ json (>= 1.4.6)
43
+ json (1.6.6)
44
+ libwebsocket (0.1.3)
45
+ addressable
46
+ mechanize (2.3)
55
47
  domain_name (~> 0.5, >= 0.5.1)
56
- http-cookie (~> 1.0.0)
57
48
  mime-types (~> 1.17, >= 1.17.2)
58
49
  net-http-digest_auth (~> 1.1, >= 1.1.1)
59
50
  net-http-persistent (~> 2.5, >= 2.5.2)
60
51
  nokogiri (~> 1.4)
61
52
  ntlm-http (~> 0.1, >= 0.1.1)
62
- webrobots (>= 0.0.9, < 0.2)
63
- mime-types (1.25.1)
64
- multi_json (1.8.2)
65
- multi_test (0.0.2)
66
- net-http-digest_auth (1.4)
67
- net-http-persistent (2.9)
68
- nokogiri (1.5.11)
53
+ webrobots (~> 0.0, >= 0.0.9)
54
+ mime-types (1.18)
55
+ multi_json (1.3.2)
56
+ net-http-digest_auth (1.2)
57
+ net-http-persistent (2.6)
58
+ nokogiri (1.5.2)
69
59
  ntlm-http (0.1.1)
70
- rack (1.5.2)
71
- rack-test (0.6.2)
60
+ rack (1.4.1)
61
+ rack-test (0.6.1)
72
62
  rack (>= 1.0)
73
- rake (10.1.0)
74
- rspec (2.13.0)
75
- rspec-core (~> 2.13.0)
76
- rspec-expectations (~> 2.13.0)
77
- rspec-mocks (~> 2.13.0)
78
- rspec-core (2.13.1)
79
- rspec-expectations (2.13.0)
80
- diff-lcs (>= 1.1.3, < 2.0)
81
- rspec-mocks (2.13.1)
82
- rubyzip (0.9.9)
83
- selenium-webdriver (2.35.1)
63
+ rake (0.9.2.2)
64
+ rspec (2.9.0)
65
+ rspec-core (~> 2.9.0)
66
+ rspec-expectations (~> 2.9.0)
67
+ rspec-mocks (~> 2.9.0)
68
+ rspec-core (2.9.0)
69
+ rspec-expectations (2.9.1)
70
+ diff-lcs (~> 1.1.3)
71
+ rspec-mocks (2.9.0)
72
+ rubyzip (0.9.7)
73
+ selenium-webdriver (2.21.2)
84
74
  childprocess (>= 0.2.5)
75
+ ffi (~> 1.0)
76
+ libwebsocket (~> 0.1.3)
85
77
  multi_json (~> 1.0)
86
- rubyzip (< 1.0.0)
87
- websocket (~> 1.0.4)
88
- unf (0.1.3)
78
+ rubyzip
79
+ term-ansicolor (1.0.7)
80
+ unf (0.0.5)
89
81
  unf_ext
90
- unf_ext (0.0.6)
82
+ unf_ext (0.0.4)
91
83
  w3c_validators (1.2)
92
84
  json
93
85
  nokogiri
94
- webrobots (0.1.1)
95
- websocket (1.0.7)
86
+ webrobots (0.0.13)
96
87
  xpath (0.1.4)
97
88
  nokogiri (~> 1.3)
98
89
 
@@ -100,8 +91,7 @@ PLATFORMS
100
91
  ruby
101
92
 
102
93
  DEPENDENCIES
94
+ cucumber (>= 0.10.5)
103
95
  frameworks-capybara!
104
- jruby-openssl
105
96
  rake
106
97
  rspec (>= 1.0.0)
107
- rspec-mocks (< 2.14.0)
data/README.rdoc CHANGED
@@ -1,5 +1,3 @@
1
- = Build Status {<img src="https://secure.travis-ci.org/bbc-frameworks/frameworks-capybara.png"/>}[https://secure.travis-ci.org/bbc-frameworks/frameworks-capybara]
2
-
3
1
  = frameworks-capybara
4
2
 
5
3
  Gem to simplify the configuration of Capybara when using multiple drivers, also exposes other useful utility methods.
@@ -27,7 +25,7 @@ In your env.rb simply add:
27
25
 
28
26
  The following environment variables can be set to configure your tests:
29
27
 
30
- ENVIRONMENT - this must be one of either 'sandbox', 'sandbox6', 'int', 'test', 'stage', 'live'
28
+ ENVIRONMENT - this must be one of either 'sandbox', 'int', 'test', 'stage', 'live'
31
29
  BROWSER - this must be one of either 'ie', 'firefox', 'chrome', 'headless', 'remote'
32
30
  HTTP_PROXY - url of proxy if required e.g. 'http://proxyhost:80', when running a headless browser this sets the proxy for the browser itself, when running a remote browser this sets the proxy for the client which will connect to the remote selenium server
33
31
  PLATFORM - used when specifying remote test on a grid that provides a choice of platforms, this must be one of either 'WINDOWS' or 'LINUX'
@@ -36,17 +34,10 @@ The following environment variables can be set to configure your tests:
36
34
  REMOTE_BROWSER_VERSION - used when specifying remote test on a grid the provides a choice of browser versions for a given browser
37
35
  REMOTE_URL - URL of remote Selenium-Webdriver server e.g. http://yourremotehost:4444/wd/hub
38
36
  FIREFOX_PROFILE - specify a firefox profile to use when running in-browser tests (local or remote)
39
- FIREFOX_PREFS - specify a json string of additional preferences e.g. FIREFOX_PREFS='{"javascript.enabled": false}'
40
- FIREFOX_CERT_PATH - specify optional directory containing Firefox profile certificate (.db) files
41
- FIREFOX_CERT_PREFIX - specify optional prefix for locating Firefox profile certificate files (e.g. <prefix>-<file>.db)
42
- CREATE_NEW_FF_PROFILE - create a new Firefox profile with name provided by FIREFOX_PROFILE
43
37
  CELERITY_JS_ENABLED (string - 'true', 'false') - determines whether Celerity (HTMLUnit) attempts to execute javascript
44
38
  XVFB - (string - 'true', 'false') - determines whether XVFB is used to run browser (i.e. headless Firefox on *nix platform)
45
39
  FW_CERT_LOCATION - path to client certificate (combined pem)
46
40
  CHROME_SWITCHES - pass in any allowed switches for the Selenium chrome driver (http://peter.sh/experiments/chromium-command-line-switches/) e.g. CHROME_SWITCHES="--user-agent=Mozilla/5.0 (PLAYSTATION 3; 3.55)"
47
- PROJECT_NAME - optional project name description which gets displayed in Cucumber html reports
48
- TEAM_NAME - optional team name description which gets displayed in Cucumber html reports
49
- BROWSER_CLI_ARGS - optional additional arguments to pass to local browser processes
50
41
 
51
42
  Here is a sample cucumber.yml:
52
43
 
@@ -79,25 +70,15 @@ This gem also sets up a number of 'base urls' for you to use in your tests, thes
79
70
  @base_static_url
80
71
  @base_open_url
81
72
 
82
- Finally this gem contains some useful monkey-patches to core libraries e.g. Capybara-Mechanize, Selenium-Webdriver and Cucumber.
73
+ Finally this gem contains some useful monkey-patches to core libraries e.g. Capybara, Selenium-Webdriver and Cucumber.
83
74
 
84
75
  == Release instructions
85
76
 
86
77
  * Run tests - 'rake'
87
- * If you have not published with 'gem' before, run 'gem push' to enter your credentials (ignore failed publish error at the end)
88
78
  * Bump version - manually update file in lib/version.rb
89
- * Update the CHANGES[https://github.com/bbc-frameworks/frameworks-capybara/blob/master/CHANGES] log (see file for convention).
90
- * Run 'bundle install --binstubs --path vendor' to pick up new version in Gemfile
91
- * Commit 'Gemfile.lock' changes
79
+ * Run 'bundle install' to pick up new version in Gemfile
92
80
  * Release - 'rake release'
93
81
 
94
- You should see something like:
95
-
96
- frameworks-capybara 0.2.23 built to pkg/frameworks-capybara-0.2.23.gem
97
- Tagged v0.2.23
98
- Pushed git commits and tags
99
- Pushed frameworks-capybara 0.2.23 to rubygems.org
100
-
101
82
  == Contributing to frameworks-capybara
102
83
 
103
84
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -20,25 +20,12 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
 
23
- if RUBY_VERSION < "1.9"
24
- s.add_runtime_dependency("mime-types", ["~>1.25"])
25
- s.add_runtime_dependency("nokogiri", ["~>1.5.10"])
26
- s.add_runtime_dependency("rubyzip", ["~>0.9.9"])
27
- else
28
- s.add_runtime_dependency("mime-types")
29
- s.add_runtime_dependency("nokogiri")
30
- s.add_runtime_dependency("rubyzip")
31
- s.add_runtime_dependency("zip")
32
- end
33
- s.add_runtime_dependency("selenium-webdriver")
34
- s.add_runtime_dependency("capybara", ["~>1.1.2"])
35
- s.add_runtime_dependency("mechanize", ["2.7.2"])
36
- s.add_runtime_dependency("capybara-mechanize", [">=0.3.0"], ["<1.0.0"])
37
- s.add_runtime_dependency("json")
38
- s.add_runtime_dependency("headless")
23
+ s.add_runtime_dependency("capybara", [">=1.0.0"])
24
+ s.add_runtime_dependency("capybara-mechanize", [">=0.3.0"])
39
25
  s.add_runtime_dependency("capybara-celerity")
40
26
  s.add_runtime_dependency("w3c_validators")
41
- s.add_runtime_dependency("cucumber", [">= 0.10.5"])
27
+ s.add_development_dependency("cucumber", [">= 0.10.5"])
42
28
  s.add_development_dependency("rake")
43
29
  s.add_development_dependency("rspec", [">=1.0.0"])
30
+
44
31
  end
@@ -4,7 +4,6 @@ require 'monkey-patches/capybara-patches'
4
4
  require 'monkey-patches/capybara-mechanize-patches'
5
5
  require 'monkey-patches/mechanize-patches'
6
6
  require 'monkey-patches/send-keys'
7
- require 'monkey-patches/net-http-persistent-patches'
8
7
  require 'selenium-webdriver'
9
8
  require 'capybara/mechanize/cucumber'
10
9
  require 'capybara/celerity'
@@ -14,7 +13,6 @@ class CapybaraSetup
14
13
  attr_reader :driver
15
14
 
16
15
  def initialize
17
-
18
16
  http_proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
19
17
 
20
18
  capybara_opts = {:environment => ENV['ENVIRONMENT'],
@@ -24,33 +22,25 @@ class CapybaraSetup
24
22
  :javascript_enabled => ENV['CELERITY_JS_ENABLED'],
25
23
  :proxy_on => ENV['PROXY_ON'],
26
24
  :url => ENV['REMOTE_URL'],
27
- :chrome_switches => ENV['CHROME_SWITCHES'],
28
- :firefox_prefs => ENV['FIREFOX_PREFS'],
29
- :args => ENV['BROWSER_CLI_ARGS']
30
- }
25
+ :chrome_switches => ENV['CHROME_SWITCHES']}
31
26
 
32
27
  selenium_remote_opts = {:platform => ENV['PLATFORM'],
33
28
  :browser_name => ENV['REMOTE_BROWSER'],
34
29
  :version => ENV['REMOTE_BROWSER_VERSION'],
35
- :url => ENV['REMOTE_URL']
36
- }
30
+ :url => ENV['REMOTE_URL']}
37
31
 
38
32
  custom_opts = {:job_name => ENV['SAUCE_JOB_NAME'],
39
- :max_duration => ENV['SAUCE_MAX_DURATION'],
40
- :firefox_cert_path => ENV['FIREFOX_CERT_PATH'],
41
- :firefox_cert_prefix => ENV['FIREFOX_CERT_PREFIX']
42
- }
33
+ :max_duration => ENV['SAUCE_MAX_DURATION']}
43
34
 
44
35
  validate_env_vars(capybara_opts.merge(selenium_remote_opts)) #validate environment variables set using cucumber.yml or passed via command line
45
36
 
46
- @proxy_host = capybara_opts[:proxy].gsub(/http:\/\//,'').gsub(/:80.*/,'') unless capybara_opts[:proxy].nil?
37
+ @proxy_host = capybara_opts[:proxy].gsub(/http:\/\//,'').gsub(/:80/,'') unless capybara_opts[:proxy].nil?
47
38
  capybara_opts[:browser] = capybara_opts[:browser].intern #update :browser value to be a symbol, required for Selenium
48
39
  selenium_remote_opts[:browser_name] = selenium_remote_opts[:browser_name].intern if selenium_remote_opts[:browser_name]#update :browser value to be a symbol, required for Selenium
49
40
 
50
41
  Capybara.run_server = false #Disable rack server
51
42
 
52
43
  [capybara_opts, selenium_remote_opts, custom_opts].each do |opts| #delete nil options and environment (which is only used for validation)
53
-
54
44
  opts.delete_if {|k,v| (v.nil? or k == :environment)}
55
45
  end
56
46
 
@@ -84,41 +74,10 @@ class CapybaraSetup
84
74
  end
85
75
  end
86
76
 
87
- # WARNING: This modifies the Firefox profile passed in the parameters
88
- def update_firefox_profile_with_certificates(profile, certificate_path, certificate_prefix = '')
89
- profile_path = profile.layout_on_disk
90
-
91
- # Create links to the certificate files in the profile directory
92
- ['cert8.db', 'key3.db', 'secmod.db'].each do |cert_file|
93
- source_file = "#{certificate_prefix}#{cert_file}"
94
- source_path = "#{certificate_path}" + File::SEPARATOR + source_file
95
- dest_path = profile_path + File::SEPARATOR + cert_file
96
- if(! File.exist?(source_path))
97
- raise "Firefox cert db file #{source_path} does not exist."
98
- end
99
- FileUtils.cp(source_path, dest_path)
100
- end
101
-
102
- # Force the certificates to get pulled into the profile
103
- profile = Selenium::WebDriver::Firefox::Profile.new(profile_path)
104
-
105
- # Avoid Firefox certificate alerts
106
- profile["security.default_personal_cert"] = 'Select Automatically'
107
-
108
- return profile
109
- end
110
-
111
77
  def register_selenium_driver(opts,remote_opts,custom_opts)
112
78
  Capybara.register_driver :selenium do |app|
113
79
 
114
- if opts[:firefox_prefs] || opts[:profile]
115
- opts[:profile] = create_profile(opts[:profile], opts[:firefox_prefs])
116
-
117
- if custom_opts[:firefox_cert_path]
118
- opts[:profile] = update_firefox_profile_with_certificates(opts[:profile], custom_opts[:firefox_cert_path], custom_opts[:firefox_cert_prefix])
119
- end
120
- end
121
-
80
+ opts[:profile] = create_profile(opts[:profile]) if(opts[:profile])
122
81
  opts[:switches] = [opts.delete(:chrome_switches)] if(opts[:chrome_switches])
123
82
 
124
83
  if opts[:browser] == :remote
@@ -134,8 +93,7 @@ class CapybaraSetup
134
93
  opts[:desired_capabilities] = caps
135
94
  opts[:http_client] = client
136
95
  end
137
-
138
- clean_opts(opts, :proxy, :proxy_on, :firefox_prefs)
96
+ clean_opts(opts, :proxy, :proxy_on)
139
97
  Capybara::Selenium::Driver.new(app,opts)
140
98
  end
141
99
  :selenium
@@ -150,31 +108,24 @@ class CapybaraSetup
150
108
  Selenium::WebDriver::Proxy.new(:http => opts[:proxy]) if opts[:proxy] && opts[:proxy_on] != 'false' #set proxy on client connection if required, note you may use ENV['HTTP_PROXY'] for setting in browser (ff profile) but not for client conection, hence allow for PROXY_ON=false
151
109
  end
152
110
 
153
- def create_profile(profile_name = nil, additional_prefs = nil)
154
- additional_prefs = JSON.parse(additional_prefs) if additional_prefs
155
- if(additional_prefs && !profile_name)
156
- profile = Selenium::WebDriver::Firefox::Profile.new
157
- profile.native_events = true
158
- elsif(profile_name == 'BBC_INTERNAL')
111
+ def create_profile(profile_name)
112
+ if(profile_name == 'BBC_INTERNAL')
159
113
  profile = Selenium::WebDriver::Firefox::Profile.new
160
114
  profile["network.proxy.type"] = 1
161
- profile["network.proxy.no_proxies_on"] = "*.sandbox.dev.bbc.co.uk,*.sandbox.bbc.co.uk"
115
+ profile["network.proxy.no_proxies_on"] = "*.sandbox.dev.bbc.co.uk"
162
116
  profile["network.proxy.http"] = @proxy_host
163
117
  profile["network.proxy.ssl"] = @proxy_host
164
118
  profile["network.proxy.http_port"] = 80
165
119
  profile["network.proxy.ssl_port"] = 80
166
120
  profile.native_events = true
121
+ elsif(profile_name == 'DISABLED_REFERER')
122
+ profile = Selenium::WebDriver::Firefox::Profile.new
123
+ profile["network.http.sendRefererHeader"] = 0
124
+ profile.native_events = true
167
125
  else
168
126
  profile = Selenium::WebDriver::Firefox::Profile.from_name profile_name
169
127
  profile.native_events = true
170
128
  end
171
-
172
- if additional_prefs
173
- additional_prefs.each do |k, v|
174
- profile[k] = v
175
- end
176
- end
177
-
178
129
  profile
179
130
  end
180
131
 
@@ -196,7 +147,6 @@ class CapybaraSetup
196
147
  :mechanize
197
148
  end
198
149
 
199
-
200
150
  def clean_opts(opts, *args)
201
151
  args.each do |arg|
202
152
  opts.delete arg
@@ -2,7 +2,6 @@ require 'frameworks/capybara'
2
2
  require 'w3c_validators'
3
3
  require 'monkey-patches/cucumber-patches'
4
4
 
5
- #This is hackish but means we only run once in cucumber and not every scenario
6
5
  if(ENV['XVFB']=='true')
7
6
  puts "You have chosen to use XVFB - ensure you have yum installed Xvfb Xorg and firefox"
8
7
  require 'headless'
@@ -19,121 +18,55 @@ module Frameworks
19
18
  #Generate base urls to use in Cucumber step defs
20
19
  def generate_base_urls
21
20
  environment = ENV['ENVIRONMENT'].downcase #be defensive
22
-
23
- prepare_host
24
-
21
+ set_scheme
25
22
  if(environment =='sandbox')
26
23
  @base_url = @sandbox + @bbc_domain
27
- @pal_base_url = @sandbox + @bbc_domain
28
- @ssl_base_url = @sslsandbox + @bbc_domain
29
24
  @static_base_url = @static_sandbox + @bbc_domain
30
- @mobile_base_url = @mobiledot_prefix + "sandbox.dev" + @bbc_domain
31
- @m_base_url = @mdot_prefix + "sandbox.dev" + @bbc_domain
32
- elsif(environment =='sandbox6')
33
- @base_url = @sandbox6 + @bbc_domain
34
- @pal_base_url = @sandbox6 + @bbc_domain
35
- @ssl_base_url = @sslsandbox6 + @bbc_domain
36
- @static_base_url = @static_sandbox6 + @bbc_domain
37
- @mobile_base_url = @mobiledot_prefix + "sandbox" + @bbc_domain
38
- @m_base_url = @mdot_prefix + "sandbox" + @bbc_domain
39
25
  elsif (environment =='live' && ENV['WWW_LIVE']=='false')
40
26
  @base_url = @www_prefix.chop + @bbc_domain
41
- @pal_base_url = @pal_prefix + environment + @bbc_domain
42
- @ssl_base_url = @ssl_prefix.chop + @bbc_domain
43
27
  @static_base_url = @static_prefix.chop + @bbci_domain
44
28
  @open_base_url = @open_prefix.chop + @bbc_domain
45
- @mobile_base_url = @mobiledot_prefix.chop + @bbc_domain
46
- @m_base_url = @mdot_prefix.chop + @bbc_domain
29
+ elsif (environment.split('.')[0].include? 'pal') #address specific box
30
+ @base_url = "#{scheme}://#{ENV['ENVIRONMENT']}"
47
31
  else
48
32
  @base_url = @www_prefix + environment + @bbc_domain
49
- @pal_base_url = @pal_prefix + environment + @bbc_domain
50
- @ssl_base_url = @ssl_prefix + environment + @bbc_domain
51
33
  @static_base_url = @static_prefix + environment + @bbci_domain
52
34
  @static_base_url = @static_prefix.chop + @bbci_domain if environment == 'live'
53
35
  @open_base_url = @open_prefix + environment + @bbc_domain
54
- @mobile_base_url = @mobiledot_prefix + environment + @bbc_domain
55
- @m_base_url = @mdot_prefix + environment + @bbc_domain
56
36
  end
57
-
58
37
  proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
59
- proxy_parts = proxy.scan(/(?:http:\/\/)?([^\:]+)(?::(\d+))?/) if proxy && !proxy.empty?
60
- if proxy_parts && !proxy_parts.empty?
61
- @proxy_host = proxy_parts[0][0]
62
- if proxy_parts[0][1]
63
- @proxy_port = proxy_parts[0][1]
64
- else
65
- @proxy_port = "80"
66
- end
67
- end
38
+ @proxy_host = proxy.scan(/http:\/\/(.*):80/).to_s if proxy
68
39
  end
69
40
 
70
- def validate_online(src, validator_args = nil)
41
+ def validate_online(src)
71
42
 
72
- args = {:proxy_host => @proxy_host,:proxy_port => @proxy_port}
73
- if(validator_args != nil)
74
- args = args.merge(validator_args)
75
- end
76
- @validator = MarkupValidator.new(args)
43
+ @validator = MarkupValidator.new({:proxy_host => @proxy_host,:proxy_port => 80})
77
44
 
78
45
  @validator.set_doctype!(:xhtml)
79
46
  begin
80
-
81
47
  results = @validator.validate_text(src)
48
+ rescue Net::HTTPFatalError => e
49
+ puts "WARNING - OUTGOING NETWORK ERROR FROM FORGE TO W3C - Validation Not Performed"
50
+ end
82
51
 
83
- if results.errors.length > 0
84
- results.errors.each do |err|
85
- puts err.to_s
86
- end
87
- raise "W3C Validation failed."
52
+ if results.errors.length > 0
53
+ results.errors.each do |err|
54
+ puts err.to_s
88
55
  end
89
-
90
- rescue SystemCallError => e
91
- puts "System error whilst performing request to W3C: #{e}"
56
+ raise "W3C Validation of " + current_url + " failed."
92
57
  end
93
58
  end
94
59
 
95
- def prepare_host
60
+
61
+ def set_scheme
96
62
  ENV['SCHEME']=='https' ? scheme = 'https' : scheme = 'http'
97
63
  @www_prefix = "#{scheme}://www."
98
- @pal_prefix = "#{scheme}://pal."
99
- @ssl_prefix = "https://ssl."
100
64
  @static_prefix = "#{scheme}://static."
101
65
  @open_prefix = "#{scheme}://open."
102
- @bbc_domain = '.' + (ENV['FW_BBC_DOMAIN'] || 'bbc.co.uk')
66
+ @bbc_domain = '.bbc.co.uk'
103
67
  @bbci_domain = '.bbci.co.uk'
104
68
  @sandbox = "#{scheme}://pal.sandbox.dev"
105
- @sandbox6 = "#{scheme}://sandbox"
106
- @mobiledot_prefix = "#{scheme}://mobile."
107
- @mdot_prefix = "#{scheme}://m."
108
- @sslsandbox = "https://ssl.sandbox.dev"
109
- @sslsandbox6 = "https://ssl.sandbox"
110
69
  @static_sandbox = "#{scheme}://static.sandbox.dev"
111
- @static_sandbox6 = "#{scheme}://static.sandbox"
112
- end
113
-
114
- def setup_mechanize(agent, http_proxy=nil)
115
- http_proxy = http_proxy || ENV['HTTP_PROXY'] || ENV['http_proxy']
116
-
117
- if ENV['FW_CERT_LOCATION']
118
- agent.cert, agent.key = ENV['FW_CERT_LOCATION'], ENV['FW_CERT_LOCATION']
119
- end
120
-
121
- agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION']
122
- agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/)[0][0].to_s,80) if http_proxy && !http_proxy.empty?
123
-
124
- #This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed
125
- agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
126
-
127
- # This prevents Mechanize from raising a Mechanize::ResponseCodeError
128
- # when the HTTP Response Code is 404 or 503. This lets capybara continue the journey.
129
- agent.agent.allowed_error_codes = ['404', '503']
130
- end
131
-
132
- def new_mechanize(http_proxy=nil)
133
- require 'mechanize'
134
- agent = Mechanize.new
135
- setup_mechanize(agent, http_proxy)
136
- agent
137
70
  end
138
71
 
139
72
  end #EnvHelper
@@ -147,7 +80,15 @@ World(Frameworks::EnvHelper)
147
80
  Before do
148
81
  #This is ugly but unavoidable since Capybara::RackTest::Driver.reset_host! does @browser = nil and wipes all brower level settings
149
82
  #it was either this or a monkey patch - need to think about pushing a softer reset change to capybara-mechanize to override this
150
- setup_mechanize(page.driver.browser.agent) if page.driver.class == Capybara::Mechanize::Driver
83
+ http_proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
84
+ if page.driver.class == Capybara::Mechanize::Driver
85
+ page.driver.browser.agent.cert, page.driver.browser.agent.key = ENV['FW_CERT_LOCATION'], ENV['FW_CERT_LOCATION'] if ENV['FW_CERT_LOCATION']
86
+ page.driver.browser.agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION']
87
+ #TODO: Fix proxy logic globally...use system proxy instead of PROXY_URL
88
+ page.driver.browser.agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/).to_s,80) if http_proxy
89
+ #This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed
90
+ page.driver.browser.agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
91
+ end
151
92
 
152
93
  generate_base_urls
153
94
  end
@@ -2,7 +2,6 @@ require 'capybara/mechanize/cucumber'
2
2
  require 'uri'
3
3
  class Capybara::Mechanize::Browser
4
4
  #patch to remove catching all Mechanize exceptions (which are nice and specific) and throwing a useless RuntimeError
5
- #patch to add Referer (Mechanize@0.3.0 won't add Referer for urls starting with http(s)://.)
6
5
  def process_remote_request(method, url, attributes, headers)
7
6
  if remote?(url)
8
7
  uri = URI.parse(url)
@@ -10,23 +9,11 @@ class Capybara::Mechanize::Browser
10
9
  @last_remote_uri = uri
11
10
  url = uri.to_s
12
11
 
13
- referer = nil
14
- referer_candidate = current_url
15
- unless referer_candidate.empty? or (referer_candidate.start_with?('https://') and url.start_with?('http://'))
16
- referer = referer_candidate
17
- end
18
-
19
12
  reset_cache!
20
13
  args = []
21
14
  args << attributes unless attributes.empty?
22
15
  args << headers unless headers.empty?
23
-
24
- if method == :get
25
- agent.send(method, url, attributes, referer, headers)
26
- else
27
- agent.send(method, url, *args)
28
- end
29
-
16
+ @agent.send(method, url, *args)
30
17
  @last_request_remote = true
31
18
  end
32
19
  end
@@ -40,14 +27,12 @@ class Capybara::Mechanize::Driver
40
27
  browser.agent.cookie_jar.jar.each do |domain|
41
28
  domain[1].each do |path|
42
29
  path[1].each do |cookie|
43
-
44
30
  cookies.push({
45
31
  :name => cookie[1].name,
46
32
  :value => cookie[1].value,
47
33
  :domain => cookie[1].domain,
48
34
  :secure => cookie[1].secure,
49
35
  :expires => cookie[1].expires,
50
- :httponly => cookie[1].httponly,
51
36
  :path => cookie[1].path
52
37
  })
53
38
  end
@@ -76,26 +61,14 @@ class Capybara::Mechanize::Driver
76
61
  browser.agent.cookie_jar.clear!
77
62
  end
78
63
 
79
- def delete_cookies_in_domain(domain)
80
- cookies.each do |cookie|
81
- delete_cookie(cookie[:name]) if cookie[:domain].include?(domain)
82
- end
83
- end
84
-
64
+ FakeURI = Struct.new(:host)
85
65
  def add_cookie(attribs)
86
-
87
- cookie = HTTP::Cookie.new(
88
- attribs[:name],
89
- attribs[:value],
90
- :domain => attribs[:domain],
91
- :for_domain => true,
92
- :path => '/',
93
- :expires => attribs[:expires],
94
- :secure => attribs[:secure],
95
- :httponly => attribs[:httponly]
96
- )
97
-
98
- browser.agent.cookie_jar.add(cookie)
99
-
66
+ c = Mechanize::Cookie.new(attribs[:name],attribs[:value])
67
+ # remember: mechanize always removes leading '.' from domains
68
+ c.domain = attribs[:domain]
69
+ c.path = '/'
70
+ c.expires = attribs[:expires]
71
+ c.secure = attribs[:secure]
72
+ browser.agent.cookie_jar.add(FakeURI.new(c.domain),c)
100
73
  end
101
74
  end
@@ -43,10 +43,6 @@ class Capybara::Selenium::Driver
43
43
  def add_cookie(attribs)
44
44
  browser.manage.add_cookie(attribs)
45
45
  end
46
-
47
- def delete_cookies_in_domain(domain)
48
- browser.manage.delete_cookies_in_domain(domain)
49
- end
50
46
  end
51
47
 
52
48
  module Capybara
@@ -82,8 +78,6 @@ module Capybara
82
78
  driver.add_cookie(attribs)
83
79
  end
84
80
 
85
- def delete_cookies_in_domain(domain)
86
- driver.delete_cookies_in_domain(domain)
87
- end
88
81
  end
82
+
89
83
  end