smartshot 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +8 -1
- data/lib/smartshot/screenshot.rb +4 -0
- data/lib/smartshot/version.rb +1 -1
- data/test/smartshot_test.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f2a658f8728e10b9da897ebda2968017f58ceab
|
4
|
+
data.tar.gz: 7644b10b19b2c8da6c24208c1fc818a248bc8dc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cae9603dee303712228faee64aee0f902434e7b86f3d58c655d7d369b2c71bb67363d4bc51093da7efe1912d3c611405b56ae198bc6dc0a0b8e031210c032cf
|
7
|
+
data.tar.gz: a45a1f7cb2735ebf523abc96fdf3a58b1832a9c72e5e0d302ae74e02e36fa125d859fa90e3678a2d10c7f4225df50f2e55893ba24afa648b0883aa93f2dafebf
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Smartshot
|
2
2
|
|
3
|
+
[](https://travis-ci.org/caiosba/smartshot)
|
4
|
+
[](http://badge.fury.io/rb/smartshot)
|
5
|
+
[](https://codeclimate.com/repos/5548f1dae30ba02e92005039/feed)
|
6
|
+
|
3
7
|
Captures a web page as a screenshot using Poltergeist, Capybara and PhantomJS.
|
4
8
|
It can wait for elements and also dive into iframes, while the existing gems
|
5
9
|
just wait for time or expect elements on the main window.
|
@@ -40,9 +44,12 @@ fetcher.take_screenshot! url: 'http://some.page.with/deep/iframes',
|
|
40
44
|
output: '/tmp/screenshot.png',
|
41
45
|
wait_for_element: 'div.embed',
|
42
46
|
frames_path: [0, 'name-of-an-iframe-inside-the-first-iframe', 'id-of-an-iframe-inside-the-previous-one']
|
47
|
+
|
48
|
+
# It's also possible to just wait for some time (for example, 5 seconds)
|
49
|
+
fetcher.take_screenshot! url: 'http://google.com', output: '/tmp/google.png', sleep: 5
|
43
50
|
```
|
44
51
|
|
45
|
-
Besides the
|
52
|
+
Besides the five custom options presented so far, it's possible to pass the same options accepted by
|
46
53
|
[Poltergeist's save screenshot method](https://github.com/teampoltergeist/poltergeist#taking-screenshots-with-some-extensions),
|
47
54
|
for example:
|
48
55
|
|
data/lib/smartshot/screenshot.rb
CHANGED
@@ -23,6 +23,10 @@ module Smartshot
|
|
23
23
|
inside_frames options.delete(:frames_path) do
|
24
24
|
page.find options.delete(:wait_for_element)
|
25
25
|
end
|
26
|
+
|
27
|
+
timeout = options.delete(:sleep)
|
28
|
+
sleep timeout unless timeout.nil?
|
29
|
+
|
26
30
|
page.driver.save_screenshot(options.delete(:output), options)
|
27
31
|
rescue => e
|
28
32
|
raise SmartshotError.new("Error: #{e.message.inspect}")
|
data/lib/smartshot/version.rb
CHANGED
data/test/smartshot_test.rb
CHANGED
@@ -42,7 +42,7 @@ class SmartshotTest < MiniTest::Unit::TestCase
|
|
42
42
|
waited = thumb(name)
|
43
43
|
File.delete waited if File.exists? waited
|
44
44
|
@smartshot.take_screenshot! url: 'http://ca.ios.ba/files/others/smartshot.html', output: waited, wait_for_element: 'p.Tweet-text',
|
45
|
-
frames_path: [0, 'child',
|
45
|
+
frames_path: [0, 'child', 0]
|
46
46
|
assert File.exists? waited
|
47
47
|
end
|
48
48
|
|
@@ -56,6 +56,26 @@ class SmartshotTest < MiniTest::Unit::TestCase
|
|
56
56
|
assert File.size(waited) > File.size(notwaited)
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_timeout
|
60
|
+
waited = notwaited = nil
|
61
|
+
|
62
|
+
%w(withtime).each do |name|
|
63
|
+
waited = thumb(name)
|
64
|
+
File.delete waited if File.exists? waited
|
65
|
+
@smartshot.take_screenshot! url: 'http://ca.ios.ba/files/others/smartshot.html', output: waited, sleep: 10
|
66
|
+
assert File.exists? waited
|
67
|
+
end
|
68
|
+
|
69
|
+
%w(notime).each do |name|
|
70
|
+
notwaited = thumb(name)
|
71
|
+
File.delete notwaited if File.exists? notwaited
|
72
|
+
@smartshot.take_screenshot! url: 'http://ca.ios.ba/files/others/smartshot.html', output: notwaited
|
73
|
+
assert File.exists? notwaited
|
74
|
+
end
|
75
|
+
|
76
|
+
assert File.size(waited) > File.size(notwaited)
|
77
|
+
end
|
78
|
+
|
59
79
|
def thumb(name)
|
60
80
|
File.join(DATA_DIR, "#{name}.png")
|
61
81
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Caio Almeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|