popart 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 005aeee61238d9ab0c097656e5003e90eb72c639
4
- data.tar.gz: 875d56fb6103b9f12c28b14cb2b9e572c8214f23
3
+ metadata.gz: 3f409136fba64bdca17bc8e6eedd84c15bf6bf12
4
+ data.tar.gz: dc1fded30805e9adf296b3b130f26cc05fede64f
5
5
  SHA512:
6
- metadata.gz: f471dfb57acc8d2db933a13e06a53166477ab2d1d8f2586f2d46aa99a3752856d832fa971d234e79b76ed192e2113190be4c3bfa6d205422ba3cc666e96a0c4d
7
- data.tar.gz: 8b970bf409d82ad3c41ba5175a742f2f0473baf6faaa683728c4cd1402a2c5bad7da550446fc428db4188f663c4e4f32dfa06de57fd9b5151ee4c4a3c4ac0e57
6
+ metadata.gz: 03f8e3d0388d75a94ea2492937f21e193fc93d7ea06548367f524d2c2ba9818fdce0829b68fee8da55a1f0fbc3fe7cd2ab9f05d626231c51980bd0fa44f41724
7
+ data.tar.gz: e89812d228542a459e5edd9a1b01a0bf5c749baa9bf768ad2c82aab3d42cc2c5810e1e758cd3a0ed0ab1cce42907e69e930b6f7b61839f58f981ade449b37abd
@@ -1,6 +1,7 @@
1
1
  # 0
2
- ## 0.1
3
- ### 1.1.2
2
+ ## 0.2.0
3
+ Added threads
4
+ ### 0.1.2
4
5
  Added YAML file parsing to specify browsers better
5
6
  ### 0.1.1
6
7
  Allowed for gem pushes
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- popart (0.1.2)
4
+ popart (0.2.0)
5
5
  parallel
6
6
  selenium-webdriver
7
7
 
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Use Sauce Labs to generate screenshots for your site across a range of browsers.
4
4
 
5
+ Popart works fast! It can use as much of your Sauce Labs concurrency as required (default is 5 concurrent sessions).
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -22,13 +24,17 @@ Or install it yourself as:
22
24
 
23
25
  Currently, Popart only supports screenshots of a single page directly accessible by URL (with or without Sauce Connect).
24
26
 
25
- To use Popart, install it (as above) then
27
+ To use Popart, install it (as above).
28
+
29
+ Set the `SAUCE_USERNAME` and `SAUCE_ACCESS_KEY` environment variables to the values for your account.
30
+
31
+ To run:
26
32
 
27
33
  `popart url_to_screenshot`.
28
34
 
29
35
  This will cause Popart to take a shot with the default browsers (Chrome and Firefox Latest on Windows 10) and save them to `./screenshots`.
30
36
 
31
- ### Configuring browsers and output location
37
+ ### Configuring browsers, threadcount and output location
32
38
 
33
39
  To configure further, copy `example_config.yaml` to your system, then customise to suit your requirements. Pass config files to Popart like so:
34
40
 
@@ -49,3 +55,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
49
55
 
50
56
  Bug reports and pull requests are welcome on GitHub at https://github.com/[DylanLacey]/popart. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
51
57
 
58
+ ## TODO
59
+ * Check account concurrency limit and use that by default
60
+ * Error handling. Any.
61
+
data/bin/popart CHANGED
@@ -1,23 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "popart"
3
3
 
4
- config = Popart::Config.new
5
- config.initial_config
4
+ Popart.configure
6
5
 
7
- browsers = config.browsers.map { |b| Popart::Browser.new b }
6
+ output_directory = Popart.configuration.output_directory
7
+ site = Popart.configuration.site
8
8
 
9
- STDOUT.puts "Fetching screenshots of #{config.site} and writing them to #{config.output_directory}"
9
+ #STDOUT.puts "Fetching screenshots of #{config.site} and writing them to #{config.output_directory}"
10
10
 
11
- screenshots = browsers.map do |browser|
12
- screenshot = browser.perform do |session|
13
- session.navigate.to config.site
14
- session.screenshot_as :png
15
- end
16
-
17
- filename = browser.capabilities["browserName"] + '_' + browser.capabilities["version"] + '_' + browser.capabilities["platform"] + '.png'
18
- filename.gsub! " ", "-"
19
-
20
- File.open((File.join config.output_directory, filename), 'w') do |file|
21
- file.write screenshot
22
- end
11
+ Popart.thread_things(output_directory) do |browser|
12
+ browser.navigate.to site
13
+ sleep 25
14
+ cat = browser.screenshot_as :png
23
15
  end
@@ -6,4 +6,5 @@ browsers:
6
6
  - { browserName: "Chrome", platform: "Windows 7", version: "latest"}
7
7
  - { browserName: "Safari", platform: "OS X 10.12", version: "latest"}
8
8
  - { browserName: "Chrome", platform: "Linux", version: "45"}
9
- output_directory: "./output"
9
+ output_directory: "./output"
10
+ thread_count: 3
@@ -1,7 +1,52 @@
1
1
  require "popart/version"
