Shoot

Shoot is a helper library to take screenshots using BrowserStack. If you don't need a full integration test coupled with screenshots, it's a simpler choice.

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'shoot'
end

And then execute:

$ bundle

Also add the following environment variables: BROWSERSTACK_USER and BROWSERSTACK_KEY. The way you do it is up to you (we recommend either dotenv or an export in your personal files).

Usage

Shoot installs a binary. To inspect it, just run:

$ shoot

The first thing you should do is:

$ shoot list
ID   OS #                Browser #     Device
0    OS X Snow Leopard   safari 5.1
1    OS X Snow Leopard   chrome 14.0
2    OS X Snow Leopard   chrome 16.0
...
537  ios 7.0             ipad          iPad mini Retina
538  ios 7.0             iphone        iPhone 5S
539  ios 7.0             iphone        iPhone 5C

The list command basically fetches all browsers available on BrowserStack and caches them locally on .screenshots/.browsers.json. You can choose to add this folder on your .gitignore, since shoot will save all images there as well.

Then, you can choose to activate the browsers you wanna use, based on id. Example:

$ shoot activate 2

This will activate (given your output is the same as above) chrome 16 on OS X Snow Leopard.

Now, create a scenario. Here's an example:

class MyScenario < Shoot::Scenario
    def 
        visit "http://url.to.login"
    end
end

As you can see, it follows capybara's syntax, so you can visit pages, fill forms, click links and so on...

Now run:

$ shoot scenario my_scenario.rb

This will run all the methods of MyScenario and generate screenshots for all active browsers, at the end of each method.

The resulting images will be saved on .screenshots folder.

If you wanna have multiple shots on each method, use the shoot method:

class MyScenario < Shoot::Scenario
    def 
        visit "http://url.to.login"
        shoot(:blank_form)

        fill_in('user', with: 'john')
        fill_in('password', with: '1234')
        shoot(:filled_form)

        click_button('Login')
        find('#welcome') # This makes sure it waits before you take another shot
        shoot(:welcome_page)
    end
end

If you wanna just test your scenarios, without paying SauceLabs and wasting time with remote connections:

$ shoot test my_scenario.rb

Or you can run a whole folder, like:

$ shoot test my_scenarios/

The test command will run locally using phantomjs (capybara).

You can choose to deactivate the browsers you don't wanna use, based on id as well. Example:

$ shoot deactivate 2

This will deactivate (given your output is the same as above) chrome 16 on OS X Snow Leopard.

If you want to deactivate all the active browsers at once you can run:

$ shoot deactivate_all

To open all screenshots (on a Mac), run:

$ shoot open

Contributing

  1. Fork it ( https://github.com/joaomilho/shoot/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request