qunit-selenium-0.0.4/0000755000175000017500000000000013477754162013512 5ustar jmkimjmkimqunit-selenium-0.0.4/bin/0000755000175000017500000000000013477754162014262 5ustar jmkimjmkimqunit-selenium-0.0.4/bin/qunit-selenium0000755000175000017500000000012313477754162017163 0ustar jmkimjmkim#!/usr/bin/env ruby require 'qunit/selenium/cli' QUnit::Selenium::Cli.start(ARGV) qunit-selenium-0.0.4/README.md0000644000175000017500000000343613477754162014777 0ustar jmkimjmkimqunit-selenium ============== Ruby QUnit test runner for Selenium WebDriver ## Install In your Gemfile: ```ruby gem 'qunit-selenium' ``` Or in your ruby gems: $ gem install qunit-selenium ## Pre-requisites This gem is a wrapper around the [selenium-webdriver](http://rubygems.org/gems/selenium-webdriver) gem with the additional logic to parse the QUnit test results page and report the success/failure of your QUnit tests. Please refer to the selenium documentation for detail instructions and drivers/browsers support. *_By default qunit-selenium will use the Selenium *FirefoxDriver* instantiated with a new Firefox profile._* If you wish to use a different driver, or to customise your driver behaviour you can still use qunit-selenium through its API (see below.) ## Usage ### Command line $ qunit-selenium [--timeout=seconds] [--screenshot=FILE] URL This command will open the QUnit test page at the given url and wait for the tests to complete before collecting and displaying the test run results. If the tests do not complete within the given timeout (by default it's 10 seconds) Selenium will raise an error and the command will fail. More in general, if any error is raised by Selenium which would cause a premature end of the test run, the program will generate a screenshot of the error page (file `qunit-selenium-error.png`). Example: $ qunit-selenium --timeout 20 --screenshot mytests.png http://myserver/tests ### Ruby API ```ruby require 'qunit/selenium/test_runner' driver = ::Selenium::WebDriver.for :firefox url = 'http://test.server.com:8080' result = QUnit::Selenium::TestRunner.new(driver).open(url, timeout: 30) puts "Total tests: #{result.tests[:total]}" puts "Passed: #{result.tests[:passed]}" puts "Failed: #{result.tests[:failed]}" driver.quit ``` qunit-selenium-0.0.4/Rakefile0000644000175000017500000000021313477754162015153 0ustar jmkimjmkimrequire "bundler/gem_tasks" require "rspec/core/rake_task" RSpec::Core::RakeTask.new Rake::Task[:build].prerequisites << Rake::Task[:spec]qunit-selenium-0.0.4/lib/0000755000175000017500000000000013477754162014260 5ustar jmkimjmkimqunit-selenium-0.0.4/lib/qunit/0000755000175000017500000000000013477754162015420 5ustar jmkimjmkimqunit-selenium-0.0.4/lib/qunit/selenium/0000755000175000017500000000000013477754162017241 5ustar jmkimjmkimqunit-selenium-0.0.4/lib/qunit/selenium/cli.rb0000644000175000017500000000310713477754162020336 0ustar jmkimjmkimrequire 'thor' require 'selenium-webdriver' require_relative 'test_runner' module QUnit module Selenium class Cli < Thor desc "open URL", %{Run qunit tests at the specified URL} option :timeout, type: :numeric, default: 10, desc: "Timeout in seconds to wait for the tests to complete (default is 10)" option :screenshot, banner: 'FILE', default: nil, desc: "Save a screenshot of the page to the specified FILE after the tests complete" def open(url) profile = ::Selenium::WebDriver::Firefox::Profile.new driver = ::Selenium::WebDriver.for :firefox, profile: profile begin test_result = TestRunner.new(driver).open(url, timeout: options[:timeout]) driver.save_screenshot options[:screenshot] if options[:screenshot] print_report(test_result) error = test_result.assertions[:failed] > 0 rescue => e puts "Error: #{e}" driver.save_screenshot('qunit-selenium-error.png') error = true ensure driver.quit end exit(1) if error end default_task :open private def print_report(result) puts "Total tests: #{result.tests[:total]}" puts "Passed: #{result.tests[:passed]}" puts "Failed: #{result.tests[:failed]}" puts "Total assertions: #{result.assertions[:total]}" puts "Passed: #{result.assertions[:passed]}" puts "Failed: #{result.assertions[:failed]}" puts "Tests duration: #{result.duration} seconds" end end end endqunit-selenium-0.0.4/lib/qunit/selenium/test_runner.rb0000644000175000017500000000117313477754162022140 0ustar jmkimjmkimrequire 'selenium-webdriver' require_relative 'test_run' module QUnit module Selenium class TestRunner def initialize(driver = nil) @driver = driver || ::Selenium::WebDriver.for(:firefox) end def open(url, options = {}) timeout = options[:timeout] || 10 force_refresh = options[:force_refresh] || false @driver.get url @driver.navigate.refresh if force_refresh TestRun.new(@driver).tap do |run| ::Selenium::WebDriver::Wait.new(timeout: timeout).until do run.completed? end end.result end end end endqunit-selenium-0.0.4/lib/qunit/selenium/test_run.rb0000644000175000017500000000250313477754162021431 0ustar jmkimjmkimmodule QUnit module Selenium class TestRun TestResult = Struct.new(:tests, :assertions, :duration) ID_TESTRESULT = 'qunit-testresult' ID_TESTS = 'qunit-tests' def initialize(driver) @qunit_testresult = driver[ID_TESTRESULT] @qunit_tests = driver[ID_TESTS] end def completed? @qunit_testresult.text =~ /Tests completed/ end def result assertions = {total: total_assertions, passed: passed_assertions, failed: failed_assertions} tests = {total: total_tests, passed: pass_tests, failed: fail_tests} TestResult.new(tests, assertions, duration) end private def duration match = /Tests completed in (?\d+) milliseconds/.match @qunit_testresult.text match[:milliseconds].to_i / 1000 end %w(total passed failed).each do |result| define_method("#{result}_assertions".to_sym) do @qunit_testresult.find_elements(:class, result).first.text.to_i end end def total_tests @qunit_tests.find_elements(:css, "##{ID_TESTS} > *").count end %w(pass fail).each do |result| define_method("#{result}_tests".to_sym) do @qunit_tests.find_elements(:css, "##{ID_TESTS} > .#{result}").count end end end end endqunit-selenium-0.0.4/lib/qunit/selenium/version.rb0000644000175000017500000000007613477754162021256 0ustar jmkimjmkimmodule QUnit module Selenium VERSION = '0.0.4' end endqunit-selenium-0.0.4/Gemfile.lock0000644000175000017500000000157413477754162015743 0ustar jmkimjmkimPATH remote: . specs: qunit-selenium (0.0.2) selenium-webdriver thor GEM remote: https://rubygems.org/ specs: childprocess (0.5.3) ffi (~> 1.0, >= 1.0.11) diff-lcs (1.2.5) ffi (1.9.3) multi_json (1.10.1) rake (10.3.2) rspec (3.0.0) rspec-core (~> 3.0.0) rspec-expectations (~> 3.0.0) rspec-mocks (~> 3.0.0) rspec-core (3.0.3) rspec-support (~> 3.0.0) rspec-expectations (3.0.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.0.0) rspec-mocks (3.0.3) rspec-support (~> 3.0.0) rspec-support (3.0.3) rubyzip (1.1.6) selenium-webdriver (2.42.0) childprocess (>= 0.5.0) multi_json (~> 1.0) rubyzip (~> 1.0) websocket (~> 1.0.4) thor (0.19.1) websocket (1.0.7) PLATFORMS ruby DEPENDENCIES bundler qunit-selenium! rake rspec (~> 3.0) qunit-selenium-0.0.4/spec/0000755000175000017500000000000013477754162014444 5ustar jmkimjmkimqunit-selenium-0.0.4/spec/qunit/0000755000175000017500000000000013477754162015604 5ustar jmkimjmkimqunit-selenium-0.0.4/spec/qunit/selenium/0000755000175000017500000000000013477754162017425 5ustar jmkimjmkimqunit-selenium-0.0.4/spec/qunit/selenium/cli_spec.rb0000644000175000017500000000000013477754162021521 0ustar jmkimjmkimqunit-selenium-0.0.4/spec/qunit/selenium/test_run_spec.rb0000644000175000017500000000410213477754162022624 0ustar jmkimjmkimrequire 'qunit/selenium/test_run' module QUnit module Selenium describe TestRun do let(:driver) {double('driver')} let(:result_element) {double('result_element')} let(:tests_element) {double('tests_element')} before do allow(driver).to receive(:[]).with('qunit-testresult').and_return(result_element) allow(driver).to receive(:[]).with('qunit-tests').and_return(tests_element) end context 'tests completed' do before do allow(result_element).to receive(:text).and_return('Tests completed in 3000 milliseconds') allow(result_element).to receive(:find_elements).with(:class, 'total').and_return([Struct.new(:text).new('123')]) allow(result_element).to receive(:find_elements).with(:class, 'passed').and_return([Struct.new(:text).new('456')]) allow(result_element).to receive(:find_elements).with(:class, 'failed').and_return([Struct.new(:text).new('789')]) allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > *').and_return([1, 2, 3]) allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > .pass').and_return([1, 2]) allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > .fail').and_return([1]) end it 'is completed' do expect(TestRun.new(driver).completed?).to be_truthy end it 'returns the tests result data' do result = TestRun.new(driver).result expect(result.tests[:total]).to eq(3) expect(result.tests[:passed]).to eq(2) expect(result.tests[:failed]).to eq(1) expect(result.assertions[:total]).to eq(123) expect(result.assertions[:passed]).to eq(456) expect(result.assertions[:failed]).to eq(789) end end context 'tests running' do before do allow(result_element).to receive(:text).and_return('Running...') end it 'is not completed' do expect(TestRun.new(driver).completed?).to be_falsy end end end end endqunit-selenium-0.0.4/spec/qunit/selenium/test_runner_spec.rb0000644000175000017500000000236313477754162023340 0ustar jmkimjmkimrequire 'qunit/selenium/test_runner' module QUnit module Selenium describe TestRunner do shared_examples 'open test page' do |timeout| let(:test_run) {double('test_run')} let(:wait) {double('wait')} before do allow(TestRun).to receive(:new).with(driver).and_return(test_run) allow(::Selenium::WebDriver::Wait).to receive(:new).with(timeout: timeout).and_return(wait) allow(wait).to receive(:until).and_yield expect(test_run).to receive(:completed?).ordered allow(test_run).to receive(:result).ordered.and_return('result') end it 'returns the completed test run' do expect(subject).to eq('result') end end let(:driver) {double('driver')} before do expect(driver).to receive(:get).with('test_url').ordered end describe ' #open' do context 'default options' do let(:subject) {TestRunner.new(driver).open('test_url')} include_examples 'open test page', 10 end context 'custom options' do let(:subject) {TestRunner.new(driver).open('test_url', timeout: 30)} include_examples 'open test page', 30 end end end end endqunit-selenium-0.0.4/Gemfile0000644000175000017500000000004613477754162015005 0ustar jmkimjmkimsource "https://rubygems.org" gemspecqunit-selenium-0.0.4/.gitignore0000644000175000017500000000001413477754162015475 0ustar jmkimjmkimpkg/ .rspec qunit-selenium-0.0.4/LICENSE.md0000644000175000017500000000207213477754162015117 0ustar jmkimjmkimThe MIT License (MIT) Copyright (c) 2014 Silvio Montanari Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.qunit-selenium-0.0.4/qunit-selenium.gemspec0000644000175000017500000000176013477754162020042 0ustar jmkimjmkimlibdir = File.join(File.dirname(__FILE__), 'lib') $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir) require 'qunit/selenium/version' Gem::Specification.new do |gem| gem.name = 'qunit-selenium' gem.version = QUnit::Selenium::VERSION gem.summary = 'Run QUnit tests through Selenium WebDriver' gem.description = 'Run QUnit tests through Selenium WebDriver' gem.authors = ['Silvio Montanari'] gem.homepage = 'https://github.com/smontanari/qunit-selenium' gem.license = 'MIT' gem.files = `git ls-files`.split($/) gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) } gem.test_files = gem.files.grep(%r{^spec/}) gem.require_paths = ['lib'] gem.required_ruby_version = '>= 1.9.3' gem.add_runtime_dependency 'selenium-webdriver' gem.add_runtime_dependency "thor" gem.add_development_dependency 'rspec', '~> 3.0' gem.add_development_dependency 'bundler' gem.add_development_dependency 'rake' end