frameworks-capybara 0.3.0.rc5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NGQ0MTAwMGMxNjgxNjc0MWZkYjdmNTBiYWJkOWM0N2MwMjRlNWY0Yw==
5
+ data.tar.gz: !binary |-
6
+ ODdmYmQyZWE1NGUxODJmN2ZmZTI3YTNhNjI0NGExYzE0NGY3NWI3ZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OTQxYjczYTljMThkMWVlZGRjNTMyNTJmZjQ2ZmY2NDQwMzhmM2NkNDMyNzg3
10
+ YWI2NjAyZmZmMmFjYzU2ZjIwYjk4YjNhNWZhYTBiNWJlNWNmZGU0ZWZlMDlh
11
+ MDkzZWRiOGU4NjBmMDQ3ODZkZmQxMTVkNTY5YTQ0ODcwZDUyMTk=
12
+ data.tar.gz: !binary |-
13
+ Mjc1NWU3MzIxY2MzNzI0NzFjMzc5MTkzZmMyNDU4MTg1ZTk1YWRlOTA5ZWFk
14
+ Y2NlMThhMmZhMTg0ODE2YWMzYzQ4NWQyNmViYTdmMzkyZmQ2N2U1NDJjMDI2
15
+ OWUyYjU0ZDMyOGYyNDEyNmJiMmZkYjJkNjBjZjAxN2FmZmI2NTk=
data/.travis.yml CHANGED
@@ -3,10 +3,6 @@ before_install:
3
3
  - sudo apt-get install xvfb
4
4
  language: ruby
5
5
  rvm:
6
- - 1.8.7
7
- - 1.9.2
8
6
  - 1.9.3
9
- - jruby-18mode # JRuby in 1.8 mode
10
- - jruby-19mode # JRuby in 1.9 mode
11
- # uncomment this line if your project needs to run something other than `rake`:
12
- # # script: bundle exec rspec spec
7
+ - 2.0.0
8
+ - 2.1.0
data/CHANGES ADDED
@@ -0,0 +1,52 @@
1
+ 1.0.0
2
+ Base required Ruby version now 1.9.3 or later
3
+ Bumped gem dependency versions
4
+ Updated Travis build lists to include Ruby 2.0, 2.1
5
+
6
+ 0.2.34
7
+ Improved validate_online method to disregard system/OS errors.
8
+
9
+ 0.2.33
10
+ Specify different runtime dependencies depending on the ruby version.
11
+
12
+ 0.2.32
13
+ Fix Ruby 1.9 RSpec test failures introduced in release 0.2.31
14
+
15
+ 0.2.31
16
+ Added Firefox profile certificate handling via the FIREFOX_CERT_PATH and FIREFOX_CERT_PREFIX variables.
17
+
18
+ 0.2.30
19
+ Fixed rake profiles listings to work with Ruby 1.9+
20
+
21
+ 0.2.29
22
+ Updated add_cookie patch to use new http_cookie API, following Mechanize changes (see http://bit.ly/12Do1l7)
23
+
24
+ 0.2.28
25
+ Updated Mechanize::CookieJar add patch to work with latest capybara-mechanize.
26
+ Added support for httpOnly cookie flag to capybara mechanize patch
27
+
28
+ 0.2.27
29
+ Can now specify arguments passed to the browser via the BROWSER_CLI_ARGS environment variable.
30
+
31
+ 0.2.25
32
+ Modified cucumber html report monkey patch to work with cucumber >= 1.3.0
33
+
34
+ 0.2.24
35
+ Added FW_BBC_DOMAIN param in order to set the top level domain used for requests.
36
+
37
+ 0.2.23
38
+ Updated capybara-mechanize patch to send referer header.
39
+
40
+ 0.2.22
41
+ Update Centos6 sandbox DNS to sandbox.bbc.co.uk.
42
+
43
+ 0.2.21
44
+ Add support for Centos6 sandbox.
45
+ Update Gemfile.lock to latest gem versions.
46
+
47
+ 0.2.20
48
+ validate_online() now takes optional hash of parameters to pass to MarkupValidator.
49
+ Updated proxy handling to pick up port and to work without protocol or port.
50
+
51
+ 0.2.19
52
+ Present production release.
data/Gemfile CHANGED
@@ -1,7 +1,9 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
3
  platforms :jruby do
4
4
  gem "jruby-openssl"
5
5
  end
6
6
 
7
+ gem "rspec-mocks", "<2.14.0"
8
+
7
9
  gemspec
data/Gemfile.lock CHANGED
@@ -1,22 +1,25 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- frameworks-capybara (0.3.0.rc5)
5
- capybara (>= 1.0.0)
4
+ frameworks-capybara (1.0.0)
5
+ capybara (~> 1.1.2)
6
6
  capybara-celerity
7
- capybara-mechanize (>= 0.3.0)
8
- capybara-webkit
7
+ capybara-mechanize (>= 0.3.0, < 1.0.0)
9
8
  cucumber (>= 0.10.5)
10
9
  headless
11
10
  json
11
+ mechanize (= 2.7.2)
12
+ mime-types
13
+ nokogiri
14
+ rubyzip
15
+ selenium-webdriver
12
16
  w3c_validators
13
17
 
14
18
  GEM
15
- remote: http://rubygems.org/
19
+ remote: https://rubygems.org/
16
20
  specs:
17
- addressable (2.2.8)
18
- builder (3.0.0)
19
- capybara (1.1.2)
21
+ builder (3.2.2)
22
+ capybara (1.1.4)
20
23
  mime-types (>= 1.16)
21
24
  nokogiri (>= 1.3.3)
22
25
  rack (>= 1.0.0)
@@ -29,66 +32,69 @@ GEM
29
32
  capybara-mechanize (0.3.0)
30
33
  capybara (~> 1.1)
31
34
  mechanize (~> 2.3)
32
- capybara-webkit (0.12.1)
33
- capybara (>= 1.0.0, < 1.2)
34
- json
35
35
  celerity (0.9.2)
36
- childprocess (0.3.3)
37
- ffi (~> 1.0.6)
38
- cucumber (1.2.1)
36
+ childprocess (0.5.1)
37
+ ffi (~> 1.0, >= 1.0.11)
38
+ cucumber (1.3.10)
39
39
  builder (>= 2.1.2)
40
40
  diff-lcs (>= 1.1.3)
41
- gherkin (~> 2.11.0)
42
- json (>= 1.4.6)
43
- diff-lcs (1.1.3)
44
- domain_name (0.5.3)
45
- unf (~> 0.0.3)
46
- ffi (1.0.11)
47
- gherkin (2.11.1)
48
- json (>= 1.4.6)
49
- headless (0.3.1)
50
- json (1.7.3)
51
- libwebsocket (0.1.4)
52
- addressable
53
- mechanize (2.5.1)
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.16)
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)
54
55
  domain_name (~> 0.5, >= 0.5.1)
