watir_shot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +28 -0
- data/lib/railtie.rb +18 -0
- data/lib/tasks/watir_shot_tasks.rake +46 -0
- data/lib/watir_shot/generator.rb +69 -0
- data/lib/watir_shot/version.rb +3 -0
- data/lib/watir_shot.rb +30 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e0f9a09acfd2c9c0b1c603a150c5576ac894c98
|
4
|
+
data.tar.gz: 7161a0927e1194a3b848497656fc62291d2d4cc2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6b00d6170190797637a6a75365545f22a19466ac0ad522654281db3178b7d0d0f1176b64de2eeb05bc156b739011793f354c10eba4936345b4947de6faf3b476
|
7
|
+
data.tar.gz: c68ebe45b0e4884e166fd7430e34f7badbe75858dc2e44e3fd813b0557ca84416b2f0f45ecf17f6b938241ef63500b1ab1828e0623b26f071f43f848f0be8fb6
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'WatirShot'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
Bundler::GemHelper.install_tasks
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/**/*_test.rb'
|
25
|
+
t.verbose = false
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: :test
|
data/lib/railtie.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
require 'watir_shot'
|
3
|
+
|
4
|
+
module WatirShot
|
5
|
+
class Railtie < ::Rails::Railtie
|
6
|
+
config.watir_shot = ActiveSupport::OrderedOptions.new
|
7
|
+
config.eager_load_namespaces << WatirShot
|
8
|
+
|
9
|
+
generators do
|
10
|
+
require 'watir_shot/generator'
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
rake_tasks do
|
15
|
+
load 'tasks/watir_shot_tasks.rake'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
namespace :watir_shot do
|
2
|
+
desc "Create config/watir_shot.yml"
|
3
|
+
task create_yml: :environment do
|
4
|
+
require 'watir_shot/generator'
|
5
|
+
WatirShot::WatirShotGenerator.new.create_routes_yml
|
6
|
+
end
|
7
|
+
|
8
|
+
desc "Capture screenshot by watir.(Ex. rake watir_shot:capture[chrome])"
|
9
|
+
task :capture, "browser_type"
|
10
|
+
task capture: :environment do |_, args|
|
11
|
+
require "watir"
|
12
|
+
require "watir-webdriver"
|
13
|
+
browser_type = args.browser_type.to_sym if args.browser_type.present?
|
14
|
+
browser_type ||= :firefox
|
15
|
+
watir_shot_yml_path = Rails.root.join("config/watir_shot.yml")
|
16
|
+
unless File.exist? watir_shot_yml_path
|
17
|
+
raise Exception.new("config/watir_shot.yml not found.\nCreate config/watir_shot.yml(rake watir_shot:create_yml)")
|
18
|
+
end
|
19
|
+
watir_shot_pages = YAML.load_file(watir_shot_yml_path)["pages"]
|
20
|
+
raise Exception.new("Need default key in watir_shot.yml") unless watir_shot_pages.keys.include?('default')
|
21
|
+
# generate browser
|
22
|
+
browser = case browser_type
|
23
|
+
when :chrome
|
24
|
+
Watir::Browser.new :chrome, switches: %w[--test-type --ignore-certificate-errors --disable-popup-blocking --disable-translate]
|
25
|
+
else
|
26
|
+
Watir::Browser.new(browser_type)
|
27
|
+
end
|
28
|
+
|
29
|
+
watir_shot_pages.keys.each do |key|
|
30
|
+
# prepare saved screenshot directory
|
31
|
+
tmp_dir = Rails.root.join("tmp/watir_shot/#{browser.driver.browser.to_s}/#{key}")
|
32
|
+
FileUtils.mkdir_p tmp_dir unless Dir.exist? tmp_dir
|
33
|
+
# clean screenshot directory before capture.
|
34
|
+
FileUtils.rm(Dir.glob(tmp_dir.to_s + '/**/*.png'))
|
35
|
+
# do pre-processing
|
36
|
+
WatirShot.befores[key.to_sym].call(browser) unless WatirShot.befores[key.to_sym]
|
37
|
+
watir_shot_pages[key].each.with_index(1) do |page, index|
|
38
|
+
browser.goto WatirShot.base_url + page['path']
|
39
|
+
browser.screenshot.save "#{tmp_dir}/#{sprintf('%04d', index)}-#{page['title']}.png"
|
40
|
+
end
|
41
|
+
# do post-processing
|
42
|
+
WatirShot.afters[key.to_sym].call(browser) unless WatirShot.afters[key.to_sym]
|
43
|
+
end
|
44
|
+
browser.close
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module WatirShot
|
2
|
+
class WatirShotGenerator < Rails::Generators::Base
|
3
|
+
desc "Initialize WatirShot"
|
4
|
+
def create_initializer_file
|
5
|
+
initializer "watir_shot.rb" do
|
6
|
+
<<-FILE.strip_heredoc
|
7
|
+
WatirShot.configure do |config|
|
8
|
+
config.default_url_options = {schema: "http", host: "localhost:3000"}
|
9
|
+
|
10
|
+
config.before :default do |browser|
|
11
|
+
# Please input setup.
|
12
|
+
# (Ex: Sign in)
|
13
|
+
#
|
14
|
+
# browser.goto WatirShot.base_url + '/user/login'
|
15
|
+
# browser.text_field(:id, "user_email").set("foo@example.com")
|
16
|
+
# browser.text_field(:id, "user_password").set("something")
|
17
|
+
# browser.button(:value, "Sign In").click
|
18
|
+
end
|
19
|
+
|
20
|
+
config.after :default do |browser|
|
21
|
+
# Please input after.
|
22
|
+
# (Ex: Sign out)
|
23
|
+
#
|
24
|
+
# browser.link(:text, "Sign Out").click
|
25
|
+
end
|
26
|
+
|
27
|
+
# If you want to capture in various situations, make a new symbol.
|
28
|
+
# And you should add new element in watir_shot.yml
|
29
|
+
# (Ex. Admin user)
|
30
|
+
#
|
31
|
+
# config.before :admin_user do |browser|
|
32
|
+
# # Something
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# config.after :admin_user do |browser|
|
36
|
+
# # Something
|
37
|
+
# end
|
38
|
+
#
|
39
|
+
# Sample watir_shot.yml
|
40
|
+
# ---
|
41
|
+
# pages:
|
42
|
+
# default:
|
43
|
+
# -
|
44
|
+
# title: 'TopPage'
|
45
|
+
# path: '/'
|
46
|
+
# admin_user:
|
47
|
+
# -
|
48
|
+
# title: 'TopPage'
|
49
|
+
# path: '/'
|
50
|
+
end
|
51
|
+
FILE
|
52
|
+
end
|
53
|
+
create_routes_yml
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_routes_yml
|
57
|
+
all_routes = Rails.application.routes.routes
|
58
|
+
require 'action_dispatch/routing/inspector'
|
59
|
+
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
|
60
|
+
routes = inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, ENV['CONTROLLER']).split("\n")
|
61
|
+
method_get_routes = routes.select{|route| route =~ /GET/ }.map{|route| route.strip }
|
62
|
+
paths = method_get_routes.map{|route| route.gsub(/\s+/, ' ').split(' ')[2].gsub('(.:format)', '')}
|
63
|
+
routes_yml = {'pages' =>
|
64
|
+
{'default' => paths.map{|path| {'title' => '', 'path' => path}} }
|
65
|
+
}.to_yaml
|
66
|
+
create_file "config/watir_shot.yml", routes_yml
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/watir_shot.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module WatirShot
|
2
|
+
|
3
|
+
mattr_accessor :default_url_options
|
4
|
+
@@default_url_options
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
yield self
|
8
|
+
end
|
9
|
+
|
10
|
+
mattr_accessor :befores
|
11
|
+
@@befores = {}
|
12
|
+
|
13
|
+
def self.before(key, &block)
|
14
|
+
@@befores[key] = block
|
15
|
+
end
|
16
|
+
|
17
|
+
mattr_accessor :afters
|
18
|
+
@@afters = {}
|
19
|
+
|
20
|
+
def self.after(key, &block)
|
21
|
+
@@afters[key] = block
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.base_url
|
25
|
+
schema = @@default_url_options[:schema] || 'http'
|
26
|
+
host = @@default_url_options[:host] || 'localhost:3000'
|
27
|
+
"#{schema}://#{host}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
require 'railtie'
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: watir_shot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Toyoaki Oko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
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: watir
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 5.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 5.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.1.6
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.1.6
|
55
|
+
description: Capture screenshot by watir.
|
56
|
+
email:
|
57
|
+
- chariderpato@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- lib/railtie.rb
|
66
|
+
- lib/tasks/watir_shot_tasks.rake
|
67
|
+
- lib/watir_shot.rb
|
68
|
+
- lib/watir_shot/generator.rb
|
69
|
+
- lib/watir_shot/version.rb
|
70
|
+
homepage: https://github.com/patorash/watir_shot
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.2.2
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Capture screenshot by watir.
|
94
|
+
test_files: []
|