http - Using Cucumber/Capybara in Rails 3, how do I set a custom User-Agent string? -
In my Rail 3 app, I have different layouts for the iPhone vs. desktop browser. I use cucumber / capebara I'm trying to test the iPhone layout. Until now, all attempts to set an iPhone user-agent string in the HTTP header of the request have failed.
I followed the tutorial but requested not to set user-agent string in HTTP.
If I only browse my rail app using my iPhone app, then I get the right layout. I am using to set up Rail Request. Iphone
How to do this work but any thoughts? I'm about to go back to Capybara ditch and Webrat.
Here's what I have till now :.
Feature: Browser Detection Ranking To Keep Different Layouts For iPhone vs. Desktop Browsers As a Developer I want to show different layouts for different browsers. Scenario: Show the home page with the desktop layout, I'm using "a desktop browser" when I go to "home page" then "Desktop Browser" scenario: Show the home page with the iPhone layout I "Mobile Safari "when I go to" Home Page "then show me the page then I should see" Mobile Safari "
Detect_browser_steps .rb
< Using code> given / ^ (?: | I) (. +) $ / Do | Browser | Case Browser: "Mobile Safari" agent = "Mozilla / 5.0 (iPhone, U, CPU iPhone OS 3_1_2 like Mac OS X; en-us) AppleWebKit / 528.18 (KHTML, like Lizard) Version / 4.0 Mobile / 7D11 Safari / 528.16 "add_headers ({'user-agent' = & gt; agent}) and # no special user-agent header end end
headers_hack.rb
< Pre> # http://aflatter.de/2010/06/testing-headers-and-ssl-with-cucumber-and-capybara/ # The following solutions will work only when you use it: rack_test driver modules La RackTestMixin def self.included (mod) mod.class_eval do # This is where we save additional entries. Def hacked_env @hacked_env || = {} End # Alias_method for original use of the nickname: original_env,: env # Override the method to merge additional headers # Plus This implication makes it public; def env original_env.merge (hacked_env) end-end End Capybara :: Driver :: RackTest.send: included, RackTestMixin module HeadersHackHelper def add_headers (header) page.driver.hacked_env.merge (header) end-end world (HeadersHackHelper)
There was something to be stupid, but in the end I used to do it Managed simply by adding:
# features / support / capybara_headers.rb: Module CapybaraHeadersHelper def add_headers (header) to headers.each | Name, price | Page.driver.browser.header (name, value) end-end world (CapybaraHeadersHelper)
You can find more information in this I wrote, but that is basically this is.
Comments
Post a Comment