Coder Social home page Coder Social logo

calliper's Introduction

Calliper

Protractor for Ruby, or testing your Angular application with elegance.

Thought this is only but a (working) hack for now.

Support

It currently supports Rack and Rails applications with Minitest, but it should be possible to hack in support for other frameworks (eg: Sinatra, RSpec).

Usage

Add the calliper gem to your Gemfile:

gem 'calliper'

Enable it in your test_helper:

Calliper.enable!

Then write a page abstraction and your tests:

# test/integration/user_notifications_test.rb

class UserNotificationsPage < Calliper::Page
  def get(user)
    super "/users/#{users.to_param}/notifications"
  end

  def notifications
    find_element(repeater: 'notification in user.notifications')
  end

  def form
    find_element(css: 'form.notification')
  end
end

class UserNotificationsIntegrationTest < ActiveSupport::TestCase
  setup do
    @user = users(:alice)
    @page = UserNotificationsPage.get(@user)
  end

  test "notifications list" do
    assert_equal @user.notifications.count, @page.notifications.count
  end

  test "leave a message" do
    assert_difference('@page.notifications.count') do
      @page.form.find_element(model: 'notification.message').send_keys("hey dude\n")
    end
    assert_equal "hey dude", @page.notifications.last.find_element(class: 'message').text
  end
end

Please note that a page abstraction isn't required, but you must always send your WebDriver methods throught an instance of Calliper::Page because these call will wait for angular to be ready. Calling directly methods on Calliper.driver won't wait and may be unsynced and fail randomly.

Run tests

Calliper will detect if a Selenium WebDriver server has been started locally on http://localhost:4444/wd/hub and use it. Otherwise it will launch the driver directly (it defaults to firefox). Alternatively you may configure it to run your tests on Sauce Labs for example:

Calliper.setup do |config|
  config.driver = :remote
  config.remote_url = "http://#{ENV['SAUCE_USERNAME']}:#{ENV['SAUCE_ACCESS_KEY']}@ondemand.saucelabs.com/wd/hub"
  config.capabilities = {
    name: 'my_app_name',
    browserName: ENV['BROWSER'] || 'firefox',
  }
end

Credits

  • Rack Server class is from Teaspoon
  • Overall design and client side scripts are from Protractor

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.