2
2
  require "popart/config"
3
3
  require "popart/browser"
4
+ require "popart/worker"
5
+ require "thread"
4
6
 
5
7
  module Popart
8
+ class << self
9
+ def configuration
10
+ @config ||= self.configure
11
+ end
6
12
 
13
+ def configure
14
+ @config = Popart::Config.new
15
+ @config.initial_config
16
+
17
+ @browsers = @config.browsers.map { |b| Popart::Browser.new b }
18
+ end
19
+
20
+ def save_screenshots directory, &actions
21
+ @browsers.each do |browser|
22
+ screenshot = browser.perform &actions
23
+
24
+ File.open((File.join directory, browser.filename), 'w') do |file|
25
+ file.write screenshot
26
+ end
27
+ end
28
+ end
29
+
30
+ def thread_things directory, &actions
31
+ threadcount = @config.thread_count
32
+ lock = Mutex.new
33
+
34
+ threads = []
35
+ threadcount.times do |t|
36
+ puts "Thread #{t}"
37
+ threads << Thread.new do
38
+ w = Popart::Worker.new @browsers, lock
39
+ w.perform do |browser|
40
+ screenshot = browser.perform &actions
41
+
42
+ File.open((File.join directory, browser.filename), 'w') do |file|
43
+ file.write screenshot
44
+ end
45
+ end
46
+ end
47
+ end
48
+
49
+ threads.map(&:join)
50
+ end
51
+ end
7
52
  end
@@ -12,8 +12,27 @@ module Popart
12
12
  unless @browser
13
13
  @browser = SeleniumSession.new capabilities
14
14
 
15
- yield @browser
15
+ begin
16
+ yield @browser
17
+ rescue
18
+
19
+ # TODO SOMETHING LESS CRAP HERE
20
+ end
16
21
  end
17
22
  end
23
+
24
+ def filename
25
+ filename = capabilities["browserName"] + '_' + capabilities["version"] + '_' + capabilities["platform"] + '.png'
26
+ filename.gsub! " ", "-"
27
+
28
+ filename
29
+ end
30
+
31
+ def cleanup
32
+ @browser.quit if @browser
33
+ rescue
34
+ ensure
35
+ @browser = nil
36
+ end
18
37
  end
19
38
  end
@@ -4,7 +4,7 @@ require "yaml"
4
4
  module Popart
5
5
  class Config
6
6
 
7
- attr_accessor :browsers, :output_directory, :site
7
+ attr_accessor :browsers, :output_directory, :site, :thread_count
8
8
 
9
9
  def default_browsers
10
10
  [
@@ -16,6 +16,10 @@ module Popart
16
16
  def default_output_directory
17
17
  './screenshots'
18
18
  end
19
+
20
+ def default_thread_count
21
+ 5
22
+ end
19
23
 
20
24
  def initial_config
21
25
  fn = ARGV[1] ||= './config.json'
@@ -33,11 +37,13 @@ module Popart
33
37
  @browsers = [config_hash["browsers"]].flatten
34
38
  @output_directory = config_hash["output_directory"]
35
39
  @site = config_hash["site"]
40
+ @thread_count = config_hash["thread_count"]
36
41
  end
37
42
 
38
43
  def set_defaults
39
44
  @browsers ||= default_browsers
40
45
  @output_directory ||= default_output_directory
46
+ @thread_count ||= default_thread_count
41
47
  set_site(@site ||= ARGV[0])
42
48
 
43
49
  @output_directory = Pathname.new @output_directory
@@ -0,0 +1,19 @@
1
+ require "parallel"
2
+ require "selenium/webdriver"
3
+
4
+ module Popart
5
+ class DoTheThing
6
+
7
+ attr_accessor :url, :number_of_threads
8
+
9
+ def initialize url, number_of_threads
10
+ @url = url
11
+ @number_of_threads = number_of_threads
12
+
13
+
14
+
15
+ filedatas = Parallel.map(browsers, :in_threads => number_of_threads) do |browser|
16
+
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module Popart
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,21 @@
1
+ module Popart
2
+ class Worker
3
+ def initialize browsers, lock
4
+ @browsers = browsers
5
+ @lock = lock
6
+ @work_remains = true
7
+ end
8
+
9
+ def perform &action
10
+ while @work_remains
11
+ browser = @lock.synchronize { @browsers.shift }
12
+ if browser
13
+ yield browser
14
+ browser.cleanup
15
+ else
16
+ @work_remains = false
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: popart
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Lacey
@@ -106,8 +106,10 @@ files:
106
106
  - lib/popart.rb
107
107
  - lib/popart/browser.rb
108
108
  - lib/popart/config.rb
109
+ - lib/popart/do_the_thing.rb
109
110
  - lib/popart/selenium_session.rb
110
111
  - lib/popart/version.rb
112
+ - lib/popart/worker.rb
111
113
  - popart.gemspec
112
114
  homepage: http://www.github.com/dylanlacey/popart
113
115
  licenses: []