I am creating a Rails 3 application that displays different views for mobile devices (using jQuery Mobile) and regular desktop browsers. I am testing Cucumber / Capybara and have separate test suites for mobile devices and a browser. I can set the User-Agent mobile line in the HTTP request header just fine using the header header found here ...
Using Cucumber / Capybara in Rails 3, how to set a User-Agent user line?
Problem...
Most of my Cucumber mobile steps work fine (for example, I set the title of the mobile device to a step, after which the mobile views are rendered). However, after submitting the form, the test then displays the browser view in the next step (and not the mobile view that I want). I think this could be due to Capybara throwing a header after the form submit action.
I tried to verify this by adding a logger to my controller action so that I could view the user_agent headers as follows:
def show # … logger.info("Headers: #{request.user_agent}") # … end
I used the iPhone header (buyer is a resource). In my test.log, I see:
For the create action ...
Started POST "/buyers" for 127.0.0.1 at 2011-04-19 16:49:18 -0700 Processing by BuyersController
For the next show action (note "Headers: empty) ...
Started GET "/buyers/1" for 127.0.0.1 at 2011-04-19 16:49:18 -0700 Processing by BuyersController
As you would expect, "show me the page step, and then display the browser page, not the mobile page I want.
How to save the title so that all my mobile actions are performed in my mobile test suite?
Update
Jnicklas (creator of the truly amazing Capybara stone!) Replies:
"This is more a question than a problem. Tbh. There is currently no way to achieve this disadvantage in Rack-Test, which I know. I was thinking of adding a header option to the rack driver that will allow for the transfer of various header options. If you use a lot of JavaScript, Selenium may be better anyway and allows you to freely install the user agent, IIRC. "
https://github.com/jnicklas
https://github.com/jnicklas/capybara