56
+ http-cookie (~> 1.0.0)
55
57
  mime-types (~> 1.17, >= 1.17.2)
56
58
  net-http-digest_auth (~> 1.1, >= 1.1.1)
57
59
  net-http-persistent (~> 2.5, >= 2.5.2)
58
60
  nokogiri (~> 1.4)
59
61
  ntlm-http (~> 0.1, >= 0.1.1)
60
- webrobots (~> 0.0, >= 0.0.9)
61
- mime-types (1.19)
62
- multi_json (1.3.6)
63
- net-http-digest_auth (1.2.1)
64
- net-http-persistent (2.7)
65
- nokogiri (1.5.5)
62
+ webrobots (>= 0.0.9, < 0.2)
63
+ mime-types (1.25.1)
64
+ mini_portile (0.5.2)
65
+ multi_json (1.8.4)
66
+ multi_test (0.0.3)
67
+ net-http-digest_auth (1.4)
68
+ net-http-persistent (2.9.4)
69
+ nokogiri (1.6.1)
70
+ mini_portile (~> 0.5.0)
66
71
  ntlm-http (0.1.1)
67
- rack (1.4.1)
68
- rack-test (0.6.1)
72
+ rack (1.5.2)
73
+ rack-test (0.6.2)
69
74
  rack (>= 1.0)
