Skip to content

bencolon/testingbot_ruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

123 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<img src=/proxy/https/github.com/bencolon/%E2%80%9Chttps://secure.travis-ci.org/testingbot/testingbot_ruby.png%E2%80%9D />

Testingbot.com is a website where you can use our cloud based Selenium grid. Test your web applications in various environments/browsers/devices.

You can install our testingbot ruby-gem by running “gem install testingbot” on your commandline.

$ gem install testingbot

After you installed the gem you need to run a one part setup. Type testingbot in your commandline and fill in the API key and API secret you obtained on testingbot.com

$ testingbot

You can find an example in our examples folder, try something like this:

require "rubygems"
require "test/unit"
require "testingbot"
class ExampleTest < TestingBot::TestCase
	attr_reader :browser
	
	def setup
		@browser = Selenium::Client::Driver.new \
		:browser => "firefox",
		:url => "http://www.google.com",
		:platform => "WINDOWS",
		:version => 10,
		:timeout_in_second => 90

		browser.start_new_browser_session
	end
	
	def teardown
		browser.close_current_browser_session
	end
	
	def test_page_search
		browser.open "/"
		assert_equal "Google", browser.title
	end
end

This example uses RSpec 2. You can run it with rspec test_rspec.rb

require 'rubygems'
require "selenium/client"
require 'rspec'
require 'testingbot'
require 'testingbot/tunnel'

# rspec 2
describe "People", :type => :selenium do
  attr_reader :selenium_driver
  before(:all) do
    # uncomment if you want to use our Tunnel
    # tunnel = TestingBot::Tunnel.new
    # tunnel.start

    @selenium_driver = Selenium::Client::Driver.new \
        :browser => "firefox", 
        :url => "http://www.google.com", 
        :timeout_in_second => 60,
        :platform => "WINDOWS",
        :version => "10"
  end

  before(:each) do
    @selenium_driver.start_new_browser_session
  end

  after(:each) do
    @selenium_driver.close_current_browser_session
  end

  it "can find the right title" do    
    @selenium_driver.open "/"
    @selenium_driver.title.should eql("Google")   
  end
end

This example uses RSpec 1. You can run it with spec test_rspec1.rb

require 'rubygems'
gem "rspec", "<2"
gem "selenium-client"
require "selenium/client"
require "selenium/rspec/spec_helper"
gem "testingbot"
require "testingbot"

describe "Test" do
  attr_reader :selenium_driver
  alias :page :selenium_driver

    before(:all) do
        @selenium_driver = Selenium::Client::Driver.new \
            :browser => "firefox", 
            :url => "http://www.google.com", 
            :timeout_in_second => 90,
            :platform => "WINDOWS",
            :version => "10"
    end

    before(:each) do
      @selenium_driver.start_new_browser_session
    end

    append_after(:each) do 
      @selenium_driver.close_current_browser_session
    end

    it "can find the right title" do    
      page.open "/"
      page.title.should eql("Google")   
    end
end

This example uses RSpec 2 together with capybara and Selenium webdriver. You can run it with rspec capybara.rb

require 'rspec'
require 'capybara/rspec'
require 'testingbot'
require 'testingbot/capybara'

TestingBot::config do |config|
  config[:desired_capabilities] = { :browserName => "firefox", :version => 9, :platform => "WINDOWS" }
  # config.require_tunnel # uncomment if you want to use our Tunnel
end

describe "People", :type => :request do
  before :each do
    Capybara.current_driver = :testingbot
    Capybara.app_host = "http://testingbot.com"
  end

  it 'has a homepage with the word Selenium' do
    visit '/'
    page.should have_content('Selenium')
  end
end

In this example we will need rspec-rails and Capybara, a rack server will be started by Capybara to run your localhost tests. Add the example below in spec/integration/home_spec.rb

----------------------------------------------------------
spec_helper.rb:

require 'capybara/rspec'
require 'capybara/rails'
require 'testingbot'
require 'testingbot/capybara'

----------------------------------------------------------
spec/integration/home_spec.rb:

require 'spec_helper'

TestingBot::config do |config|
  config[:desired_capabilities] = { :browserName => "firefox", :version => 9, :platform => "WINDOWS", :localhost => "YES" }
  config.require_tunnel
end

describe 'home page' do
  before :each do
    Capybara.server_port = 3011
    Capybara.current_driver = :testingbot
    Capybara.app_host = "http://127.0.0.1:3011"
  end

  after :each do
    # this is a workaround to push test status/details back to testingbot
    # we need to use this because capybara overwrites the driver with a rack-test driver
    @selenium_driver = page.driver.browser.send(:bridge)
  end

  it "shows the home page", :type => :request do
    visit '/'
    page.should have_content('Selenium')
  end
end

Use the :multibrowser => true statement to indicate you want to test on multiple browsers. This should work together with Capybara as well.

require 'rubygems'
require "selenium/client"
require 'rspec'
require 'testingbot'
require 'testingbot/tunnel'

TestingBot::config do |config|
  config[:desired_capabilities] = [{ :browserName => "firefox", :version => 9, :platform => "WINDOWS" }, { :browserName => "firefox", :version => 11, :platform => "WINDOWS" }]
end

describe "Google", :type => :selenium, :multibrowser => true do
    it "can find the right title" do    
      page.navigate.to "http://www.google.com"
      page.title.should eql("Google")   
    end
end

The examples directory contains an example of testing with Capybara and Cucumber. The Rakefile in examples/cucumber contains a cucumber task which will run the same Cucumber story on multiple browsers.

More info available on testingbot.com/support/getting-started/cucumber.html

The tests for this gem are located in the spec folder, you can run them with this Rake task:

rake spec

You can specify extra options like enabling/disabling the screenrecording or screenshot feature. For WebDriver use the config to specify extra options.

For RC tests use the start_new_browser_session(options) options hash.

Get more information on testingbot.com

Copyright © 2012 TestingBot Please see our LICENSE

About

Ruby gem to use with the Cloud Selenium Service at testingbot.com

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Ruby 90.8%
  • JavaScript 9.2%