From 1a22a7dd5d3b4373f4300c6407ccfa485d7b3ecb Mon Sep 17 00:00:00 2001 From: Nidhi Makhijani Date: Mon, 9 May 2016 18:23:13 +0530 Subject: [PATCH 1/3] intial --- Gemfile | 6 ++++++ Gemfile.lock | 29 +++++++++++++++++++++++++++++ README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ Rakefile | 29 +++++++++++++++++++++++++++++ test.rb | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+) create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 README.md create mode 100644 Rakefile create mode 100644 test.rb diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..ee3d590 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source "https://www.rubygems.org" + +gem 'selenium-webdriver' +gem 'rake' +gem 'test-unit' +gem 'browserstack-local' \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..69d0199 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e616597 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +capybara-browserstack +========= + +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=` + +`export BROWSERSTACK_KEY=` + + +###Run tests +* Single Test: + ``` + $ rake name_of_test + ``` +Examples: +``` +rake windows_firefox_40 +``` +You see the other tests in the rakefile. + +* Tests in Parallel: + ``` + $ 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! diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a0d4108 --- /dev/null +++ b/Rakefile @@ -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 diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..9b7d976 --- /dev/null +++ b/test.rb @@ -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 \ No newline at end of file From 8e03e40fab1496b9f8352a12cd949e6a54ede5c3 Mon Sep 17 00:00:00 2001 From: Nidhi Makhijani Date: Mon, 9 May 2016 18:26:34 +0530 Subject: [PATCH 2/3] readme --- README.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9b4881c..5d02846 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,20 @@ These can be found on the automate accounts page on [BrowserStack](https://www.b ###Run tests * Single Test: - ``` - $ rake name_of_test - ``` -Examples: -``` + ` + rake name_of_test + ` + +Example: +` rake windows_firefox_40 -``` +` You see the other tests in the rakefile. * Tests in Parallel: - ``` - $ rake parallel_test - ``` + ` + rake parallel_test + ` * Local test To run local tests, just set the `browserstack.local` capability to true in the test. From 32d282bd5756557d50144b72b558602a0b36b97b Mon Sep 17 00:00:00 2001 From: Nidhi Makhijani Date: Mon, 9 May 2016 18:29:10 +0530 Subject: [PATCH 3/3] beautify readme --- README.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 5d02846..b3c6a13 100644 --- a/README.md +++ b/README.md @@ -20,24 +20,10 @@ These can be found on the automate accounts page on [BrowserStack](https://www.b ###Run tests -* Single Test: - ` - rake name_of_test - ` - -Example: -` -rake windows_firefox_40 -` +* Single Test: `rake name_of_test ` Example: `rake windows_firefox_40` You see the other tests in the rakefile. - -* Tests in Parallel: - ` - rake parallel_test - ` -* Local test - -To run local tests, just set the `browserstack.local` capability to true in the test. +* 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)