70
- rake (0.9.2.2)
71
- rspec (2.10.0)
72
- rspec-core (~> 2.10.0)
73
- rspec-expectations (~> 2.10.0)
74
- rspec-mocks (~> 2.10.0)
75
- rspec-core (2.10.1)
76
- rspec-expectations (2.10.0)
77
- diff-lcs (~> 1.1.3)
78
- rspec-mocks (2.10.1)
79
- rubyzip (0.9.9)
80
- selenium-webdriver (2.24.0)
81
- childprocess (>= 0.2.5)
82
- libwebsocket (~> 0.1.3)
75
+ rake (10.1.1)
76
+ rspec (2.13.0)
77
+ rspec-core (~> 2.13.0)
78
+ rspec-expectations (~> 2.13.0)
79
+ rspec-mocks (~> 2.13.0)
80
+ rspec-core (2.13.1)
81
+ rspec-expectations (2.13.0)
82
+ diff-lcs (>= 1.1.3, < 2.0)
83
+ rspec-mocks (2.13.1)
84
+ rubyzip (1.1.0)
85
+ selenium-webdriver (2.40.0)
86
+ childprocess (>= 0.5.0)
83
87
  multi_json (~> 1.0)
84
- rubyzip
85
- unf (0.0.5)
88
+ rubyzip (~> 1.0)
89
+ websocket (~> 1.0.4)
90
+ unf (0.1.3)
86
91
  unf_ext
87
- unf_ext (0.0.5)
92
+ unf_ext (0.0.6)
88
93
  w3c_validators (1.2)
89
94
  json
90
95
  nokogiri
91
- webrobots (0.0.13)
96
+ webrobots (0.1.1)
97
+ websocket (1.0.7)
92
98
  xpath (0.1.4)
93
99
  nokogiri (~> 1.3)
94
100
 
@@ -100,3 +106,4 @@ DEPENDENCIES
100
106
  jruby-openssl
101
107
  rake
102
108
  rspec (>= 1.0.0)
109
+ rspec-mocks (< 2.14.0)
data/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Build Status {<img src="https://secure.travis-ci.org/mcrmfc/frameworks-capybara.png"/>}[https://secure.travis-ci.org/mcrmfc/frameworks-capybara]
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
2
 
3
3
  = frameworks-capybara
4
4
 
@@ -27,7 +27,7 @@ In your env.rb simply add:
27
27
 
28
28
  The following environment variables can be set to configure your tests:
29
29
 
30
- ENVIRONMENT - this must be one of either 'sandbox', 'int', 'test', 'stage', 'live'
30
+ ENVIRONMENT - this must be one of either 'sandbox', 'sandbox6', 'int', 'test', 'stage', 'live'
31
31
  BROWSER - this must be one of either 'ie', 'firefox', 'chrome', 'headless', 'remote'
32
32
  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
33
  PLATFORM - used when specifying remote test on a grid that provides a choice of platforms, this must be one of either 'WINDOWS' or 'LINUX'
@@ -37,11 +37,16 @@ The following environment variables can be set to configure your tests:
37
37
  REMOTE_URL - URL of remote Selenium-Webdriver server e.g. http://yourremotehost:4444/wd/hub
38
38
  FIREFOX_PROFILE - specify a firefox profile to use when running in-browser tests (local or remote)
39
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)
40
42
  CREATE_NEW_FF_PROFILE - create a new Firefox profile with name provided by FIREFOX_PROFILE
41
43
  CELERITY_JS_ENABLED (string - 'true', 'false') - determines whether Celerity (HTMLUnit) attempts to execute javascript
42
44
  XVFB - (string - 'true', 'false') - determines whether XVFB is used to run browser (i.e. headless Firefox on *nix platform)
43
45
  FW_CERT_LOCATION - path to client certificate (combined pem)
44
46
  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
45
50
 
46
51
  Here is a sample cucumber.yml:
47
52
 
@@ -74,15 +79,25 @@ This gem also sets up a number of 'base urls' for you to use in your tests, thes
74
79
  @base_static_url
75
80
  @base_open_url
76
81
 
77
- Finally this gem contains some useful monkey-patches to core libraries e.g. Capybara, Selenium-Webdriver and Cucumber.
82
+ Finally this gem contains some useful monkey-patches to core libraries e.g. Capybara-Mechanize, Selenium-Webdriver and Cucumber.
78
83
 
79
84
  == Release instructions
80
85
 
81
86
  * 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)
82
88
  * Bump version - manually update file in lib/version.rb
83
- * Run 'bundle install' to pick up new version in Gemfile
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
84
92
  * Release - 'rake release'
85
93
 
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
+
86
101
  == Contributing to frameworks-capybara
87
102
 
88
103
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -20,9 +20,13 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.files = `git ls-files`.split("\n")
22
22
 
