browshot 1.29.0 → 1.32.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 +4 -4
- data/CHANGELOG.rdoc +12 -0
- data/Gemfile +2 -9
- data/LICENSE.txt +20 -0
- data/README.rdoc +94 -0
- data/VERSION +1 -0
- data/browshot.gemspec +20 -0
- data/lib/browshot.rb +87 -17
- data/test/helper.rb +14 -17
- data/test/test_browshot.rb +90 -454
- data/test/test_browshot_artifacts.rb +170 -0
- data/test/test_browshot_artifacts_live.rb +59 -0
- metadata +20 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 317dbeba50f7f1752fc19e9a70276f960e392c16625b4b7e93b0da5480f2c553
|
|
4
|
+
data.tar.gz: c9d5da63d1b89c23042f3d42a815741278ea2616ab999d8406f1d082e687e889
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b173a7d24fafdc88d438111ba7406d2438f8b85eaaec0acff8bdc3150f8cac41dd6d5f6a058aeb46fc8a69b026aff115023acfb27aa61593cebc77d12c84067e
|
|
7
|
+
data.tar.gz: c7be1e20220a454eaca0dded39158eafa89eb616d1df0172df557e1e7d82b885813dfe797a3ae5f2b504c36f74768cccd8be3b3bdb075720f363ff97274e1be7
|
data/CHANGELOG.rdoc
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
= Changelog
|
|
2
|
+
|
|
3
|
+
== 1.32.0
|
|
4
|
+
|
|
5
|
+
* Add +screenshot_pdf+, +screenshot_pdf_file+, +screenshot_video+, and
|
|
6
|
+
+screenshot_video_file+ for PDF, WebM, MP4, and GIF downloads.
|
|
7
|
+
* Pass the API 1.32 options through existing capture methods. Fix the batch
|
|
8
|
+
upload content type and allow the crawl starting URL in its options hash.
|
|
9
|
+
* Encode API keys and accept either symbol or string keys for repeated URL
|
|
10
|
+
and instance options.
|
|
11
|
+
* Document the options, credit costs, and native country instance IDs.
|
|
12
|
+
* Add offline artifact tests and opt-in live tests with an environment key.
|
data/Gemfile
CHANGED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright (c) 2011 Julien Sobrier
|
|
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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
= browshot
|
|
2
|
+
|
|
3
|
+
Browshot (http://www.browshot.com/) is a web service to easily make screenshots of web pages in any screen size, as any device: iPhone©, iPad©, Android©, Nook©, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support.
|
|
4
|
+
|
|
5
|
+
The latest API version is detailed at http://browshot.com/api/documentation. browshot follows the API documentation very closely: the function names are similar to the URLs used (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(), etc.), the request arguments are exactly the same, etc.
|
|
6
|
+
|
|
7
|
+
The library version matches closely the API version it handles: browshot 1.0.0 is the first release for the API 1.0, browshot 1.1.1 is the second release for the API 1.1, etc.
|
|
8
|
+
|
|
9
|
+
browshot can handle most the API updates within the same major version, e.g. browshot 1.0.0 should be compatible with the API 1.1 or 1.2.
|
|
10
|
+
|
|
11
|
+
Browshot gem is availabe at rubygems: https://rubygems.org/gems/browshot
|
|
12
|
+
|
|
13
|
+
== Build and install browshot
|
|
14
|
+
|
|
15
|
+
git clone https://github.com/juliensobrier/browshot-ruby
|
|
16
|
+
gem build browshot.gemspec
|
|
17
|
+
gem install --dev browshot-<version>.gem
|
|
18
|
+
rake test
|
|
19
|
+
rake rdoc
|
|
20
|
+
|
|
21
|
+
Or
|
|
22
|
+
|
|
23
|
+
gem install browshot
|
|
24
|
+
|
|
25
|
+
== API 1.32
|
|
26
|
+
|
|
27
|
+
Pass capture options in the existing parameter hash.
|
|
28
|
+
|
|
29
|
+
require 'browshot'
|
|
30
|
+
|
|
31
|
+
client = Browshot.new(ENV.fetch('BROWSHOT_API_KEY'))
|
|
32
|
+
capture = client.screenshot_create('https://example.com/',
|
|
33
|
+
instance_id: 373, pdf: 1, pdf_format: 'a4', pdf_margin: '10mm',
|
|
34
|
+
device_scale: 2, hide_ads: 1)
|
|
35
|
+
|
|
36
|
+
Poll +screenshot_info(capture['id'])+ until its status is +finished+.
|
|
37
|
+
Use +screenshot_pdf(capture['id'])+ to read the PDF bytes or
|
|
38
|
+
+screenshot_pdf_file(capture['id'], 'example.pdf')+ to save them.
|
|
39
|
+
|
|
40
|
+
For a video or animated GIF, request the recording when creating the capture.
|
|
41
|
+
|
|
42
|
+
recording = client.screenshot_create('https://example.com/',
|
|
43
|
+
instance_id: 373, video: 1, video_format: 'gif',
|
|
44
|
+
video_duration: 5, video_scale: 0.5)
|
|
45
|
+
|
|
46
|
+
Once the capture finishes, use +screenshot_video(recording['id'])+ for the
|
|
47
|
+
bytes or +screenshot_video_file(recording['id'], 'example.gif')+ to save the
|
|
48
|
+
file. The video formats are WebM (default), MP4, and GIF. MP4 can fall back to
|
|
49
|
+
WebM, and the file helper uses the supplied path and extension. Download
|
|
50
|
+
methods return binary strings, and file helpers return the path on success.
|
|
51
|
+
Both return an empty string on failure.
|
|
52
|
+
|
|
53
|
+
PDF options include paper format (+letter+, +a4+, or +legal+), background,
|
|
54
|
+
landscape, one-page output, and PDF margins. Video options include duration
|
|
55
|
+
(1 to 30 seconds), quality (0 to 63), frame rate (1 to 30), and scale
|
|
56
|
+
(0.1 to 1). GIF uses 20 frames per second.
|
|
57
|
+
|
|
58
|
+
Choose a country with +instance_id+. The new instances below are listed in
|
|
59
|
+
order Chrome, Firefox, iPhone 12, and Samsung S20.
|
|
60
|
+
|
|
61
|
+
France 373 374 375 376
|
|
62
|
+
India 377 378 379 380
|
|
63
|
+
Finland 381 382 383 384
|
|
64
|
+
United Kingdom 385 386 387 388
|
|
65
|
+
|
|
66
|
+
Each instance costs one credit before options. PDF adds one credit, and a
|
|
67
|
+
recording adds one credit for every started five seconds of requested duration.
|
|
68
|
+
PDF and video require a paid Chrome-based instance. Recording requires
|
|
69
|
+
+device_scale=1+. Retina (+device_scale=2+), ad blocking (+hide_ads=1+), and
|
|
70
|
+
downloads add no credits.
|
|
71
|
+
|
|
72
|
+
== Tests
|
|
73
|
+
|
|
74
|
+
Run +bundle install+ and +bundle exec rake test+. The offline tests use a
|
|
75
|
+
loopback HTTP server. Set +BROWSHOT_API_KEY+ to run live tests. Use
|
|
76
|
+
+BROWSHOT_SCREENSHOT_ID+ for an owned finished screenshot and
|
|
77
|
+
+BROWSHOT_RETINA_ID+ for one with retina and ad blocking enabled. The PDF,
|
|
78
|
+
WebM, MP4, and GIF checks use +BROWSHOT_PDF_ID+, +BROWSHOT_WEBM_ID+,
|
|
79
|
+
+BROWSHOT_MP4_ID+, and +BROWSHOT_GIF_ID+ for finished captures in your account.
|
|
80
|
+
|
|
81
|
+
== Contributing to browshot
|
|
82
|
+
|
|
83
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
|
84
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
|
85
|
+
* Fork the project
|
|
86
|
+
* Start a feature/bugfix branch
|
|
87
|
+
* Commit and push until you are happy with your contribution
|
|
88
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
|
89
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
|
90
|
+
|
|
91
|
+
== Copyright
|
|
92
|
+
|
|
93
|
+
Copyright (c) 2014 Julien Sobrier. See LICENSE.txt for
|
|
94
|
+
further details.
|
data/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.32.0
|
data/browshot.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = 'browshot'
|
|
3
|
+
s.version = File.read(File.expand_path('VERSION', File.dirname(__FILE__))).strip
|
|
4
|
+
s.summary = "Take website screenshots with Browshot"
|
|
5
|
+
s.description = "Library for the Browshot API"
|
|
6
|
+
s.authors = ["Julien Sobrier"]
|
|
7
|
+
s.email = 'julien@sobrier.net'
|
|
8
|
+
s.files = ["Gemfile", "Rakefile", "README.rdoc", "CHANGELOG.rdoc", "LICENSE.txt", "VERSION", "browshot.gemspec", "lib/browshot.rb"]
|
|
9
|
+
s.require_paths = ["lib"]
|
|
10
|
+
s.test_files = Dir["test/*.rb"]
|
|
11
|
+
s.homepage = 'https://browshot.com/'
|
|
12
|
+
s.license = 'MIT'
|
|
13
|
+
s.add_dependency "json"
|
|
14
|
+
s.add_dependency "url"
|
|
15
|
+
s.add_development_dependency "rake"
|
|
16
|
+
s.add_development_dependency "shoulda-context"
|
|
17
|
+
s.add_development_dependency "yard"
|
|
18
|
+
s.add_development_dependency 'test-unit'
|
|
19
|
+
s.add_development_dependency 'webrick'
|
|
20
|
+
end
|
data/lib/browshot.rb
CHANGED
|
@@ -16,6 +16,8 @@ require 'net/https'
|
|
|
16
16
|
require "cgi"
|
|
17
17
|
|
|
18
18
|
class Browshot
|
|
19
|
+
VERSION = '1.32.0'
|
|
20
|
+
|
|
19
21
|
# @!attribute [r]
|
|
20
22
|
# API key
|
|
21
23
|
attr_reader :key
|
|
@@ -39,7 +41,7 @@ class Browshot
|
|
|
39
41
|
|
|
40
42
|
# Return the API version handled by the library. Note that this library can usually handle new arguments in requests without requiring an update.
|
|
41
43
|
def api_version()
|
|
42
|
-
return
|
|
44
|
+
return VERSION.split('.')[0, 2].join('.')
|
|
43
45
|
end
|
|
44
46
|
|
|
45
47
|
# Retrieve a screenshot with one call. See {https://browshot.com/api/documentation#simple} for the full list of possible arguments.
|
|
@@ -211,6 +213,34 @@ class Browshot
|
|
|
211
213
|
end
|
|
212
214
|
|
|
213
215
|
|
|
216
|
+
# Download the PDF generated by a finished screenshot requested with pdf=1.
|
|
217
|
+
#
|
|
218
|
+
# @param id [Integer, String] Screenshot ID
|
|
219
|
+
# @return [String] PDF bytes, or an empty string on failure
|
|
220
|
+
def screenshot_pdf(id=0, parameters={})
|
|
221
|
+
return screenshot_artifact('pdf', id, parameters, ['application/pdf'])
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Download the WebM, MP4, or GIF generated by a finished screenshot requested with video=1.
|
|
225
|
+
#
|
|
226
|
+
# @param id [Integer, String] Screenshot ID
|
|
227
|
+
# @return [String] Recording bytes, or an empty string on failure
|
|
228
|
+
def screenshot_video(id=0, parameters={})
|
|
229
|
+
return screenshot_artifact('video', id, parameters, ['video/webm', 'video/mp4', 'image/gif'])
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Save a PDF to a local file and return its name, or an empty string on failure.
|
|
233
|
+
def screenshot_pdf_file(id=0, file='', parameters={})
|
|
234
|
+
return save_artifact(:screenshot_pdf, id, file, parameters)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Save a video to a local file and return its name, or an empty string on failure.
|
|
238
|
+
# MP4 requests can produce WebM. The file name stays as supplied.
|
|
239
|
+
def screenshot_video_file(id=0, file='', parameters={})
|
|
240
|
+
return save_artifact(:screenshot_video, id, file, parameters)
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
|
|
214
244
|
# Request multiple screenshots. See http://browshot.com/api/documentation#screenshot_multiple for the response format.
|
|
215
245
|
#
|
|
216
246
|
# See http://browshot.com/api/documentation#screenshot_multiple for the full list of possible arguments.
|
|
@@ -242,21 +272,21 @@ class Browshot
|
|
|
242
272
|
return return_reply('batch/info', parameters)
|
|
243
273
|
end
|
|
244
274
|
|
|
245
|
-
#Crawl a domain. See
|
|
275
|
+
# Crawl a domain. See https://browshot.com/api/documentation#crawl_create.
|
|
246
276
|
#
|
|
247
|
-
# See http://browshot.com/api/documentation#crawl_create for the full list of possible arguments.
|
|
248
|
-
#
|
|
249
277
|
# @param id [Integer] Instance ID
|
|
250
278
|
# @param domain [String] Domain to crawl
|
|
251
|
-
# @param
|
|
252
|
-
def crawl_create(id=0,
|
|
253
|
-
parameters
|
|
254
|
-
|
|
255
|
-
|
|
279
|
+
# @param parameters [Hash] Capture options, including an optional :url to start with
|
|
280
|
+
def crawl_create(id=0, domain='', parameters={})
|
|
281
|
+
parameters = parameters.merge(:instance_id => id)
|
|
282
|
+
unless domain.empty?
|
|
283
|
+
parameters.delete('domain')
|
|
284
|
+
parameters[:domain] = domain
|
|
285
|
+
end
|
|
256
286
|
|
|
257
287
|
return return_reply('crawl/create', parameters)
|
|
258
288
|
end
|
|
259
|
-
|
|
289
|
+
|
|
260
290
|
# Get information about a screenshot crawl requested previously. See {https://browshot.com/api/documentation#crawl_info} for the response format.
|
|
261
291
|
#
|
|
262
292
|
# See http://browshot.com/api/documentation#crawl_info for the full list of possible arguments.
|
|
@@ -276,21 +306,61 @@ class Browshot
|
|
|
276
306
|
|
|
277
307
|
private
|
|
278
308
|
|
|
309
|
+
def screenshot_artifact(kind, id, parameters, content_types)
|
|
310
|
+
return ''.b unless id.to_s =~ /\A[1-9][0-9]{0,18}\z/
|
|
311
|
+
|
|
312
|
+
query = parameters.reject { |key, _| key.to_s == 'id' }
|
|
313
|
+
query[:id] = id
|
|
314
|
+
url = URI(make_url('screenshot/' + kind, query))
|
|
315
|
+
request = Net::HTTP::Get.new(url.request_uri, {
|
|
316
|
+
'Accept-Encoding' => 'identity', 'User-Agent' => "Browshot Ruby #{VERSION}"
|
|
317
|
+
})
|
|
318
|
+
response = Net::HTTP.start(url.host, url.port, :use_ssl => url.scheme == 'https') do |http|
|
|
319
|
+
http.request(request)
|
|
320
|
+
end
|
|
321
|
+
return ''.b unless response.code == '200'
|
|
322
|
+
|
|
323
|
+
type = response['content-type'].to_s.partition(';').first.strip.downcase
|
|
324
|
+
return ''.b unless content_types.include?(type)
|
|
325
|
+
|
|
326
|
+
body = response.body.to_s.b
|
|
327
|
+
length = response['content-length']
|
|
328
|
+
return ''.b if length && length.to_i != body.bytesize
|
|
329
|
+
|
|
330
|
+
return body
|
|
331
|
+
rescue IOError, SystemCallError, SocketError, Timeout::Error, OpenSSL::SSL::SSLError,
|
|
332
|
+
Net::HTTPBadResponse, Net::ProtocolError
|
|
333
|
+
return ''.b
|
|
334
|
+
end
|
|
335
|
+
|
|
336
|
+
def save_artifact(method, id, file, parameters)
|
|
337
|
+
return '' unless file.is_a?(String) || file.respond_to?(:to_path)
|
|
338
|
+
return '' if file == ''
|
|
339
|
+
|
|
340
|
+
content = public_send(method, id, parameters)
|
|
341
|
+
return '' if content.empty?
|
|
342
|
+
|
|
343
|
+
File.binwrite(file, content)
|
|
344
|
+
return file
|
|
345
|
+
rescue IOError, SystemCallError, ArgumentError
|
|
346
|
+
return ''
|
|
347
|
+
end
|
|
348
|
+
|
|
279
349
|
def make_url(action='', parameters={})
|
|
280
|
-
url = "#{@base}#{action}?key=#{@key}"
|
|
350
|
+
url = "#{@base}#{action}?key=#{CGI::escape(@key.to_s)}"
|
|
281
351
|
|
|
282
352
|
|
|
283
353
|
parameters.each_pair do |key, value|
|
|
284
|
-
if (key == 'urls')
|
|
354
|
+
if (key.to_s == 'urls')
|
|
285
355
|
value.each { |val|
|
|
286
356
|
url += '&url=' + CGI::escape(val.to_s)
|
|
287
357
|
}
|
|
288
|
-
elsif (key == 'instances')
|
|
358
|
+
elsif (key.to_s == 'instances')
|
|
289
359
|
value.each { |instance|
|
|
290
360
|
url += '&instance_id=' + CGI::escape(instance.to_s)
|
|
291
361
|
}
|
|
292
362
|
else
|
|
293
|
-
url += "&#{key}=" + CGI::escape(value.to_s)
|
|
363
|
+
url += "&#{CGI::escape(key.to_s)}=" + CGI::escape(value.to_s)
|
|
294
364
|
end
|
|
295
365
|
end
|
|
296
366
|
|
|
@@ -368,7 +438,7 @@ class Browshot
|
|
|
368
438
|
http.open_timeout = 240
|
|
369
439
|
http.read_timeout = 240
|
|
370
440
|
|
|
371
|
-
request = Net::HTTP::Get.new(uri.request_uri, {'User-Agent' =>
|
|
441
|
+
request = Net::HTTP::Get.new(uri.request_uri, {'User-Agent' => "Browshot Ruby #{VERSION}"})
|
|
372
442
|
if (uri.scheme == 'https')
|
|
373
443
|
http.use_ssl = true
|
|
374
444
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
|
@@ -403,9 +473,9 @@ class Browshot
|
|
|
403
473
|
post_body << File.read(file)
|
|
404
474
|
post_body << "\r\n--#{boundary}--\r\n"
|
|
405
475
|
|
|
406
|
-
request = Net::HTTP::Post.new(uri.request_uri, {'User-Agent' =>
|
|
476
|
+
request = Net::HTTP::Post.new(uri.request_uri, {'User-Agent' => "Browshot Ruby #{VERSION}"})
|
|
407
477
|
request.body = post_body.join
|
|
408
|
-
request["Content-Type"] = "multipart/form-data
|
|
478
|
+
request["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
|
|
409
479
|
|
|
410
480
|
if (uri.scheme == 'https')
|
|
411
481
|
http.use_ssl = true
|
data/test/helper.rb
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'shoulda'
|
|
3
|
-
require 'bundler'
|
|
4
|
-
|
|
5
|
-
begin
|
|
6
|
-
Bundler.setup(:default, :development)
|
|
7
|
-
rescue Bundler::BundlerError => e
|
|
8
|
-
$stderr.puts e.message
|
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
|
10
|
-
exit e.status_code
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
require 'rubygems'
|
|
14
1
|
require 'test/unit'
|
|
15
|
-
|
|
2
|
+
require 'shoulda/context'
|
|
16
3
|
|
|
17
|
-
|
|
18
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
19
|
-
require 'browshot'
|
|
4
|
+
require_relative '../lib/browshot'
|
|
20
5
|
|
|
21
6
|
class Test::Unit::TestCase
|
|
7
|
+
def live_browshot
|
|
8
|
+
key = ENV['BROWSHOT_API_KEY']
|
|
9
|
+
omit('Set BROWSHOT_API_KEY for live tests') if key.nil? || key.empty?
|
|
10
|
+
Browshot.new(key)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def fixture_id(name)
|
|
14
|
+
variable = "BROWSHOT_#{name.upcase}_ID"
|
|
15
|
+
id = ENV[variable]
|
|
16
|
+
omit("Set #{variable} to an owned test capture ID") if id.nil? || id.empty?
|
|
17
|
+
id
|
|
18
|
+
end
|
|
22
19
|
end
|
data/test/test_browshot.rb
CHANGED
|
@@ -1,479 +1,115 @@
|
|
|
1
|
-
|
|
2
|
-
require
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require 'tmpdir'
|
|
3
3
|
|
|
4
4
|
class TestBrowshot < Test::Unit::TestCase
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
# assert_equal(1, 1)
|
|
10
|
-
# end
|
|
11
|
-
context "Browshot client" do
|
|
12
|
-
setup do
|
|
13
|
-
@browshot = Browshot.new('vPTtKKLBtPUNxVwwfEKlVvekuxHyTXyi')
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
should "get the API version" do
|
|
17
|
-
assert_equal '1.29', @browshot.api_version()
|
|
5
|
+
context 'Browshot client' do
|
|
6
|
+
should 'report the API version' do
|
|
7
|
+
assert_equal '1.32', Browshot.new.api_version
|
|
8
|
+
assert_equal '1.32.0', Browshot::VERSION
|
|
18
9
|
end
|
|
10
|
+
end
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
assert_equal true, data[:png].length > 0, "Screenshot should be sent"
|
|
12
|
+
context 'Browshot API with an account' do
|
|
13
|
+
setup do
|
|
14
|
+
@browshot = live_browshot
|
|
24
15
|
end
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
17
|
+
should 'get a screenshot with the simple method and save it to disk' do
|
|
18
|
+
parameters = { :url => 'https://browshot.com/', :instance_id => 12, :cache => 365 * 86400 }
|
|
19
|
+
response = @browshot.simple(parameters)
|
|
20
|
+
assert_equal 200, response[:code].to_i
|
|
21
|
+
assert response[:png].bytesize > 100
|
|
22
|
+
Dir.mktmpdir do |directory|
|
|
23
|
+
path = File.join(directory, 'capture.png')
|
|
24
|
+
saved = @browshot.simple_file(path, parameters)
|
|
25
|
+
assert_equal 200, saved[:code].to_i
|
|
26
|
+
assert_equal path, saved[:file]
|
|
27
|
+
assert_equal response[:png].bytes, File.binread(path).bytes
|
|
28
|
+
end
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
should
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
assert_equal true, instances['free'].kind_of?(Array), "List of free instances is incorrect"
|
|
37
|
-
assert_equal true, instances['free'].length > 0, "There should be at least 1 free instance"
|
|
38
|
-
|
|
39
|
-
assert_equal false, instances['shared'].nil?, "List of shared instances is missing"
|
|
40
|
-
assert_equal true, instances['shared'].kind_of?(Array), "List of shared instances is incorrect"
|
|
41
|
-
assert_equal true, instances['shared'].length > 0, "There should be at least 1 shared instance"
|
|
42
|
-
|
|
43
|
-
assert_equal false, instances['private'].nil?, "List of private instances is missing"
|
|
44
|
-
assert_equal true, instances['private'].kind_of?(Array), "List of private instances is incorrect"
|
|
45
|
-
assert_equal true, instances['private'].length == 1, "There should be at least no private instance"
|
|
46
|
-
|
|
47
|
-
free = instances['free'][0]
|
|
48
|
-
assert_equal false, free['id'].nil?, "Missing instance ID"
|
|
49
|
-
assert_equal false, free['width'].nil?, "Missing instance screen width"
|
|
50
|
-
assert_equal false, free['height'].nil?, "Missing instance screen height"
|
|
51
|
-
assert_equal false, free['load'].nil?, "Missing instance load"
|
|
52
|
-
assert_equal false, free['browser'].nil?, "Missing instance browser"
|
|
53
|
-
assert_equal false, free['browser']['id'].nil?, "Missing instance browser ID"
|
|
54
|
-
assert_equal false, free['browser']['name'].nil?, "Missing instance browser name"
|
|
55
|
-
assert_equal false, free['browser']['javascript'].nil?, "Missing instance browser javascript capability"
|
|
56
|
-
assert_equal false, free['browser']['flash'].nil?, "Missing instance browser flash capability"
|
|
57
|
-
assert_equal false, free['browser']['mobile'].nil?, "Missing instance browser mobile capability"
|
|
58
|
-
assert_equal false, free['type'].nil?, "Missing instance type"
|
|
59
|
-
assert_equal false, free['screenshot_cost'].nil?, "Missing instance cost"
|
|
60
|
-
assert_equal 0, free['screenshot_cost'].to_i, "Cost should be 0"
|
|
31
|
+
should 'return an error for an invalid Simple API URL' do
|
|
32
|
+
response = @browshot.simple(:url => 'http://', :instance_id => 12)
|
|
33
|
+
assert_equal 400, response[:code].to_i
|
|
34
|
+
assert_equal '', response[:png]
|
|
61
35
|
end
|
|
62
36
|
|
|
63
|
-
should
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
37
|
+
should 'list free shared and private instances and fetch a free instance' do
|
|
38
|
+
instances = @browshot.instance_list
|
|
39
|
+
%w[free shared private].each { |type| assert_kind_of Array, instances[type] }
|
|
40
|
+
assert !instances['free'].empty?
|
|
41
|
+
assert !instances['shared'].empty?
|
|
42
|
+
free = instances['free'].first
|
|
43
|
+
instance = @browshot.instance_info(free['id'])
|
|
44
|
+
%w[id width height type screenshot_cost].each do |key|
|
|
45
|
+
assert_not_nil free[key]
|
|
46
|
+
assert_equal free[key], instance[key]
|
|
47
|
+
end
|
|
48
|
+
%w[id name javascript mobile].each do |key|
|
|
49
|
+
assert_not_nil free['browser'][key]
|
|
50
|
+
assert_equal free['browser'][key], instance['browser'][key]
|
|
51
|
+
end
|
|
52
|
+
assert_equal 0, instance['screenshot_cost'].to_i
|
|
79
53
|
end
|
|
80
54
|
|
|
81
|
-
should
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
55
|
+
should 'list browsers and fetch the details of a browser' do
|
|
56
|
+
browsers = @browshot.browser_list
|
|
57
|
+
assert !browsers.empty?
|
|
58
|
+
id, browser = browsers.first
|
|
59
|
+
assert id.to_i > 0
|
|
60
|
+
info = @browshot.browser_info(id)
|
|
61
|
+
%w[name user_agent appname vendorsub appcodename platform vendor appversion javascript mobile].each do |key|
|
|
62
|
+
assert browser.key?(key), "Missing #{key} in browser list"
|
|
63
|
+
assert info.key?(key), "Missing #{key} in browser details"
|
|
64
|
+
end
|
|
65
|
+
assert_equal browser['name'], info['name']
|
|
86
66
|
end
|
|
87
67
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
#
|
|
95
|
-
# instance = @browshot.instance_create({'browser_id' => -1})
|
|
96
|
-
# assert_equal false, instance['error'].nil?, "Instance browser ID should be invalid"
|
|
97
|
-
# end
|
|
98
|
-
|
|
99
|
-
# should "create a new instance" do
|
|
100
|
-
# # Option disabled for most accounts
|
|
101
|
-
# instance = @browshot.instance_create()
|
|
102
|
-
#
|
|
103
|
-
# assert_equal false, instance['error'].nil?, "Instance cannot be created for this account"
|
|
104
|
-
# # assert_equal false, instance['id'].nil?, "Instance ID should be present"
|
|
105
|
-
# # assert_equal false, instance['width'].nil?, "Instance screen width should be present"
|
|
106
|
-
# # assert_equal false, instance['height'].nil?, "Instance screen height should be present"
|
|
107
|
-
# # assert_equal 1, instance['active'].to_i, "Instance should be active"
|
|
108
|
-
# # assert_equal false, instance['browser'].nil?, "Instance browser should be present"
|
|
109
|
-
# # assert_equal false, instance['browser']['id'].nil?, "Instance browser ID should be present"
|
|
110
|
-
# end
|
|
111
|
-
|
|
112
|
-
should "get the list of browsers" do
|
|
113
|
-
browsers = @browshot.browser_list()
|
|
114
|
-
assert_equal true, browsers.length > 0, "There should be multiple browsers"
|
|
115
|
-
|
|
116
|
-
browser_id = 0
|
|
117
|
-
browsers.each do |key, browser|
|
|
118
|
-
browser_id = key
|
|
119
|
-
break
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
assert_equal true, browser_id.to_i > 0, "Browser ID should be positive"
|
|
123
|
-
browser = browsers[browser_id]
|
|
124
|
-
|
|
125
|
-
assert_equal false, browser['name'].nil?, "Browser name should be present"
|
|
126
|
-
assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
|
|
127
|
-
assert_equal false, browser['appname'].nil?, "Browser appname should be present"
|
|
128
|
-
assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
|
|
129
|
-
assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
|
|
130
|
-
assert_equal false, browser['platform'].nil?, "Browser platform should be present"
|
|
131
|
-
assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
|
|
132
|
-
assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
|
|
133
|
-
assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
|
|
134
|
-
assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
|
|
135
|
-
assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
|
|
68
|
+
should 'report validation errors for invalid capture requests' do
|
|
69
|
+
assert @browshot.instance_info(-1)['error']
|
|
70
|
+
assert @browshot.screenshot_create('http://', :instance_id => 12)['error']
|
|
71
|
+
assert @browshot.screenshot_info(0)['error']
|
|
72
|
+
assert @browshot.screenshot_host(0)['error']
|
|
73
|
+
assert @browshot.screenshot_share(0)['error']
|
|
136
74
|
end
|
|
137
75
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# assert_equal false, browser['error'].nil?, "Browser cannot be created for this account"
|
|
143
|
-
# # assert_equal false, browser['name'].nil?, "Browser name should be present"
|
|
144
|
-
# # assert_equal false, browser['user_agent'].nil?, "Browser user_agent should be present"
|
|
145
|
-
# # assert_equal false, browser['appname'].nil?, "Browser appname should be present"
|
|
146
|
-
# # assert_equal false, browser['vendorsub'].nil?, "Browser vendorsub should be present"
|
|
147
|
-
# # assert_equal false, browser['appcodename'].nil?, "Browser appcodename should be present"
|
|
148
|
-
# # assert_equal false, browser['platform'].nil?, "Browser platform should be present"
|
|
149
|
-
# # assert_equal false, browser['vendor'].nil?, "Browser vendor should be present"
|
|
150
|
-
# # assert_equal false, browser['appversion'].nil?, "Browser appversion should be present"
|
|
151
|
-
# # assert_equal false, browser['javascript'].nil?, "Browser javascript capability should be present"
|
|
152
|
-
# # assert_equal false, browser['mobile'].nil?, "Browser mobile capability should be present"
|
|
153
|
-
# # assert_equal false, browser['flash'].nil?, "Browser flash capability should be present"
|
|
154
|
-
# end
|
|
155
|
-
|
|
156
|
-
should "fail to create screenshot" do
|
|
157
|
-
screenshot = @browshot.screenshot_create()
|
|
158
|
-
assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
|
|
159
|
-
|
|
160
|
-
screenshot = @browshot.screenshot_create('-')
|
|
161
|
-
assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
|
|
76
|
+
should 'create a screenshot and return its legacy identity fields' do
|
|
77
|
+
screenshot = @browshot.screenshot_create('https://browshot.com/', :instance_id => 12, :cache => 365 * 86400)
|
|
78
|
+
%w[id url instance_id size status priority].each { |key| assert screenshot.key?(key) }
|
|
79
|
+
assert_include %w[in_process in_queue finished], screenshot['status']
|
|
162
80
|
end
|
|
163
81
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
assert_equal false, screenshot['width'].nil?, "Screenshot width should be present"
|
|
178
|
-
assert_equal false, screenshot['height'].nil?, "Screenshot height should be present"
|
|
179
|
-
assert_equal false, screenshot['request_time'].nil?, "Screenshot request_time should be present"
|
|
180
|
-
assert_equal false, screenshot['started'].nil?, "Screenshot started should be present"
|
|
181
|
-
assert_equal false, screenshot['load'].nil?, "Screenshot load should be present"
|
|
182
|
-
assert_equal false, screenshot['content'].nil?, "Screenshot content should be present"
|
|
183
|
-
assert_equal false, screenshot['finished'].nil?, "Screenshot finished should be present"
|
|
184
|
-
assert_equal false, screenshot['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
185
|
-
assert_equal false, screenshot['response_code'].nil?, "Screenshot response_code should be present"
|
|
186
|
-
assert_equal false, screenshot['final_url'].nil?, "Screenshot final_url should be present"
|
|
187
|
-
assert_equal false, screenshot['content_type'].nil?, "Screenshot content_type should be present"
|
|
188
|
-
assert_equal false, screenshot['scale'].nil?, "Screenshot scale should be present"
|
|
189
|
-
assert_equal false, screenshot['cost'].nil?, "Screenshot cost should be present"
|
|
190
|
-
end
|
|
82
|
+
should 'fetch screenshot metadata at all legacy detail levels' do
|
|
83
|
+
id = fixture_id('screenshot')
|
|
84
|
+
[0, 1, 2].each do |level|
|
|
85
|
+
info = @browshot.screenshot_info(id, :details => level)
|
|
86
|
+
assert_equal id, info['id'].to_s
|
|
87
|
+
assert_equal 'finished', info['status']
|
|
88
|
+
assert !info['screenshot_url'].empty?
|
|
89
|
+
assert_equal level >= 1, info.key?('final_url')
|
|
90
|
+
assert_equal level >= 1, info.key?('response_code')
|
|
91
|
+
assert_equal level >= 2, info.key?('started')
|
|
92
|
+
assert_equal level >= 2, info.key?('finished')
|
|
93
|
+
assert !info.key?('images')
|
|
94
|
+
end
|
|
191
95
|
end
|
|
192
96
|
|
|
193
|
-
should
|
|
194
|
-
|
|
195
|
-
|
|
97
|
+
should 'list and search for screenshots and retrieve a PNG thumbnail' do
|
|
98
|
+
id = fixture_id('screenshot')
|
|
99
|
+
info = @browshot.screenshot_info(id)
|
|
100
|
+
screenshots = @browshot.screenshot_list(:limit => 1)
|
|
101
|
+
assert !screenshots.empty?
|
|
102
|
+
assert screenshots.values.first.key?('status')
|
|
103
|
+
assert @browshot.screenshot_search(info['url']).key?(id)
|
|
104
|
+
assert_equal "\x89PNG\r\n\x1a\n".b, @browshot.screenshot_thumbnail(id, :width => 64).byteslice(0, 8)
|
|
196
105
|
end
|
|
197
106
|
|
|
198
|
-
should
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
|
|
205
|
-
assert_equal false, info['cost'].nil?, "Screenshot cost should be present"
|
|
206
|
-
|
|
207
|
-
if (info['status'] == 'finished')
|
|
208
|
-
assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
209
|
-
assert_equal false, info['url'].nil?, "Screenshot url should be present"
|
|
210
|
-
assert_equal false, info['size'].nil?, "Screenshot size should be present"
|
|
211
|
-
assert_equal false, info['width'].nil?, "Screenshot width should be present"
|
|
212
|
-
assert_equal false, info['height'].nil?, "Screenshot height should be present"
|
|
213
|
-
assert_equal false, info['request_time'].nil?, "Screenshot request_time should be present"
|
|
214
|
-
assert_equal false, info['started'].nil?, "Screenshot started should be present"
|
|
215
|
-
assert_equal false, info['load'].nil?, "Screenshot load should be present"
|
|
216
|
-
assert_equal false, info['content'].nil?, "Screenshot content should be present"
|
|
217
|
-
assert_equal false, info['finished'].nil?, "Screenshot finished should be present"
|
|
218
|
-
assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
219
|
-
assert_equal false, info['response_code'].nil?, "Screenshot response_code should be present"
|
|
220
|
-
assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
|
|
221
|
-
assert_equal false, info['content_type'].nil?, "Screenshot content_type should be present"
|
|
222
|
-
assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
|
|
223
|
-
end
|
|
107
|
+
should 'get account information and reject an invalid key' do
|
|
108
|
+
account = @browshot.account_info
|
|
109
|
+
assert account.key?('balance')
|
|
110
|
+
assert account['balance'].to_i >= 0
|
|
111
|
+
assert_equal 1, account['active'].to_i
|
|
112
|
+
assert Browshot.new('invalid-test-key').account_info['error']
|
|
224
113
|
end
|
|
225
|
-
|
|
226
|
-
should "retrieve a screenshot with details==0" do
|
|
227
|
-
screenshot = @browshot.screenshot_create('http://browshot.com/')
|
|
228
|
-
info = @browshot.screenshot_info(screenshot['id'], { 'details' => 0 })
|
|
229
|
-
|
|
230
|
-
assert_equal false, info['id'].nil?, "Screenshot ID should be present"
|
|
231
|
-
assert_equal false, info['status'].nil?, "Screenshot status should be present"
|
|
232
|
-
assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
|
|
233
|
-
assert_equal false, info['cost'].nil?, "Screenshot cost should be present"
|
|
234
|
-
|
|
235
|
-
if (info['status'] == 'finished')
|
|
236
|
-
assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
237
|
-
assert_equal false, info['url'].nil?, "Screenshot url should be present"
|
|
238
|
-
assert_equal false, info['size'].nil?, "Screenshot size should be present"
|
|
239
|
-
assert_equal false, info['width'].nil?, "Screenshot width should be present"
|
|
240
|
-
assert_equal false, info['height'].nil?, "Screenshot height should be present"
|
|
241
|
-
assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
242
|
-
assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
|
|
243
|
-
assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
|
|
244
|
-
|
|
245
|
-
# assert_equal true, info['response_code'].nil?, "Screenshot response_code should NOT be present"
|
|
246
|
-
# assert_equal true, info['content_type'].nil?, "Screenshot content_type should NOT be present"
|
|
247
|
-
|
|
248
|
-
# assert_equal true, info['started'].nil?, "Screenshot started should NOT be present"
|
|
249
|
-
# assert_equal true, info['finished'].nil?, "Screenshot finished should NOT be present"
|
|
250
|
-
# assert_equal true, info['load'].nil?, "Screenshot load should NOT be present"
|
|
251
|
-
# assert_equal true, info['request_time'].nil?, "Screenshot request_time should NOT be present"
|
|
252
|
-
# assert_equal true, info['content'].nil?, "Screenshot content should NOT be present"
|
|
253
|
-
|
|
254
|
-
# assert_equal true, info['images'].nil?, "Screenshot images should NOT be present"
|
|
255
|
-
end
|
|
256
|
-
end
|
|
257
|
-
|
|
258
|
-
should "retrieve a screenshot with details==1" do
|
|
259
|
-
screenshot = @browshot.screenshot_create('http://browshot.com/')
|
|
260
|
-
info = @browshot.screenshot_info(screenshot['id'], { 'details' => 1 })
|
|
261
|
-
|
|
262
|
-
assert_equal false, info['id'].nil?, "Screenshot ID should be present"
|
|
263
|
-
assert_equal false, info['status'].nil?, "Screenshot status should be present"
|
|
264
|
-
assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
|
|
265
|
-
assert_equal false, info['cost'].nil?, "Screenshot cost should be present"
|
|
266
|
-
|
|
267
|
-
if (info['status'] == 'finished')
|
|
268
|
-
assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
269
|
-
assert_equal false, info['url'].nil?, "Screenshot url should be present"
|
|
270
|
-
assert_equal false, info['size'].nil?, "Screenshot size should be present"
|
|
271
|
-
assert_equal false, info['width'].nil?, "Screenshot width should be present"
|
|
272
|
-
assert_equal false, info['height'].nil?, "Screenshot height should be present"
|
|
273
|
-
assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
274
|
-
assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
|
|
275
|
-
assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
|
|
276
|
-
|
|
277
|
-
assert_equal false, info['response_code'].nil?, "Screenshot response_code should be present"
|
|
278
|
-
assert_equal false, info['content_type'].nil?, "Screenshot content_type should be present"
|
|
279
|
-
|
|
280
|
-
# assert_equal true, info['started'].nil?, "Screenshot started should NOT be present"
|
|
281
|
-
# assert_equal true, info['finished'].nil?, "Screenshot finished should NOT be present"
|
|
282
|
-
# assert_equal true, info['load'].nil?, "Screenshot load should NOT be present"
|
|
283
|
-
# assert_equal true, info['request_time'].nil?, "Screenshot request_time should NOT be present"
|
|
284
|
-
# assert_equal true, info['content'].nil?, "Screenshot content should NOT be present"
|
|
285
|
-
|
|
286
|
-
# assert_equal true, info['images'].nil?, "Screenshot images should NOT be present"
|
|
287
|
-
end
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
should "to retrieve a screenshot with details==2" do
|
|
291
|
-
screenshot = @browshot.screenshot_create('http://browshot.com/')
|
|
292
|
-
info = @browshot.screenshot_info(screenshot['id'], { 'details' => 2 })
|
|
293
|
-
|
|
294
|
-
assert_equal false, info['id'].nil?, "Screenshot ID should be present"
|
|
295
|
-
assert_equal false, info['status'].nil?, "Screenshot status should be present"
|
|
296
|
-
assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
|
|
297
|
-
assert_equal false, info['cost'].nil?, "Screenshot cost should be present"
|
|
298
|
-
|
|
299
|
-
if (info['status'] == 'finished')
|
|
300
|
-
assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
301
|
-
assert_equal false, info['url'].nil?, "Screenshot url should be present"
|
|
302
|
-
assert_equal false, info['size'].nil?, "Screenshot size should be present"
|
|
303
|
-
assert_equal false, info['width'].nil?, "Screenshot width should be present"
|
|
304
|
-
assert_equal false, info['height'].nil?, "Screenshot height should be present"
|
|
305
|
-
assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
306
|
-
assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
|
|
307
|
-
assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
|
|
308
|
-
|
|
309
|
-
assert_equal false, info['response_code'].nil?, "Screenshot response_code should be present"
|
|
310
|
-
assert_equal false, info['content_type'].nil?, "Screenshot content_type should be present"
|
|
311
|
-
|
|
312
|
-
assert_equal false, info['started'].nil?, "Screenshot started should be present"
|
|
313
|
-
assert_equal false, info['finished'].nil?, "Screenshot finished should be present"
|
|
314
|
-
assert_equal false, info['load'].nil?, "Screenshot load should be present"
|
|
315
|
-
assert_equal false, info['request_time'].nil?, "Screenshot request_time should be present"
|
|
316
|
-
assert_equal false, info['content'].nil?, "Screenshot content should be present"
|
|
317
|
-
|
|
318
|
-
assert_equal true, info['images'].nil?, "Screenshot images should NOT be present"
|
|
319
|
-
end
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
# Details = 2 by default
|
|
323
|
-
# should "to retrieve a screenshot with details==3" do
|
|
324
|
-
# screenshot = @browshot.screenshot_create('http://browshot.com/')
|
|
325
|
-
# info = @browshot.screenshot_info(screenshot['id'], { 'details' => 3 })
|
|
326
|
-
#
|
|
327
|
-
# assert_equal false, info['id'].nil?, "Screenshot ID should be present"
|
|
328
|
-
# assert_equal false, info['status'].nil?, "Screenshot status should be present"
|
|
329
|
-
# assert_equal false, info['priority'].nil?, "Screenshot priority should be present"
|
|
330
|
-
# assert_equal false, info['cost'].nil?, "Screenshot cost should be present"
|
|
331
|
-
#
|
|
332
|
-
# if (info['status'] == 'finished')
|
|
333
|
-
# assert_equal false, info['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
334
|
-
# assert_equal false, info['url'].nil?, "Screenshot url should be present"
|
|
335
|
-
# assert_equal false, info['size'].nil?, "Screenshot size should be present"
|
|
336
|
-
# assert_equal false, info['width'].nil?, "Screenshot width should be present"
|
|
337
|
-
# assert_equal false, info['height'].nil?, "Screenshot height should be present"
|
|
338
|
-
# assert_equal false, info['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
339
|
-
# assert_equal false, info['final_url'].nil?, "Screenshot final_url should be present"
|
|
340
|
-
# assert_equal false, info['scale'].nil?, "Screenshot scale should be present"
|
|
341
|
-
#
|
|
342
|
-
# assert_equal false, info['response_code'].nil?, "Screenshot response_code should be present"
|
|
343
|
-
# assert_equal false, info['content_type'].nil?, "Screenshot content_type should be present"
|
|
344
|
-
#
|
|
345
|
-
# assert_equal false, info['started'].nil?, "Screenshot started should be present"
|
|
346
|
-
# assert_equal false, info['finished'].nil?, "Screenshot finished should be present"
|
|
347
|
-
# assert_equal false, info['load'].nil?, "Screenshot load should be present"
|
|
348
|
-
# assert_equal false, info['request_time'].nil?, "Screenshot request_time should be present"
|
|
349
|
-
# assert_equal false, info['content'].nil?, "Screenshot content should be present"
|
|
350
|
-
#
|
|
351
|
-
# assert_equal false, info['images'].nil?, "Screenshot images should be present"
|
|
352
|
-
# assert_equal true, info['images'].length > 0, "Screenshot images should be present"
|
|
353
|
-
# assert_equal false, info['scripts'].nil?, "Screenshot scripts should be present"
|
|
354
|
-
# assert_equal false, info['iframes'].nil?, "Screenshot iframes should be present"
|
|
355
|
-
# assert_equal false, info['embeds'].nil?, "Screenshot embeds should be present"
|
|
356
|
-
# end
|
|
357
|
-
# end
|
|
358
|
-
|
|
359
|
-
should "retrieve the list of screenshots" do
|
|
360
|
-
screenshots = @browshot.screenshot_list()
|
|
361
|
-
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
|
362
|
-
|
|
363
|
-
screenshot_id = 0
|
|
364
|
-
screenshots.each do |key, screenshot|
|
|
365
|
-
screenshot_id = key
|
|
366
|
-
break
|
|
367
|
-
end
|
|
368
|
-
|
|
369
|
-
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
|
370
|
-
screenshot = screenshots[screenshot_id]
|
|
371
|
-
|
|
372
|
-
assert_equal false, screenshot['id'].nil?, "Screenshot ID should be present"
|
|
373
|
-
assert_equal false, screenshot['status'].nil?, "Screenshot status should be present"
|
|
374
|
-
assert_equal false, screenshot['priority'].nil?, "Screenshot priority should be present"
|
|
375
|
-
assert_equal false, screenshot['cost'].nil?, "Screenshot cost should be present"
|
|
376
|
-
|
|
377
|
-
if (screenshot['status'] == 'finished')
|
|
378
|
-
assert_equal false, screenshot['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
|
|
379
|
-
assert_equal false, screenshot['url'].nil?, "Screenshot url should be present"
|
|
380
|
-
assert_equal false, screenshot['size'].nil?, "Screenshot size should be present"
|
|
381
|
-
assert_equal false, screenshot['width'].nil?, "Screenshot width should be present"
|
|
382
|
-
assert_equal false, screenshot['height'].nil?, "Screenshot height should be present"
|
|
383
|
-
assert_equal false, screenshot['request_time'].nil?, "Screenshot request_time should be present"
|
|
384
|
-
assert_equal false, screenshot['started'].nil?, "Screenshot started should be present"
|
|
385
|
-
assert_equal false, screenshot['load'].nil?, "Screenshot load should be present"
|
|
386
|
-
assert_equal false, screenshot['content'].nil?, "Screenshot content should be present"
|
|
387
|
-
assert_equal false, screenshot['finished'].nil?, "Screenshot finished should be present"
|
|
388
|
-
assert_equal false, screenshot['instance_id'].nil?, "Screenshot instance_id should be present"
|
|
389
|
-
assert_equal false, screenshot['response_code'].nil?, "Screenshot response_code should be present"
|
|
390
|
-
assert_equal false, screenshot['final_url'].nil?, "Screenshot final_url should be present"
|
|
391
|
-
assert_equal false, screenshot['content_type'].nil?, "Screenshot content_type should be present"
|
|
392
|
-
assert_equal false, screenshot['scale'].nil?, "Screenshot scale should be present"
|
|
393
|
-
end
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
should "retrieve a thumbnail" do
|
|
397
|
-
screenshots = @browshot.screenshot_list()
|
|
398
|
-
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
|
399
|
-
|
|
400
|
-
screenshot_id = 0
|
|
401
|
-
screenshots.each do |key, screenshot|
|
|
402
|
-
screenshot_id = key
|
|
403
|
-
break
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
|
407
|
-
|
|
408
|
-
thumbnail = @browshot.screenshot_thumbnail(screenshot_id, { 'width' => 480 });
|
|
409
|
-
assert_equal 'PNG', thumbnail[1..3], "Thumbnail is a valid PNG"
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
should "Fail hosting screenshots" do
|
|
413
|
-
screenshots = @browshot.screenshot_list()
|
|
414
|
-
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
|
415
|
-
|
|
416
|
-
screenshot_id = 0
|
|
417
|
-
screenshots.each do |key, screenshot|
|
|
418
|
-
screenshot_id = key
|
|
419
|
-
break
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
|
423
|
-
|
|
424
|
-
hosting = @browshot.screenshot_host(screenshot_id)
|
|
425
|
-
assert_equal 'error', hosting['status'], "Default hosting option not enabled for this account"
|
|
426
|
-
|
|
427
|
-
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 's3' })
|
|
428
|
-
assert_equal 'error', hosting['status'], "S3 hosting option not enabled for this account"
|
|
429
|
-
|
|
430
|
-
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 's3', 'bucket' => 'mine' })
|
|
431
|
-
assert_equal 'error', hosting['status'], "S3 hosting option not enabled for this account"
|
|
432
|
-
|
|
433
|
-
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 'cdn' })
|
|
434
|
-
assert_equal 'error', hosting['status'], "CDN hosting option not enabled for this account"
|
|
435
|
-
|
|
436
|
-
hosting = @browshot.screenshot_host(screenshot_id, { 'hosting' => 'browshot' })
|
|
437
|
-
assert_equal 'error', hosting['status'], "Browshot hosting option not enabled for this account"
|
|
438
|
-
end
|
|
439
|
-
|
|
440
|
-
should "Fail sharing a screenshots" do
|
|
441
|
-
hosting = @browshot.screenshot_share(0)
|
|
442
|
-
assert_equal 'error', hosting['status'], "Missing screenshot ID"
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
should "Search for screenshots" do
|
|
446
|
-
screenshots = @browshot.screenshot_search('google.com', { :details => 0 })
|
|
447
|
-
assert_equal true, screenshots.length > 0, "There should be multiple screenshots"
|
|
448
|
-
|
|
449
|
-
screenshot_id = 0
|
|
450
|
-
screenshots.each do |key, screenshot|
|
|
451
|
-
screenshot_id = key
|
|
452
|
-
break
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
assert_equal true, screenshot_id.to_i > 0, "Screenshot ID should be positive"
|
|
456
|
-
screenshot = screenshots[screenshot_id]
|
|
457
|
-
|
|
458
|
-
assert_equal false, screenshot['id'].nil?, "Screenshot ID should be present"
|
|
459
|
-
assert_equal false, screenshot['status'].nil?, "Screenshot status should be present"
|
|
460
|
-
assert_equal false, screenshot['priority'].nil?, "Screenshot priority should be present"
|
|
461
|
-
assert_equal false, screenshot['cost'].nil?, "Screenshot cost should be present"
|
|
462
|
-
end
|
|
463
|
-
|
|
464
|
-
should "retrieve account information" do
|
|
465
|
-
account = @browshot.account_info()
|
|
466
|
-
assert_equal false, account['balance'].nil?, "Account balance should be present"
|
|
467
|
-
assert_equal 0, account['balance'].to_i, "Balance should be empty"
|
|
468
|
-
assert_equal false, account['active'].nil?, "Account active should be present"
|
|
469
|
-
assert_equal 1, account['active'].to_i, "Accountshould be active"
|
|
470
|
-
# assert_equal false, account['instances'].nil?, "Account instances should be present"
|
|
471
|
-
end
|
|
472
|
-
|
|
473
|
-
should "refuse invalid key" do
|
|
474
|
-
bad = Browshot.new()
|
|
475
|
-
account = bad.account_info()
|
|
476
|
-
assert_equal false, account['error'].nil?, "Request should be invalid"
|
|
477
|
-
end
|
|
478
114
|
end
|
|
479
115
|
end
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require 'tmpdir'
|
|
3
|
+
require 'webrick'
|
|
4
|
+
|
|
5
|
+
class TestBrowshotArtifacts < Test::Unit::TestCase
|
|
6
|
+
FIXTURE_ID = '9007199254740991'
|
|
7
|
+
TEST_KEY = 'test key & value'
|
|
8
|
+
ARTIFACTS = {
|
|
9
|
+
'pdf' => ['application/pdf', "%PDF-1.7\n\x00\x80\xff".b],
|
|
10
|
+
'webm' => ['video/webm', "\x1a\x45\xdf\xa3\x00\x80\xff".b],
|
|
11
|
+
'mp4' => ['video/mp4', "\x00\x00\x00\x10ftyp\x00\x80\xff".b],
|
|
12
|
+
'gif' => ['image/gif', "GIF89a\x00\x80\xff".b]
|
|
13
|
+
}.freeze
|
|
14
|
+
|
|
15
|
+
context 'API 1.32 against a local server' do
|
|
16
|
+
setup do
|
|
17
|
+
ready = Queue.new
|
|
18
|
+
@server = WEBrick::HTTPServer.new(
|
|
19
|
+
:BindAddress => '127.0.0.1', :Port => 0,
|
|
20
|
+
:Logger => WEBrick::Log.new(File::NULL), :AccessLog => [],
|
|
21
|
+
:StartCallback => proc { ready << true }
|
|
22
|
+
)
|
|
23
|
+
@server.mount_proc('/') { |request, response| fixture_response(request, response) }
|
|
24
|
+
@server_thread = Thread.new { @server.start }
|
|
25
|
+
Timeout.timeout(5) { ready.pop }
|
|
26
|
+
@browshot = Browshot.new(TEST_KEY, false, "http://127.0.0.1:#{@server.config[:Port]}/api/v1/")
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
teardown do
|
|
30
|
+
@server.shutdown
|
|
31
|
+
@server_thread.join
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
should 'download and save all four artifact formats without changing their bytes' do
|
|
35
|
+
ARTIFACTS.each do |format, (_, content)|
|
|
36
|
+
download = format == 'pdf' ? :screenshot_pdf : :screenshot_video
|
|
37
|
+
save = format == 'pdf' ? :screenshot_pdf_file : :screenshot_video_file
|
|
38
|
+
options = { :stub_format => format, 'id' => '1' }
|
|
39
|
+
|
|
40
|
+
data = @browshot.public_send(download, FIXTURE_ID, options)
|
|
41
|
+
assert_equal content, data
|
|
42
|
+
assert_equal Encoding::BINARY, data.encoding
|
|
43
|
+
assert_equal '1', options['id']
|
|
44
|
+
|
|
45
|
+
Dir.mktmpdir do |directory|
|
|
46
|
+
path = File.join(directory, "capture.#{format}")
|
|
47
|
+
assert_equal path, @browshot.public_send(save, FIXTURE_ID, path, options)
|
|
48
|
+
assert_equal content, File.binread(path)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
should 'accept WebM when an MP4 request falls back' do
|
|
54
|
+
assert_equal ARTIFACTS['webm'][1], @browshot.screenshot_video(FIXTURE_ID, :video_format => 'mp4')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
should 'reject erroneous empty or truncated responses and incorrect content types' do
|
|
58
|
+
[:screenshot_pdf, :screenshot_video].each do |method|
|
|
59
|
+
[400, 401, 404, 503].each do |status|
|
|
60
|
+
assert_equal '', @browshot.public_send(method, FIXTURE_ID, :stub_status => status)
|
|
61
|
+
end
|
|
62
|
+
[:stub_bad_type, :stub_empty, :stub_truncated].each do |flag|
|
|
63
|
+
assert_equal '', @browshot.public_send(method, FIXTURE_ID, flag => 1)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
assert_equal '', @browshot.screenshot_pdf(FIXTURE_ID, :stub_format => 'gif')
|
|
67
|
+
assert_equal '', @browshot.screenshot_video(FIXTURE_ID, :stub_format => 'pdf')
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
should 'reject invalid screenshot IDs and local paths' do
|
|
71
|
+
[0, -1, nil, '1.5', 'test', '9' * 20, "1\n"].each do |id|
|
|
72
|
+
assert_equal '', @browshot.screenshot_pdf(id)
|
|
73
|
+
assert_equal '', @browshot.screenshot_video(id)
|
|
74
|
+
end
|
|
75
|
+
assert_equal '', @browshot.screenshot_pdf_file(FIXTURE_ID, '')
|
|
76
|
+
assert_equal '', @browshot.screenshot_video_file(FIXTURE_ID, 1)
|
|
77
|
+
assert_equal '', @browshot.screenshot_video_file(FIXTURE_ID, "bad\0path")
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
should 'leave an existing file intact on a download failure and handle write errors' do
|
|
81
|
+
Dir.mktmpdir do |directory|
|
|
82
|
+
path = File.join(directory, 'existing.pdf')
|
|
83
|
+
File.binwrite(path, 'original')
|
|
84
|
+
assert_equal '', @browshot.screenshot_pdf_file(FIXTURE_ID, path, :stub_status => 404)
|
|
85
|
+
assert_equal 'original', File.binread(path)
|
|
86
|
+
assert_equal '', @browshot.screenshot_video_file(FIXTURE_ID, File.join(path, 'capture.gif'))
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
should 'forward all capture options through single multiple batch and crawl requests' do
|
|
91
|
+
options = {
|
|
92
|
+
:pdf => 1, :pdf_format => 'a4', :pdf_background => 1, :pdf_landscape => 0,
|
|
93
|
+
:pdf_one_page => 1, :pdf_margin => '10mm', :pdf_margin_top => '1cm',
|
|
94
|
+
:pdf_margin_bottom => '0.5in', :pdf_margin_left => '2px', :pdf_margin_right => '3px',
|
|
95
|
+
:video => 1, :video_format => 'mp4', :video_duration => 5, :video_quality => 24,
|
|
96
|
+
:video_fps => 20, :video_scale => 0.5, :device_scale => 1, :hide_ads => true
|
|
97
|
+
}
|
|
98
|
+
url = 'https://example.com/?a=hello+world&b=1'
|
|
99
|
+
single = @browshot.screenshot_create(url, options.merge(:instance_id => 373))
|
|
100
|
+
assert_capture_options single, 'screenshot/create', options
|
|
101
|
+
assert_equal ['373'], single['query']['instance_id']
|
|
102
|
+
assert_equal [url], single['query']['url']
|
|
103
|
+
|
|
104
|
+
multiple = @browshot.screenshot_multiple(options.merge(:urls => [url, 'https://example.net/'], 'instances' => [373, 377]))
|
|
105
|
+
assert_capture_options multiple, 'screenshot/multiple', options
|
|
106
|
+
assert_equal [url, 'https://example.net/'], multiple['query']['url']
|
|
107
|
+
assert_equal ['373', '377'], multiple['query']['instance_id']
|
|
108
|
+
|
|
109
|
+
crawl = @browshot.crawl_create(381, 'example.com', options.merge(:url => url))
|
|
110
|
+
assert_capture_options crawl, 'crawl/create', options
|
|
111
|
+
assert_equal ['381'], crawl['query']['instance_id']
|
|
112
|
+
assert_equal ['example.com'], crawl['query']['domain']
|
|
113
|
+
assert_equal [url], crawl['query']['url']
|
|
114
|
+
|
|
115
|
+
Dir.mktmpdir do |directory|
|
|
116
|
+
path = File.join(directory, 'urls.csv')
|
|
117
|
+
File.write(path, url + "\n")
|
|
118
|
+
batch = @browshot.batch_create(385, path, options.dup)
|
|
119
|
+
assert_capture_options batch, 'batch/create', options
|
|
120
|
+
assert_equal ['385'], batch['query']['instance_id']
|
|
121
|
+
assert_equal 'POST', batch['method']
|
|
122
|
+
assert_equal url + "\n", batch['file']
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
def fixture_response(request, response)
|
|
130
|
+
query = URI.decode_www_form(request.query_string.to_s).group_by(&:first)
|
|
131
|
+
query = query.transform_values { |pairs| pairs.map(&:last) }
|
|
132
|
+
if query['stub_status']
|
|
133
|
+
response.status = query['stub_status'].first.to_i
|
|
134
|
+
response['Content-Type'] = 'application/json'
|
|
135
|
+
response.body = '{"error":"test"}'
|
|
136
|
+
return
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
if ['/api/v1/screenshot/pdf', '/api/v1/screenshot/video'].include?(request.path)
|
|
140
|
+
unless query['id'] == [FIXTURE_ID] && query['key'] == [TEST_KEY] && request.request_method == 'GET'
|
|
141
|
+
response.status = 404
|
|
142
|
+
return
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
default_format = request.path.end_with?('/pdf') ? 'pdf' : 'webm'
|
|
146
|
+
format = query.fetch('stub_format', [default_format]).first
|
|
147
|
+
media_type, body = ARTIFACTS.fetch(format)
|
|
148
|
+
media_type = 'text/html' if query.key?('stub_bad_type')
|
|
149
|
+
body = ''.b if query.key?('stub_empty')
|
|
150
|
+
response['Content-Type'] = media_type.upcase + '; charset=binary'
|
|
151
|
+
if query.key?('stub_truncated')
|
|
152
|
+
response['Content-Length'] = (body.bytesize + 1).to_s
|
|
153
|
+
response['Connection'] = 'close'
|
|
154
|
+
end
|
|
155
|
+
response.body = body
|
|
156
|
+
else
|
|
157
|
+
response['Content-Type'] = 'application/json'
|
|
158
|
+
response.body = JSON.generate(
|
|
159
|
+
'path' => request.path, 'query' => query,
|
|
160
|
+
'method' => request.request_method, 'file' => request.query['file']
|
|
161
|
+
)
|
|
162
|
+
end
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
def assert_capture_options(result, path, options)
|
|
166
|
+
assert_equal '/api/v1/' + path, result['path']
|
|
167
|
+
assert_equal [TEST_KEY], result['query']['key']
|
|
168
|
+
options.each { |key, value| assert_equal [value.to_s], result['query'][key.to_s], key.to_s }
|
|
169
|
+
end
|
|
170
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require_relative 'helper'
|
|
2
|
+
require 'tmpdir'
|
|
3
|
+
|
|
4
|
+
class TestBrowshotArtifactsLive < Test::Unit::TestCase
|
|
5
|
+
context 'API 1.32 with an account' do
|
|
6
|
+
setup do
|
|
7
|
+
@browshot = live_browshot
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
{
|
|
11
|
+
'pdf' => ['%PDF-'.b, 0],
|
|
12
|
+
'webm' => ["\x1a\x45\xdf\xa3".b, 0],
|
|
13
|
+
'mp4' => ['ftyp'.b, 4],
|
|
14
|
+
'gif' => ['GIF8'.b, 0]
|
|
15
|
+
}.each do |format, (signature, offset)|
|
|
16
|
+
should "download and save a live #{format.upcase} artifact" do
|
|
17
|
+
id = fixture_id(format)
|
|
18
|
+
kind = format == 'pdf' ? 'pdf' : 'video'
|
|
19
|
+
method = 'screenshot_' + kind
|
|
20
|
+
info = @browshot.screenshot_info(id, :details => 1)
|
|
21
|
+
assert_equal 'finished', info['status']
|
|
22
|
+
assert_equal 1, info[kind].to_i
|
|
23
|
+
assert !info[kind + '_url'].empty?
|
|
24
|
+
|
|
25
|
+
content = @browshot.public_send(method, id)
|
|
26
|
+
assert_equal signature, content.byteslice(offset, signature.bytesize)
|
|
27
|
+
Dir.mktmpdir do |directory|
|
|
28
|
+
path = File.join(directory, "capture.#{format}")
|
|
29
|
+
assert_equal path, @browshot.public_send(method + '_file', id, path)
|
|
30
|
+
assert_equal content, File.binread(path)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
should 'list all sixteen native country instances at one credit' do
|
|
36
|
+
instances = @browshot.instance_list['shared'].each_with_object({}) { |instance, ids| ids[instance['id']] = instance }
|
|
37
|
+
countries = ['France', 'India', 'Finland', 'United Kingdom']
|
|
38
|
+
(373..388).each do |id|
|
|
39
|
+
assert instances.key?(id), "Missing instance #{id}"
|
|
40
|
+
assert_equal countries[(id - 373) / 4], instances[id]['country']
|
|
41
|
+
assert_equal 1, instances[id]['screenshot_cost'].to_i
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
should 'return retina and ad blocking metadata' do
|
|
46
|
+
info = @browshot.screenshot_info(fixture_id('retina'), :details => 1)
|
|
47
|
+
assert_equal 'finished', info['status']
|
|
48
|
+
assert_equal 2, info['device_scale'].to_i
|
|
49
|
+
assert_equal 1, info['hide_ads'].to_i
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
should 'return empty strings for unavailable or unauthorized artifacts' do
|
|
53
|
+
[@browshot, Browshot.new('invalid-test-key')].each do |client|
|
|
54
|
+
assert_equal '', client.screenshot_pdf(1)
|
|
55
|
+
assert_equal '', client.screenshot_video(1)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: browshot
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.32.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Julien Sobrier
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-11-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: json
|
|
@@ -39,21 +39,21 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: rake
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
|
-
name:
|
|
56
|
+
name: shoulda-context
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
59
|
- - ">="
|
|
@@ -67,7 +67,7 @@ dependencies:
|
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
68
|
version: '0'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
|
-
name:
|
|
70
|
+
name: yard
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
73
|
- - ">="
|
|
@@ -81,7 +81,7 @@ dependencies:
|
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
|
-
name:
|
|
84
|
+
name: test-unit
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
87
|
- - ">="
|
|
@@ -95,7 +95,7 @@ dependencies:
|
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
98
|
-
name:
|
|
98
|
+
name: webrick
|
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
|
100
100
|
requirements:
|
|
101
101
|
- - ">="
|
|
@@ -114,11 +114,18 @@ executables: []
|
|
|
114
114
|
extensions: []
|
|
115
115
|
extra_rdoc_files: []
|
|
116
116
|
files:
|
|
117
|
+
- CHANGELOG.rdoc
|
|
117
118
|
- Gemfile
|
|
119
|
+
- LICENSE.txt
|
|
120
|
+
- README.rdoc
|
|
118
121
|
- Rakefile
|
|
122
|
+
- VERSION
|
|
123
|
+
- browshot.gemspec
|
|
119
124
|
- lib/browshot.rb
|
|
120
125
|
- test/helper.rb
|
|
121
126
|
- test/test_browshot.rb
|
|
127
|
+
- test/test_browshot_artifacts.rb
|
|
128
|
+
- test/test_browshot_artifacts_live.rb
|
|
122
129
|
homepage: https://browshot.com/
|
|
123
130
|
licenses:
|
|
124
131
|
- MIT
|
|
@@ -144,5 +151,7 @@ signing_key:
|
|
|
144
151
|
specification_version: 4
|
|
145
152
|
summary: Take website screenshots with Browshot
|
|
146
153
|
test_files:
|
|
154
|
+
- test/test_browshot_artifacts.rb
|
|
155
|
+
- test/test_browshot_artifacts_live.rb
|
|
147
156
|
- test/helper.rb
|
|
148
157
|
- test/test_browshot.rb
|