selenium-reporter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c66eba291cae96f8c635ddca9ec1024032e05435
4
+ data.tar.gz: e8b737e8b206e25461e17231588c4cb309a1b01e
5
+ SHA512:
6
+ metadata.gz: 70aa97d7397e5099521581e971c4a1fe1b5f3417886e0c575270fee9df8e90823df19772f4f72b794e1287d9020eee9d86ef900231cbffd1c66165169b7ca32c
7
+ data.tar.gz: 9f6eea37bf02d4deb94ff130bf316cd636fff5cdf93abad953d5c6dfca32877d9cb8305360e27b9135d9b64360eeb479ddb747321b33f413121b1e1e9ee8288a
@@ -0,0 +1,7 @@
1
+ *.lock
2
+ .*.swp
3
+ .DS_Store
4
+ spec/results
5
+ tmp/
6
+ results/
7
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,60 @@
1
+ = selenium-reporter
2
+
3
+ == DESCRIPTION:
4
+
5
+ A report helper, generator, and viewer for Selenium that displays failure screenshots and stacktraces in an HTML digest.
6
+
7
+ == INSTALLATION:
8
+
9
+ gem install selenium-reporter
10
+
11
+ == USAGE:
12
+
13
+ === Environment Variables
14
+
15
+ SE_OUTPUT_DIR (relative path to where you want to store screenshots and the final report)
16
+
17
+ === Capturing Screenshots
18
+
19
+ ENV['SE_OUTPUT_DIR'] = 'results'
20
+ reporter = SeleniumReporter.new
21
+ driver = Selenium::WebDriver.for :firefox
22
+ driver.save_screenshot(reporter.screenshot_file)
23
+
24
+ NOTE: This will overwrite result output from previous test runs
25
+
26
+ === Generating a Report
27
+
28
+ reporter.generate_report
29
+
30
+ NOTE: This will generate an HTML report in a sub-directory within the output directory you specified
31
+
32
+ === Viewing a Report
33
+
34
+ reporter.serve_report
35
+
36
+ NOTE: This will start a local web server and make the final report available at http://localhost:4567
37
+
38
+ == LICENSE:
39
+
40
+ The MIT License (MIT)
41
+
42
+ Copyright (c) 2014 Dave Haeffner
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy
45
+ of this software and associated documentation files (the "Software"), to deal
46
+ in the Software without restriction, including without limitation the rights
47
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
48
+ copies of the Software, and to permit persons to whom the Software is
49
+ furnished to do so, subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
56
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
57
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
58
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
59
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
60
+ SOFTWARE.
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+
@@ -0,0 +1,70 @@
1
+ require_relative 'selenium-reporter/config-checker'
2
+ require_relative 'selenium-reporter/system/folder'
3
+ require 'uuid'
4
+ require 'rspec'
5
+
6
+ class SeleniumReporter
7
+
8
+ attr_reader :output_dir
9
+
10
+ def initialize
11
+ ConfigChecker.new
12
+ make_absolute ENV['SE_OUTPUT_DIR']
13
+ System::Folder.prepare
14
+ load_rspec_config
15
+ end
16
+
17
+ def screenshot_file
18
+ "#{screenshot_dir}/#{UUID.new.generate}.png"
19
+ end
20
+
21
+ def generate_report
22
+ system("java -jar #{allure_cli} generate #{xml_dir} -o #{report_dir}")
23
+ end
24
+
25
+ def serve_report
26
+ ENV['SE_REPORT_DIR'] = report_dir
27
+ @pid = Process.spawn('ruby lib/selenium-reporter/report-server.rb')
28
+ end
29
+
30
+ def stop_report
31
+ Process.kill("KILL", @pid)
32
+ ENV['SE_REPORT_DIR'] = nil
33
+ end
34
+
35
+ private
36
+
37
+ def pwd
38
+ Dir.pwd
39
+ end
40
+
41
+ def make_absolute(relative_path)
42
+ @output_dir = File.join(pwd, ENV['SE_OUTPUT_DIR'])
43
+ ENV['SE_OUTPUT_DIR'] = output_dir
44
+ end
45
+
46
+ def screenshot_dir
47
+ output_dir + '/screenshot'
48
+ end
49
+
50
+ def xml_dir
51
+ output_dir + '/xml'
52
+ end
53
+
54
+ def report_dir
55
+ output_dir + '/report'
56
+ end
57
+
58
+ def allure_cli
59
+ File.join(pwd, 'bin/allure/allure-cli-2.1.jar')
60
+ end
61
+
62
+ def load_rspec_config
63
+ require 'nokogiri' # this is a dependent lib for allure-rspec
64
+ require 'allure-rspec'
65
+ AllureRSpec.configure do |c|
66
+ c.output_dir = xml_dir
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,20 @@
1
+ class SeleniumReporter
2
+
3
+ class ConfigChecker
4
+
5
+ def initialize
6
+ output_dir_check
7
+ end
8
+
9
+ private
10
+
11
+ ERRORS = { NoOutputDirSpecified: 'You need to specify an output directory (e.g., SE_OUTPUT_DIR).' }
12
+
13
+ def output_dir_check
14
+ if ENV['SE_OUTPUT_DIR'].nil?
15
+ raise ERRORS[:NoOutputDirSpecified]
16
+ end
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require 'sinatra/base'
2
+
3
+ class SeleniumReporter
4
+ class ReportServer < Sinatra::Base
5
+
6
+ set :public_folder, ENV['SE_REPORT_DIR']
7
+
8
+ get '/' do
9
+ redirect '/index.html'
10
+ end
11
+
12
+ run! if app_file == $0
13
+ end
14
+ end
@@ -0,0 +1,47 @@
1
+ class SeleniumReporter
2
+ module System
3
+ module Folder
4
+
5
+ extend self
6
+
7
+ def prepare
8
+ unless exists?
9
+ create!
10
+ else
11
+ clean!
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def exist?
18
+ File.directory?(ENV['SE_OUTPUT_DIR'])
19
+ end
20
+
21
+ def exists?
22
+ !Dir.glob(ENV['SE_OUTPUT_DIR'] + '/*').empty?
23
+ end
24
+
25
+ def create!
26
+ FileUtils.mkdir_p(ENV['SE_OUTPUT_DIR'])
27
+ FileUtils.mkdir_p(ENV['SE_OUTPUT_DIR'] + '/screenshot')
28
+ FileUtils.mkdir_p(ENV['SE_OUTPUT_DIR'] + '/xml')
29
+ FileUtils.mkdir_p(ENV['SE_OUTPUT_DIR'] + '/report')
30
+ end
31
+
32
+ def empty?
33
+ Dir.glob("#{ENV['SE_OUTPUT_DIR']}/*").empty?
34
+ end
35
+
36
+ def empty!
37
+ FileUtils.rm_rf Dir.glob("#{ENV['SE_OUTPUT_DIR']}/*")
38
+ end
39
+
40
+ def clean!
41
+ empty!
42
+ create!
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ class SeleniumReporter
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'selenium-reporter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'selenium-reporter'
8
+ spec.version = SeleniumReporter::VERSION
9
+ spec.authors = ['Dave Haeffner']
10
+ spec.email = ['dhaeffner@gmail.com']
11
+ spec.summary = %q{See README.txt for details.}
12
+ spec.description = %q{Generate HTML test reports more easily.}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'allure-rspec', '~> 0.6.5'
21
+ spec.add_dependency 'nokogiri', '~> 1.6.3.1'
22
+ spec.add_dependency 'uuid', '~> 2.3.7'
23
+ spec.add_dependency 'sinatra', '~> 1.4.5'
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'rake', '~> 10.3.2'
26
+ spec.add_development_dependency 'rspec', '~> 3.1.0'
27
+ spec.add_development_dependency 'guard-rspec', '~> 4.3.1'
28
+ spec.add_development_dependency 'selenium-webdriver', '~> 2.43.0'
29
+ spec.add_development_dependency 'typhoeus', '~> 0.6.9'
30
+ end
@@ -0,0 +1,15 @@
1
+ require_relative '../lib/selenium-reporter/config-checker'
2
+
3
+ describe 'Config Checker -> ' do
4
+
5
+ before(:each) do
6
+ ENV['SE_OUTPUT_DIR'] = nil
7
+ end
8
+
9
+ it 'no output directory set' do
10
+ expect { SeleniumReporter::ConfigChecker.new }.to raise_error(
11
+ RuntimeError,
12
+ 'You need to specify an output directory (e.g., SE_OUTPUT_DIR).')
13
+ end
14
+
15
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../lib/selenium-reporter/system/folder'
2
+
3
+ describe 'Folder manipulation' do
4
+
5
+ before(:all) do
6
+ @loc = ENV['SE_OUTPUT_DIR'] = File.join(Dir.pwd, 'spec/results')
7
+ end
8
+
9
+ before(:each) do
10
+ FileUtils.rm_rf(@loc)
11
+ end
12
+
13
+ after(:all) do
14
+ FileUtils.rm_rf(@loc)
15
+ end
16
+
17
+ it 'directory exists' do
18
+ FileUtils.mkdir_p(@loc)
19
+ expect(SeleniumReporter::System::Folder.send(:exist?)).to eql true
20
+ end
21
+
22
+ it 'directory creation' do
23
+ SeleniumReporter::System::Folder.send(:create!)
24
+ expect(SeleniumReporter::System::Folder.send(:exists?)).to eql true
25
+ end
26
+
27
+ it 'empty' do
28
+ SeleniumReporter::System::Folder.send(:create!)
29
+ SeleniumReporter::System::Folder.send(:empty!)
30
+ expect(SeleniumReporter::System::Folder.send(:empty?)).to eql true
31
+ end
32
+
33
+ it 'clean' do
34
+ SeleniumReporter::System::Folder.send(:clean!)
35
+ expect(SeleniumReporter::System::Folder.send(:empty?)).to eql false
36
+ expect(SeleniumReporter::System::Folder.send(:exists?)).to eql true
37
+ end
38
+
39
+ end
@@ -0,0 +1,39 @@
1
+ require_relative '../lib/selenium-reporter'
2
+ require 'selenium-webdriver'
3
+ require 'typhoeus'
4
+
5
+ describe 'selenium-reporter' do
6
+
7
+ it 'provides a unique file with output directory' do
8
+ ENV['SE_OUTPUT_DIR'] = 'spec/results'
9
+ screenshot_file = SeleniumReporter.new.screenshot_file
10
+ expect(screenshot_file).to include(ENV['SE_OUTPUT_DIR'])
11
+ expect(screenshot_file).to include('.png')
12
+ end
13
+
14
+ context 'report' do
15
+
16
+ before(:all) do
17
+ ENV['SE_OUTPUT_DIR'] = 'spec/results'
18
+ @reporter = SeleniumReporter.new
19
+ driver = Selenium::WebDriver.for :firefox
20
+ driver.get 'http://the-internet.herokuapp.com'
21
+ driver.save_screenshot(@reporter.screenshot_file)
22
+ driver.quit
23
+ end
24
+
25
+ it 'compiles output into a consolidated report' do
26
+ @reporter.generate_report
27
+ expect($?.exitstatus).to eql 0
28
+ end
29
+
30
+ it 'consolidated report is viewable in a browser' do
31
+ @reporter.serve_report
32
+ sleep 4
33
+ expect(Typhoeus.get('http://localhost:4567/', followlocation: true).code).to eql 200
34
+ @reporter.stop_report
35
+ end
36
+
37
+ end
38
+
39
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-reporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Haeffner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: allure-rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.6.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.6.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.7
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.7
55
+ - !ruby/object:Gem::Dependency
56
+ name: sinatra
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.5
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.4.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 10.3.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 10.3.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 3.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 3.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 4.3.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 4.3.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: selenium-webdriver
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 2.43.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 2.43.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: typhoeus
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.6.9
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.6.9
153
+ description: Generate HTML test reports more easily.
154
+ email:
155
+ - dhaeffner@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - Gemfile
162
+ - README.txt
163
+ - Rakefile
164
+ - bin/allure/allure-cli-2.1.jar
165
+ - lib/selenium-reporter.rb
166
+ - lib/selenium-reporter/config-checker.rb
167
+ - lib/selenium-reporter/report-server.rb
168
+ - lib/selenium-reporter/system/folder.rb
169
+ - lib/selenium-reporter/version.rb
170
+ - selenium-reporter.gemspec
171
+ - spec/config-checker_spec.rb
172
+ - spec/folder_spec.rb
173
+ - spec/selenium-reporter_spec.rb
174
+ homepage: ''
175
+ licenses:
176
+ - MIT
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.2.2
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: See README.txt for details.
198
+ test_files:
199
+ - spec/config-checker_spec.rb
200
+ - spec/folder_spec.rb
201
+ - spec/selenium-reporter_spec.rb