23
- s.add_runtime_dependency("capybara", [">=1.0.0"])
24
- s.add_runtime_dependency("capybara-mechanize", [">=0.3.0"])
25
- s.add_runtime_dependency("capybara-webkit")
23
+ s.add_runtime_dependency("mime-types")
24
+ s.add_runtime_dependency("nokogiri")
25
+ s.add_runtime_dependency("rubyzip")
26
+ s.add_runtime_dependency("selenium-webdriver")
27
+ s.add_runtime_dependency("capybara", ["~>1.1.2"])
28
+ s.add_runtime_dependency("mechanize", ["2.7.2"])
29
+ s.add_runtime_dependency("capybara-mechanize", [">=0.3.0"], ["<1.0.0"])
26
30
  s.add_runtime_dependency("json")
27
31
  s.add_runtime_dependency("headless")
28
32
  s.add_runtime_dependency("capybara-celerity")
@@ -1,7 +1,6 @@
1
1
  require 'capybara/cucumber'
2
2
  require 'monkey-patches/webdriver-patches'
3
3
  require 'monkey-patches/capybara-patches'
4
- require 'monkey-patches/capybara-webkit-patches'
5
4
  require 'monkey-patches/capybara-mechanize-patches'
6
5
  require 'monkey-patches/mechanize-patches'
7
6
  require 'monkey-patches/send-keys'
@@ -9,7 +8,6 @@ require 'monkey-patches/net-http-persistent-patches'
9
8
  require 'selenium-webdriver'
10
9
  require 'capybara/mechanize/cucumber'
11
10
  require 'capybara/celerity'
12
- require 'capybara-webkit'
13
11
 
14
12
  class CapybaraSetup
15
13
 
@@ -27,19 +25,25 @@ class CapybaraSetup
27
25
  :proxy_on => ENV['PROXY_ON'],
28
26
  :url => ENV['REMOTE_URL'],
29
27
  :chrome_switches => ENV['CHROME_SWITCHES'],
30
- :firefox_prefs => ENV['FIREFOX_PREFS']}
28
+ :firefox_prefs => ENV['FIREFOX_PREFS'],
29
+ :args => ENV['BROWSER_CLI_ARGS']
30
+ }
31
31
 
32
32
  selenium_remote_opts = {:platform => ENV['PLATFORM'],
33
33
  :browser_name => ENV['REMOTE_BROWSER'],
34
34
  :version => ENV['REMOTE_BROWSER_VERSION'],
35
- :url => ENV['REMOTE_URL']}
35
+ :url => ENV['REMOTE_URL']
36
+ }
36
37
 
37
38
  custom_opts = {:job_name => ENV['SAUCE_JOB_NAME'],
38
- :max_duration => ENV['SAUCE_MAX_DURATION']}
39
+ :max_duration => ENV['SAUCE_MAX_DURATION'],
40
+ :firefox_cert_path => ENV['FIREFOX_CERT_PATH'],
41
+ :firefox_cert_prefix => ENV['FIREFOX_CERT_PREFIX']
42
+ }
39
43
 
40
44
  validate_env_vars(capybara_opts.merge(selenium_remote_opts)) #validate environment variables set using cucumber.yml or passed via command line
41
45
 
