qunit-selenium 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b1d4eb78a62b37be9338bc89b3864b2e89c2e92
4
+ data.tar.gz: 2d776ef850825d5cda0727bd3bf14c2b8fca705e
5
+ SHA512:
6
+ metadata.gz: ef6e0f1984d9edc4c9323f6497f9405886c9cf3dc5b9ce36d79015906f2a3ed609849052c4f9096d13f99e1361254308562ed41d0cc2d784263fc32b1e9211da
7
+ data.tar.gz: 11f8951b8ae4d05c2142b9c332d9803a95c6725f7acc02c6d67c7e7ee43017a670a1e35587f99492e2a354bc1ae0e8ea5a860dff99a18bc89f36ddb7e32e1276
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg/
2
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ qunit-selenium (0.0.2)
5
+ selenium-webdriver
6
+ thor
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ childprocess (0.5.3)
12
+ ffi (~> 1.0, >= 1.0.11)
13
+ diff-lcs (1.2.5)
14
+ ffi (1.9.3)
15
+ multi_json (1.10.1)
16
+ rake (10.3.2)
17
+ rspec (3.0.0)
18
+ rspec-core (~> 3.0.0)
19
+ rspec-expectations (~> 3.0.0)
20
+ rspec-mocks (~> 3.0.0)
21
+ rspec-core (3.0.3)
22
+ rspec-support (~> 3.0.0)
23
+ rspec-expectations (3.0.3)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.0.0)
26
+ rspec-mocks (3.0.3)
27
+ rspec-support (~> 3.0.0)
28
+ rspec-support (3.0.3)
29
+ rubyzip (1.1.6)
30
+ selenium-webdriver (2.42.0)
31
+ childprocess (>= 0.5.0)
32
+ multi_json (~> 1.0)
33
+ rubyzip (~> 1.0)
34
+ websocket (~> 1.0.4)
35
+ thor (0.19.1)
36
+ websocket (1.0.7)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler
43
+ qunit-selenium!
44
+ rake
45
+ rspec (~> 3.0)
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Silvio Montanari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ qunit-selenium
2
+ ==============
3
+
4
+ Ruby QUnit test runner for Selenium WebDriver
5
+
6
+ ## Install
7
+
8
+ In your Gemfile:
9
+
10
+ ```ruby
11
+ gem 'qunit-selenium'
12
+ ```
13
+
14
+ Or in your ruby gems:
15
+
16
+ $ gem install qunit-selenium
17
+
18
+ ## Pre-requisites
19
+ 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.
20
+ Please refer to the selenium documentation for detail instructions and drivers/browsers support.
21
+
22
+ *_By default qunit-selenium will use the Selenium *FirefoxDriver* instantiated with a new Firefox profile._*
23
+
24
+ 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.)
25
+
26
+ ## Usage
27
+
28
+ ### Command line
29
+
30
+ $ qunit-selenium [--timeout=seconds] [--screenshot=FILE] URL
31
+
32
+ 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.
33
+
34
+ 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`).
35
+
36
+ Example:
37
+
38
+ $ qunit-selenium --timeout 20 --screenshot mytests.png http://myserver/tests
39
+
40
+ ### Ruby API
41
+
42
+ ```ruby
43
+ require 'qunit/selenium/test_runner'
44
+
45
+ driver = ::Selenium::WebDriver.for :firefox
46
+ url = 'http://test.server.com:8080'
47
+
48
+ result = QUnit::Selenium::TestRunner.new(driver).open(url, timeout: 30)
49
+
50
+ puts "Total tests: #{result.tests[:total]}"
51
+ puts "Passed: #{result.tests[:passed]}"
52
+ puts "Failed: #{result.tests[:failed]}"
53
+
54
+ driver.quit
55
+ ```
56
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+ Rake::Task[:build].prerequisites << Rake::Task[:spec]
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'qunit/selenium/cli'
3
+
4
+ QUnit::Selenium::Cli.start(ARGV)
@@ -0,0 +1,48 @@
1
+ require 'thor'
2
+ require 'selenium-webdriver'
3
+ require_relative 'test_runner'
4
+
5
+ module QUnit
6
+ module Selenium
7
+ class Cli < Thor
8
+ desc "open URL", %{Run qunit tests at the specified URL}
9
+ option :timeout, type: :numeric, default: 10, desc: "Timeout in seconds to wait for the tests to complete (default is 10)"
10
+ option :screenshot, banner: 'FILE', default: nil, desc: "Save a screenshot of the page to the specified FILE after the tests complete"
11
+
12
+ def open(url)
13
+ profile = ::Selenium::WebDriver::Firefox::Profile.new
14
+ driver = ::Selenium::WebDriver.for :firefox, profile: profile
15
+
16
+ begin
17
+ test_result = TestRunner.new(driver).open(url, timeout: options[:timeout])
18
+ driver.save_screenshot options[:screenshot] if options[:screenshot]
19
+
20
+ print_report(test_result)
21
+
22
+ error = test_result.assertions[:failed] > 0
23
+ rescue => e
24
+ puts "Error: #{e}"
25
+ driver.save_screenshot('qunit-selenium-error.png')
26
+ error = true
27
+ ensure
28
+ driver.quit
29
+ end
30
+ exit(1) if error
31
+ end
32
+
33
+ default_task :open
34
+
35
+ private
36
+
37
+ def print_report(result)
38
+ puts "Total tests: #{result.tests[:total]}"
39
+ puts "Passed: #{result.tests[:passed]}"
40
+ puts "Failed: #{result.tests[:failed]}"
41
+ puts "Total assertions: #{result.assertions[:total]}"
42
+ puts "Passed: #{result.assertions[:passed]}"
43
+ puts "Failed: #{result.assertions[:failed]}"
44
+ puts "Tests duration: #{result.duration} seconds"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,47 @@
1
+ module QUnit
2
+ module Selenium
3
+ class TestRun
4
+ TestResult = Struct.new(:tests, :assertions, :duration)
5
+ ID_TESTRESULT = 'qunit-testresult'
6
+ ID_TESTS = 'qunit-tests'
7
+
8
+ def initialize(driver)
9
+ @qunit_testresult = driver[ID_TESTRESULT]
10
+ @qunit_tests = driver[ID_TESTS]
11
+ end
12
+
13
+ def completed?
14
+ @qunit_testresult.text =~ /Tests completed/
15
+ end
16
+
17
+ def result
18
+ assertions = {total: total_assertions, passed: passed_assertions, failed: failed_assertions}
19
+ tests = {total: total_tests, passed: pass_tests, failed: fail_tests}
20
+ TestResult.new(tests, assertions, duration)
21
+ end
22
+
23
+ private
24
+
25
+ def duration
26
+ match = /Tests completed in (?<milliseconds>\d+) milliseconds/.match @qunit_testresult.text
27
+ match[:milliseconds].to_i / 1000
28
+ end
29
+
30
+ %w(total passed failed).each do |result|
31
+ define_method("#{result}_assertions".to_sym) do
32
+ @qunit_testresult.find_elements(:class, result).first.text.to_i
33
+ end
34
+ end
35
+
36
+ def total_tests
37
+ @qunit_tests.find_elements(:css, "##{ID_TESTS} > *").count
38
+ end
39
+
40
+ %w(pass fail).each do |result|
41
+ define_method("#{result}_tests".to_sym) do
42
+ @qunit_tests.find_elements(:css, "##{ID_TESTS} > .#{result}").count
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,26 @@
1
+ require 'selenium-webdriver'
2
+ require_relative 'test_run'
3
+
4
+ module QUnit
5
+ module Selenium
6
+ class TestRunner
7
+ def initialize(driver = nil)
8
+ @driver = driver || ::Selenium::WebDriver.for(:firefox)
9
+ end
10
+
11
+ def open(url, options = {})
12
+ timeout = options[:timeout] || 10
13
+ force_refresh = options[:force_refresh] || false
14
+
15
+ @driver.get url
16
+ @driver.navigate.refresh if force_refresh
17
+
18
+ TestRun.new(@driver).tap do |run|
19
+ ::Selenium::WebDriver::Wait.new(timeout: timeout).until do
20
+ run.completed?
21
+ end
22
+ end.result
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ module QUnit
2
+ module Selenium
3
+ VERSION = '0.0.4'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ libdir = File.join(File.dirname(__FILE__), 'lib')
2
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
3
+
4
+ require 'qunit/selenium/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'qunit-selenium'
8
+ gem.version = QUnit::Selenium::VERSION
9
+ gem.summary = 'Run QUnit tests through Selenium WebDriver'
10
+ gem.description = 'Run QUnit tests through Selenium WebDriver'
11
+
12
+ gem.authors = ['Silvio Montanari']
13
+ gem.homepage = 'https://github.com/smontanari/qunit-selenium'
14
+ gem.license = 'MIT'
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^spec/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.required_ruby_version = '>= 1.9.3'
21
+
22
+ gem.add_runtime_dependency 'selenium-webdriver'
23
+ gem.add_runtime_dependency "thor"
24
+ gem.add_development_dependency 'rspec', '~> 3.0'
25
+ gem.add_development_dependency 'bundler'
26
+ gem.add_development_dependency 'rake'
27
+ end
File without changes
@@ -0,0 +1,53 @@
1
+ require 'qunit/selenium/test_run'
2
+
3
+ module QUnit
4
+ module Selenium
5
+ describe TestRun do
6
+ let(:driver) {double('driver')}
7
+ let(:result_element) {double('result_element')}
8
+ let(:tests_element) {double('tests_element')}
9
+
10
+ before do
11
+ allow(driver).to receive(:[]).with('qunit-testresult').and_return(result_element)
12
+ allow(driver).to receive(:[]).with('qunit-tests').and_return(tests_element)
13
+ end
14
+
15
+ context 'tests completed' do
16
+ before do
17
+ allow(result_element).to receive(:text).and_return('Tests completed in 3000 milliseconds')
18
+ allow(result_element).to receive(:find_elements).with(:class, 'total').and_return([Struct.new(:text).new('123')])
19
+ allow(result_element).to receive(:find_elements).with(:class, 'passed').and_return([Struct.new(:text).new('456')])
20
+ allow(result_element).to receive(:find_elements).with(:class, 'failed').and_return([Struct.new(:text).new('789')])
21
+ allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > *').and_return([1, 2, 3])
22
+ allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > .pass').and_return([1, 2])
23
+ allow(tests_element).to receive(:find_elements).with(:css, '#qunit-tests > .fail').and_return([1])
24
+ end
25
+
26
+ it 'is completed' do
27
+ expect(TestRun.new(driver).completed?).to be_truthy
28
+ end
29
+
30
+ it 'returns the tests result data' do
31
+ result = TestRun.new(driver).result
32
+
33
+ expect(result.tests[:total]).to eq(3)
34
+ expect(result.tests[:passed]).to eq(2)
35
+ expect(result.tests[:failed]).to eq(1)
36
+ expect(result.assertions[:total]).to eq(123)
37
+ expect(result.assertions[:passed]).to eq(456)
38
+ expect(result.assertions[:failed]).to eq(789)
39
+ end
40
+ end
41
+
42
+ context 'tests running' do
43
+ before do
44
+ allow(result_element).to receive(:text).and_return('Running...')
45
+ end
46
+
47
+ it 'is not completed' do
48
+ expect(TestRun.new(driver).completed?).to be_falsy
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,44 @@
1
+ require 'qunit/selenium/test_runner'
2
+
3
+ module QUnit
4
+ module Selenium
5
+ describe TestRunner do
6
+ shared_examples 'open test page' do |timeout|
7
+ let(:test_run) {double('test_run')}
8
+ let(:wait) {double('wait')}
9
+
10
+ before do
11
+ allow(TestRun).to receive(:new).with(driver).and_return(test_run)
12
+ allow(::Selenium::WebDriver::Wait).to receive(:new).with(timeout: timeout).and_return(wait)
13
+ allow(wait).to receive(:until).and_yield
14
+ expect(test_run).to receive(:completed?).ordered
15
+ allow(test_run).to receive(:result).ordered.and_return('result')
16
+ end
17
+
18
+ it 'returns the completed test run' do
19
+ expect(subject).to eq('result')
20
+ end
21
+ end
22
+
23
+ let(:driver) {double('driver')}
24
+
25
+ before do
26
+ expect(driver).to receive(:get).with('test_url').ordered
27
+ end
28
+
29
+ describe ' #open' do
30
+ context 'default options' do
31
+ let(:subject) {TestRunner.new(driver).open('test_url')}
32
+
33
+ include_examples 'open test page', 10
34
+ end
35
+
36
+ context 'custom options' do
37
+ let(:subject) {TestRunner.new(driver).open('test_url', timeout: 30)}
38
+
39
+ include_examples 'open test page', 30
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qunit-selenium
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Silvio Montanari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: selenium-webdriver
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Run QUnit tests through Selenium WebDriver
84
+ email:
85
+ executables:
86
+ - qunit-selenium
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - LICENSE.md
94
+ - README.md
95
+ - Rakefile
96
+ - bin/qunit-selenium
97
+ - lib/qunit/selenium/cli.rb
98
+ - lib/qunit/selenium/test_run.rb
99
+ - lib/qunit/selenium/test_runner.rb
100
+ - lib/qunit/selenium/version.rb
101
+ - qunit-selenium.gemspec
102
+ - spec/qunit/selenium/cli_spec.rb
103
+ - spec/qunit/selenium/test_run_spec.rb
104
+ - spec/qunit/selenium/test_runner_spec.rb
105
+ homepage: https://github.com/smontanari/qunit-selenium
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.9.3
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.0.14
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Run QUnit tests through Selenium WebDriver
129
+ test_files:
130
+ - spec/qunit/selenium/cli_spec.rb
131
+ - spec/qunit/selenium/test_run_spec.rb
132
+ - spec/qunit/selenium/test_runner_spec.rb