This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
sos
executable file
·138 lines (108 loc) · 4.03 KB
/
sos
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env ruby
require 'optparse'
require 'ostruct'
require 'selenium-webdriver'
require 'RMagick'
require 'uri'
require "yaml"
require 'thread/pool'
require 'colored'
require "artii"
include Magick
class Browser
attr_accessor :name, :version, :platform, :resolution
end
options = OpenStruct.new
options.encoding = "utf8"
optparse = OptionParser.new do |opts|
opts.on('-h', 'Shows this help screen') do
puts opts
exit
end
opts.on('-u', '--url URL', 'Set the URL to take screen shots of') do |url|
options.url = url
end
end.parse!
begin
optparse.parse!
mandatory = [:url] # Enforce the presence of
missing = mandatory.select{ |param| options[param].nil? }
if not missing.empty? #
puts "Missing options: #{missing.join(', ')}" #
puts optparse #
exit #
end
rescue OptionParser::InvalidOption, OptionParser::MissingArgument #
puts $!.to_s # Friendly output when parsing fails
puts optparse #
exit #
end
$url = options.url.to_s
class ShotsOnSauce
# load configuration
CONFIGYAML = 'config.yaml'
if File.exists? (CONFIGYAML)
cfg = YAML::load(File.open(CONFIGYAML))
grid = cfg['grid']
maxthreads = cfg['maxthreads']
else
abort("Missing config.yaml file".red_on_yellow)
end
pool = Thread.pool(maxthreads) # COUNT OF YOUR THREADS
# load up all the browsers in a array
BROWSERSYAML = 'browsers.yaml'
if File.exists? (BROWSERSYAML)
browsers = YAML::load(File.open(BROWSERSYAML))
else
abort("Missing browsers.yaml file".red_on_yellow)
end
# clean up the url for documentation
uri = URI.parse(URI.encode($url))
#quick little url valid check for debugging - needs better url error handling
puts uri.kind_of? URI::HTTP
cleanUrl = uri.host.to_s + uri.path.to_s + uri.query.to_s
a = Artii::Base.new :font => 'big'
puts a.asciify('Shots on Sauce!').bold.blue
puts ('a github super diff screen-shotting machine').blue
puts ('--------------------------------------------').blue
browsers.each do |b|
pool.process {
puts ("INFO: Opening " + b.name + " " + b.version + " driver").blue
imageName = ((b.name + "_" + b.version + "_" + b.platform + "_" + cleanUrl.gsub(/[^a-zA-Z 0-9]/, "-")).gsub(/\s/,'-')) + ".png"
caps = Selenium::WebDriver::Remote::Capabilities.send(b.name.to_sym)
caps.version = b.version
caps.platform = b.platform
caps['screen-resolution'] = b.resolution
caps[:name] = "Shots on Sauce - " + b.name + " " + b.version
caps['max-duration'] = 300
driver = Selenium::WebDriver.for(:remote, :url => grid, :desired_capabilities => caps)
driver.manage.window.maximize
driver.manage.timeouts.implicit_wait = 60
driver.get($url)
puts ("INFO: Taking Screen Shot of: " + $url + " using " + b.name + " " + b.version + " on " + b.platform).bold.red
File.delete(imageName) if File.exist?(imageName)
driver.save_screenshot imageName
begin
# need to make the images smaller github diff won't handle large file sizes
# Read first image from file
image = Magick::Image::read(imageName).first
# Resize image to maxium dimensions
image.resize_to_fit!(600,100000)
# Write image to file system
image.write(imageName)
# Free image from memory
image.destroy!
rescue Exception => e
puts e
end
driver.quit
}
end
pool.shutdown
puts "INFO: Commiting to github"
system('git add . --ignore-removal')
system("git commit -m #{cleanUrl} ")
system('git push origin master')
puts "INFO: Cleaning up and then done!".bold.red
system('rm *.png')
end