42
- @proxy_host = capybara_opts[:proxy].gsub(/http:\/\//,'').gsub(/:80/,'') unless capybara_opts[:proxy].nil?
46
+ @proxy_host = capybara_opts[:proxy].gsub(/http:\/\//,'').gsub(/:80.*/,'') unless capybara_opts[:proxy].nil?
43
47
  capybara_opts[:browser] = capybara_opts[:browser].intern #update :browser value to be a symbol, required for Selenium
44
48
  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
45
49
 
@@ -55,8 +59,6 @@ class CapybaraSetup
55
59
  @driver = register_celerity_driver(capybara_opts)
56
60
  when :mechanize then
57
61
  @driver = register_mechanize_driver(capybara_opts)
58
- when :webkit then
59
- @driver = register_webkit_driver(capybara_opts)
60
62
  else
61
63
  @driver = register_selenium_driver(capybara_opts, selenium_remote_opts, custom_opts)
62
64
  end
@@ -82,11 +84,39 @@ class CapybaraSetup
82
84
  end
83
85
  end
84
86
 
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
+
85
111
  def register_selenium_driver(opts,remote_opts,custom_opts)
86
112
  Capybara.register_driver :selenium do |app|
87
113
 
88
114
  if opts[:firefox_prefs] || opts[:profile]
89
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
90
120
  end
91
121
 
92
122
  opts[:switches] = [opts.delete(:chrome_switches)] if(opts[:chrome_switches])
@@ -128,7 +158,7 @@ class CapybaraSetup
128
158
  elsif(profile_name == 'BBC_INTERNAL')
129
159
  profile = Selenium::WebDriver::Firefox::Profile.new
130
160
  profile["network.proxy.type"] = 1
131
- profile["network.proxy.no_proxies_on"] = "*.sandbox.dev.bbc.co.uk"
161
+ profile["network.proxy.no_proxies_on"] = "*.sandbox.dev.bbc.co.uk,*.sandbox.bbc.co.uk"
132
162
  profile["network.proxy.http"] = @proxy_host
133
163
  profile["network.proxy.ssl"] = @proxy_host
134
164
  profile["network.proxy.http_port"] = 80
@@ -166,13 +196,6 @@ class CapybaraSetup
166
196
  :mechanize
167
197
  end
168
198
 
169
- def register_webkit_driver(opts)
170
- Capybara.register_driver :webkit do |app|
171
- Capybara::Driver::Webkit.new(app)
172
- end
173
- Capybara.javascript_driver = :webkit
174
- :webkit
175
- end
176
199
 
177
200
  def clean_opts(opts, *args)
178
201
  args.each do |arg|
@@ -3,7 +3,7 @@ require 'w3c_validators'
3
3
  require 'monkey-patches/cucumber-patches'
4
4
 
5
5
  #This is hackish but means we only run once in cucumber and not every scenario
6
- if(ENV['XVFB']=='true' || ENV['BROWSER'] == 'webkit')
6
+ if(ENV['XVFB']=='true')
7
7
  puts "You have chosen to use XVFB - ensure you have yum installed Xvfb Xorg and firefox"
8
8
  require 'headless'
9
9
  headless = Headless.new
@@ -27,8 +27,15 @@ module Frameworks
27
27
  @pal_base_url = @sandbox + @bbc_domain
28
28
  @ssl_base_url = @sslsandbox + @bbc_domain
29
29
  @static_base_url = @static_sandbox + @bbc_domain
30
- @mobile_base_url = @mobiledot_prefix + "sandbox.dev.bbc.co.uk"
31
- @m_base_url = @mdot_prefix + "sandbox.dev.bbc.co.uk"
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
32
39
  elsif (environment =='live' && ENV['WWW_LIVE']=='false')
33
40
  @base_url = @www_prefix.chop + @bbc_domain
34
41
  @pal_base_url = @pal_prefix + environment + @bbc_domain
@@ -49,12 +56,24 @@ module Frameworks
49
56
  end
50
57
 
51
58
  proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
52
- @proxy_host = proxy.scan(/http:\/\/(.*):80/)[0][0] if 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
53
68
  end
54
69
 
55
- def validate_online(src)
70
+ def validate_online(src, validator_args = nil)
56
71
 
57
- @validator = MarkupValidator.new({:proxy_host => @proxy_host,:proxy_port => 80})
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)
58
77
 
59
78
  @validator.set_doctype!(:xhtml)
60
79
  begin
@@ -65,11 +84,11 @@ module Frameworks
65
84
  results.errors.each do |err|
66
85
  puts err.to_s
67
86
  end
68
- raise "W3C Validation of " + current_url + " failed."
87
+ raise "W3C Validation failed."
69
88
  end
70
89
 
71
- rescue Net::HTTPFatalError => e
72
- puts "WARNING - OUTGOING NETWORK ERROR FROM FORGE TO W3C - Validation Not Performed"
90
+ rescue SystemCallError => e
91
+ puts "System error whilst performing request to W3C: #{e}"
73
92
  end
74
93
  end
75
94
 
@@ -80,13 +99,41 @@ module Frameworks
80
99
  @ssl_prefix = "https://ssl."
81
100
  @static_prefix = "#{scheme}://static."
82
101
  @open_prefix = "#{scheme}://open."
83
- @bbc_domain = '.bbc.co.uk'
102
+ @bbc_domain = '.' + (ENV['FW_BBC_DOMAIN'] || 'bbc.co.uk')
84
103
  @bbci_domain = '.bbci.co.uk'
85
104
  @sandbox = "#{scheme}://pal.sandbox.dev"
105
+ @sandbox6 = "#{scheme}://sandbox"
86
106
  @mobiledot_prefix = "#{scheme}://mobile."
87
107
  @mdot_prefix = "#{scheme}://m."
88
108
  @sslsandbox = "https://ssl.sandbox.dev"
109
+ @sslsandbox6 = "https://ssl.sandbox"
89
110
  @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
90
137
  end
91
138
 
92
139
  end #EnvHelper
@@ -100,29 +147,7 @@ World(Frameworks::EnvHelper)
100
147
  Before do
101
148
  #This is ugly but unavoidable since Capybara::RackTest::Driver.reset_host! does @browser = nil and wipes all brower level settings
102
149
  #it was either this or a monkey patch - need to think about pushing a softer reset change to capybara-mechanize to override this
103
- http_proxy = ENV['HTTP_PROXY'] || ENV['http_proxy']
104
- if page.driver.class == Capybara::Mechanize::Driver
105
-
106
- if ENV['FW_CERT_LOCATION']
107
- page.driver.browser.agent.cert, page.driver.browser.agent.key =
108
- ENV['FW_CERT_LOCATION'],
109
- ENV['FW_CERT_LOCATION']
110
- end
111
-
112
- page.driver.browser.agent.ca_file = ENV['CA_CERT_LOCATION'] if ENV['CA_CERT_LOCATION']
113
-
114
- page.driver.browser.agent.set_proxy(http_proxy.scan(/http:\/\/(.*):80/).to_s,80) if http_proxy
115
-
116
- #This is necessary because Mech2 does not ship with root certs like Mech1 did and boxes may not have the OpenSSL set installed
117
- page.driver.browser.agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
118
- end
119
-
120
- #TODO: See if this can be set at the driver level rather than in before do - and only want to start headless once
121
- if page.driver.class == Capybara::Driver::Webkit
122
- page.driver.browser.ignore_ssl_errors #shouldn't have to do this on test but for some reason do
123
- page.driver.browser.set_proxy(:host => http_proxy.scan(/http:\/\/(.*):80/).to_s,:port => '80') if http_proxy
124
- end
125
-
150
+ setup_mechanize(page.driver.browser.agent) if page.driver.class == Capybara::Mechanize::Driver
126
151
 
127
152
  generate_base_urls
128
153
  end
@@ -2,6 +2,7 @@ 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)://.)
5
6
  def process_remote_request(method, url, attributes, headers)
