auto_screenshot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +7 -0
- data/LICENSE +22 -0
- data/README.md +44 -0
- data/Rakefile +2 -0
- data/auto_screenshot.gemspec +18 -0
- data/lib/auto_screenshot/version.rb +3 -0
- data/lib/auto_screenshot.rb +107 -0
- metadata +65 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ryan Wold
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
Auto Screenshot
|
2
|
+
===============
|
3
|
+
|
4
|
+
A small library designed to help document web products.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
From console, within the /auto_screenshot directory:
|
9
|
+
|
10
|
+
irb
|
11
|
+
load auto_screenshot.rb
|
12
|
+
|
13
|
+
This works in 2 ways:
|
14
|
+
|
15
|
+
Method 1: Pass in an array of URL's
|
16
|
+
|
17
|
+
urls = ["http://ryanwold.net", "http://afomi.com", "http://www.granicus.com"]
|
18
|
+
s = Screenshot.new(:urls => urls) # => an array of URL's as strings
|
19
|
+
|
20
|
+
Or
|
21
|
+
|
22
|
+
Method 2: Read from a .json file
|
23
|
+
|
24
|
+
s = Screenshot.new(:file => "test.json") # => an array of URL's as strings
|
25
|
+
s.go # => screenshots are saved to the /screenshots directory as .png files
|
26
|
+
|
27
|
+
gem install auto_screenshot
|
28
|
+
rake screenshots --all
|
29
|
+
|
30
|
+
screenshot based on a .rb file or pass arguments
|
31
|
+
|
32
|
+
load 'auto_screenshot.rb'
|
33
|
+
s = Screenshot.new(:file => "test.json")
|
34
|
+
s.go
|
35
|
+
|
36
|
+
Alternatively, use a ruby file to generate a @links array of URL strings for each page (see dmap.rb as an example)
|
37
|
+
|
38
|
+
load 'dmap.rb'
|
39
|
+
s = Screenshot.new(:urls => $links)
|
40
|
+
|
41
|
+
#### Remember
|
42
|
+
|
43
|
+
* Ensure your website is running when testing locally.
|
44
|
+
* Don't abuse anybody's website.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/auto_screenshot/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Ryan Wold"]
|
6
|
+
gem.email = ["wold@afomi.com"]
|
7
|
+
gem.description = %q{'Automatically screenshot webpages'}
|
8
|
+
gem.summary = %q{'Automating webpage screenshots'}
|
9
|
+
gem.homepage = "http://github.com/afomi/auto_screenshot"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "auto_screenshot"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = AutoScreenshot::VERSION
|
17
|
+
gem.add_runtime_dependency 'capybara'
|
18
|
+
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
require "auto_screenshot/version"
|
2
|
+
|
3
|
+
require 'uri'
|
4
|
+
require 'json'
|
5
|
+
require 'capybara/dsl'
|
6
|
+
|
7
|
+
module AutoScreenshot
|
8
|
+
|
9
|
+
class Screenshot
|
10
|
+
|
11
|
+
include Capybara::DSL
|
12
|
+
Capybara.default_driver = :selenium
|
13
|
+
|
14
|
+
attr_accessor :urls, :folder, :action_map_path, :action_map
|
15
|
+
|
16
|
+
def initialize(opts = { :urls => [], :file => "", :rb_file => nil, :action_map_path => "", :folder => "" })
|
17
|
+
raise Exception, "please pass in an array of urls like {:urls => []}, or a file, like {:file => \"test.json\"}" unless opts[:urls] or opts[:file] or opts[:rb_file]
|
18
|
+
|
19
|
+
if opts[:urls]
|
20
|
+
@urls = opts[:urls]
|
21
|
+
elsif opts[:rb_file]
|
22
|
+
require_relative opts[:rb_file]
|
23
|
+
@urls = $links
|
24
|
+
elsif opts[:file]
|
25
|
+
@urls = JSON.parse(File.open(opts[:file], "r").read)
|
26
|
+
end
|
27
|
+
|
28
|
+
@action_map_path = opts[:action_map_path]
|
29
|
+
@folder = opts[:folder] ||= "screenshots"
|
30
|
+
@action_map = action_map
|
31
|
+
end
|
32
|
+
|
33
|
+
def go
|
34
|
+
errors = []
|
35
|
+
@urls.each do |url|
|
36
|
+
begin
|
37
|
+
puts "Getting #{url}"
|
38
|
+
visit "#{url}"
|
39
|
+
|
40
|
+
page.wait_until do
|
41
|
+
page.evaluate_script 'jQuery.active == 0'
|
42
|
+
end
|
43
|
+
snap
|
44
|
+
actions(url)
|
45
|
+
rescue => err
|
46
|
+
puts err.inspect
|
47
|
+
puts "error on #{url}"
|
48
|
+
errors << url
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
puts errors
|
53
|
+
end
|
54
|
+
|
55
|
+
def action_map
|
56
|
+
json = File.open(@action_map_path).read
|
57
|
+
hash = JSON.parse(json)
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# custom actions for Granicus
|
62
|
+
# something custom based on a page. pages must be ordered in the URL array though
|
63
|
+
def actions(url)
|
64
|
+
# do a specific action for a url, like login
|
65
|
+
|
66
|
+
if action_map.has_key?(url)
|
67
|
+
self.send(action_map[url])
|
68
|
+
else
|
69
|
+
nil
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def login
|
74
|
+
click_on "Sign in / up"
|
75
|
+
sleep 2.0
|
76
|
+
fill_in "user_email", :with => "ryanw@granicus.com"
|
77
|
+
fill_in "user_password", :with => ""
|
78
|
+
click_on "Sign in"
|
79
|
+
sleep 2.0
|
80
|
+
wait_for_ajax
|
81
|
+
end
|
82
|
+
|
83
|
+
def wait
|
84
|
+
sleep 15.0
|
85
|
+
end
|
86
|
+
|
87
|
+
def grab_links(url)
|
88
|
+
links = []
|
89
|
+
|
90
|
+
visit "#{url}"
|
91
|
+
nodes = Nokogiri::HTML(page.html).css("a")
|
92
|
+
nodes.each do |link|
|
93
|
+
links << link["href"]
|
94
|
+
end
|
95
|
+
links.uniq
|
96
|
+
end
|
97
|
+
|
98
|
+
def snap
|
99
|
+
page.execute_script('$(window).width(1200)')
|
100
|
+
name = page.current_url.gsub("https:\/\/", "").gsub("http:\/\/", "").gsub(":", "").gsub("\/", "-").gsub("&", "-").gsub("?", "_").gsub("dev.lvh.me3000-", "").gsub("admin.lvh.me3000-", "").gsub("localhost3001-", "").gsub("dev.dev.lvh.me3000-", "").gsub("test.civicideasstaging.com", "")
|
101
|
+
Capybara.current_session.driver.browser.manage.window.resize_to(1000, 800)
|
102
|
+
Capybara.current_session.driver.browser.save_screenshot("#{File.dirname(__FILE__)}/#{@folder}/#{name}.png")
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: auto_screenshot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ryan Wold
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-19 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: capybara
|
16
|
+
requirement: &70132291619560 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70132291619560
|
25
|
+
description: ! '''Automatically screenshot webpages'''
|
26
|
+
email:
|
27
|
+
- wold@afomi.com
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- auto_screenshot.gemspec
|
38
|
+
- lib/auto_screenshot.rb
|
39
|
+
- lib/auto_screenshot/version.rb
|
40
|
+
homepage: http://github.com/afomi/auto_screenshot
|
41
|
+
licenses: []
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.15
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: ! '''Automating webpage screenshots'''
|
64
|
+
test_files: []
|
65
|
+
has_rdoc:
|