Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
source "https://www.rubygems.org"

gem 'selenium-webdriver'
gem 'rake'
gem 'test-unit'
gem 'browserstack-local'
29 changes: 29 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
GEM
remote: https://www.rubygems.org/
specs:
browserstack-local (0.1.1)
childprocess (0.5.9)
ffi (~> 1.0, >= 1.0.11)
ffi (1.9.10)
power_assert (0.3.0)
rake (11.1.2)
rubyzip (1.2.0)
selenium-webdriver (2.53.0)
childprocess (~> 0.5)
rubyzip (~> 1.0)
websocket (~> 1.0)
test-unit (3.1.8)
power_assert
websocket (1.2.3)

PLATFORMS
ruby

DEPENDENCIES
browserstack-local
rake
selenium-webdriver
test-unit

BUNDLED WITH
1.11.2
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# testunit-browserstack
=======================

Selenium examples for TestUnit and BrowserStack Automate

This repository provides information and helpful tweaks to run your TestUnit tests on the BrowserStack selenium cloud infrastructure.

###Configuration
Add rake, test-unit, browserstack-local gems into your Gemfile.
Run `bundle install`.

### BrowserStack Authentication

Export the environment variables for the username and access key of your BrowserStack account.
These can be found on the automate accounts page on [BrowserStack](https://www.browserstack.com/accounts/automate)

`export BROWSERSTACK_USERNAME=<browserstack-username>`

`export BROWSERSTACK_KEY=<browserstack-access-key>`


###Run tests
* Single Test: `rake name_of_test ` Example: `rake windows_firefox_40`
You see the other tests in the rakefile.
* Parallel Tests: `rake parallel_test`
* Local test: To run local tests, just set the `browserstack.local` capability to true in the test.

###Further Reading
- [TestUnit](http://ruby-doc.org/stdlib-1.8.7/libdoc/test/unit/rdoc/Test/Unit.html)
- [BrowserStack documentation for Automate](https://www.browserstack.com/automate/ruby)

Happy Testing!
29 changes: 29 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

def run_tests(platform, browser, version)
system("os=\"#{platform}\" browser=\"#{browser}\" browser_version=\"#{version}\" ruby test.rb")
end

task :windows_chrome_43 do
run_tests('Windows', 'chrome', '43')
end

task :windows_firefox_40 do
run_tests('Windows', 'firefox','40')
end

task :windows_chrome_45 do
run_tests('Windows', 'chrome','45')
end

task :windows_firefox_39 do
run_tests('Windows', 'firefox','39')
end

multitask :parallel_test => [
:windows_chrome_43,
:windows_firefox_40,
:windows_chrome_45,
:windows_firefox_39
] do
puts 'Running parallel Tests'
end
33 changes: 33 additions & 0 deletions test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'rubygems'
require 'selenium-webdriver'
require 'test-unit'
require 'browserstack/local'

class SampleTests < Test::Unit::TestCase
def setup
caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browser"] = "#{ENV['browser']}"
caps["browser_version"] = "#{ENV['browser_version']}"
caps["os"] = "#{ENV['os']}"
caps["browserstack.local"] = "false"
if caps['browserstack.local'] && caps['browserstack.local'] == 'true';
@bs_local = BrowserStack::Local.new
bs_local_args = { "key" => "#{BROWSERSTACK_KEY}", "forcelocal" => true }
@bs_local.start(bs_local_args)
end

url = "http://#{BROWSERSTACK_USERNAME}:#{BROWSERSTACK_KEY}@hub.browserstack.com/wd/hub"
@driver = Selenium::WebDriver.for(:remote, :url => url, :desired_capabilities => caps)
end

def test_post
@driver.get "https://rubygems.org/gems/selenium-webdriver"
title = @driver.title()
assert_equal(title, "selenium-webdriver | RubyGems.org | your community gem host")
end

def teardown
@driver.quit
@bs_local.stop unless @bs_local.nil?
end
end