6
7
  if remote?(url)
7
8
  uri = URI.parse(url)
@@ -9,11 +10,23 @@ class Capybara::Mechanize::Browser
9
10
  @last_remote_uri = uri
10
11
  url = uri.to_s
11
12
 
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
+
12
19
  reset_cache!
13
20
  args = []
14
21
  args << attributes unless attributes.empty?
15
22
  args << headers unless headers.empty?
16
- @agent.send(method, url, *args)
23
+
24
+ if method == :get
25
+ agent.send(method, url, attributes, referer, headers)
26
+ else
27
+ agent.send(method, url, *args)
28
+ end
29
+
17
30
  @last_request_remote = true
18
31
  end
19
32
  end
@@ -27,12 +40,14 @@ class Capybara::Mechanize::Driver
27
40
  browser.agent.cookie_jar.jar.each do |domain|
28
41
  domain[1].each do |path|
29
42
  path[1].each do |cookie|
43
+
30
44
  cookies.push({
31
45
  :name => cookie[1].name,
32
46
  :value => cookie[1].value,
33
47
  :domain => cookie[1].domain,
34
48
  :secure => cookie[1].secure,
35
49
  :expires => cookie[1].expires,
50
+ :httponly => cookie[1].httponly,
36
51
  :path => cookie[1].path
37
52
  })
38
53
  end
@@ -67,14 +82,20 @@ class Capybara::Mechanize::Driver
67
82
  end
68
83
  end
69
84
 
70
- FakeURI = Struct.new(:host)
71
85
  def add_cookie(attribs)
72
- c = Mechanize::Cookie.new(attribs[:name],attribs[:value])
73
- # remember: mechanize always removes leading '.' from domains
74
- c.domain = attribs[:domain]
75
- c.path = '/'
76
- c.expires = attribs[:expires]
77
- c.secure = attribs[:secure]
78
- browser.agent.cookie_jar.add(FakeURI.new(c.domain),c)
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
+
79
100
  end
80
101
  end