Using Cucumber/Capybara in Rails 3, how do I set a custom User-Agent string?

前端 未结 2 1372
长发绾君心
长发绾君心 2020-12-20 02:28

In my Rails 3 app, I have different layouts for iPhone vs desktop browsers. I\'m trying to test the iPhone layout using Cucumber/Capybara. So far, all my attempts at setting

2条回答
  •  半阙折子戏
    2020-12-20 03:20

    Had to fiddle a bit on this, but in the end I managed to get it working just by adding:

    # features/support/capybara_headers.rb:
    
    module CapybaraHeadersHelper
      def add_headers(headers)
        headers.each do |name, value|
          page.driver.browser.header(name, value)
        end
      end
    end
    World(CapybaraHeadersHelper)
    

    You can get more info in this blog post I wrote, but that's basically it.

提交回复
热议问题