bloc referral

If you are interested in learning to code with a mentor, try bloc and get $100 off.

Wednesday, October 15, 2014

Capybara page.save_screenshot('screenshot.png')

I spent a lot of time trying to fix integration test at work and have experience using the `save_and_open_page` command to view the actual page. This has been an awesome addition to my test debugging, but recently I discovered a new command `page.save_screenshot('screenshot.png')`.

The screenshot command only works with pages and test that use Javascript, and are great to check to see if the functionality is really happening in a controlled environment.

I spent the past weeks working on a filtered search using Sunspot/SOLR which is all new stuff for me. SOLR is basically a tool to do searching of the database and Sunspot is the gem that connects Rails to SOLR easily.

SOLR has specific methods that query the database and I spent a lot of time checking out a number of them and testing the UI to be sure the correct data shows.

I am sure I could of spent the entire time in the terminal testing functionality but using my integration test and the Capybara screenshot command to view the actual page was a little more rewarding.

If you have integration test I highly recommend using Capybara to debug integration testing. I wrote this post to remind myself of the syntax, since I literally google it every time I need to use it.

*UPDATE: the screenshot call only works if you enable javascript in your test, with something like selenium:

 `def switch_to_javascript
    Capybara.javascript_driver = :selenium if ENV["FF"]
    Capybara.current_driver = Capybara.javascript_driver
  end
'

Thanks Adam Brice for pointing that out.

2 comments:

  1. You can discover a great cord for web page save and page open this command is help full for only works with pages and test that use Javascript...

    Web Development

    ReplyDelete
  2. very true, I will update my post to include that note.

    ReplyDelete