browshot 1.16.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.
@@ -1,479 +1,115 @@
1
- current_dir = File.expand_path(File.dirname(__FILE__))
2
- require "#{current_dir}/helper"
1
+ require_relative 'helper'
2
+ require 'tmpdir'
3
3
 
4
4
  class TestBrowshot < Test::Unit::TestCase
5
- # def test_new
6
- # puts "New client"
7
- # client = Browshot.new()
8
- # client = Browshot.new(key='',nil,debug=1)
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.16', @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
- should "get a screenshot with the simple method" do
21
- data = @browshot.simple({'url' => 'http://mobilito.net/', 'cache' => 60 * 60 * 24 * 365})
22
- assert_equal 200, data[:code].to_i, "Screenshot should be succesful"
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
- should "get an error with the simple method" do
27
- data = @browshot.simple({'url' => 'http://', 'cache' => 60 * 60 * 24 * 365})
28
- assert_equal 400, data[:code].to_i, "Screenshot should have failed"
29
- assert_equal 0, data[:png].length, "Screenshot should not be sent"
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 "get the list of instances available" do
33
- # assert_equal 10, @calculator.product(2, 5)
34
- instances = @browshot.instance_list()
35
- assert_equal false, instances['free'].nil?, "List of free instances is missing"
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 "get an instance information" do
64
- instances = @browshot.instance_list()
65
- free = instances['free'][0]
66
-
67
- instance = @browshot.instance_info(free['id'])
68
- assert_equal free['id'], instance['id'], "Mismatch instance ID"
69
- assert_equal free['width'], instance['width'], "Mismatch instance screen width"
70
- assert_equal free['height'], instance['height'], "Mismatch instance screen height"
71
- # assert_equal free['load'], instance['load'], "Mismatch instance load"
72
- assert_equal free['browser']['id'], instance['browser']['id'], "Mismatch instance browser ID"
73
- assert_equal free['browser']['name'], instance['browser']['name'], "Mismatch instance browser name"
74
- assert_equal free['browser']['javascript'], instance['browser']['javascript'],"Mismatch instance browser javascript capability"
75
- assert_equal free['browser']['flash'], instance['browser']['flash'], "Mismatch instance browser flash capability"
76
- assert_equal free['browser']['mobile'].to_i, instance['browser']['mobile'].to_i, "Mismatch instance browser mobile capability"
77
- assert_equal free['type'], instance['type'], "Mismatch instance type"
78
- assert_equal free['screenshot_cost'].to_i, instance['screenshot_cost'].to_i, "Mismatch instance cost"
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 "send an error for the wrong instance ID" do
82
- instance = @browshot.instance_info(-1)
83
-
84
- assert_equal false, instance['error'].nil?, "Instance should not be found"
85
- assert_equal false, instance['status'].nil?, "Instance should not be found"
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
- # should "send an errror when creating a instance with ivalid arguments" do
89
- # instance = @browshot.instance_create({'width' => 3000})
90
- # assert_equal false, instance['error'].nil?, "Instance width should be too large"
91
- #
92
- # instance = @browshot.instance_create({'height' => 3000})
93
- # assert_equal false, instance['error'].nil?, "Instance width should be too large"
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
- # should "create a browser" do
139
- # # Option disabled for most accounts
140
- # browser = @browshot.browser_create({'mobile' => 1, 'flash' => 1, 'user_agent' => 'test'})
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
- should "create screenshot" do
166
- # screenshot is not actually created for test account, so the reply may not match our parameters
167
- screenshot = @browshot.screenshot_create('http://browshot.com/')
168
-
169
- assert_equal false, screenshot['id'].nil?, "Screenshot ID should be present"
170
- assert_equal false, screenshot['status'].nil?, "Screenshot status should be present"
171
- assert_equal false, screenshot['priority'].nil?, "Screenshot priority should be present"
172
-
173
- if (screenshot['status'] == 'finished')
174
- assert_equal false, screenshot['screenshot_url'].nil?, "Screenshot screenshot_url should be present"
175
- assert_equal false, screenshot['url'].nil?, "Screenshot url should be present"
176
- assert_equal false, screenshot['size'].nil?, "Screenshot size should be present"
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 "not be able to retrieve a screenshot" do
194
- screenshot = @browshot.screenshot_info()
195
- assert_equal false, screenshot['error'].nil?, "Screenshot should have failed"
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 "retrieve a screenshot" do
199
- screenshot = @browshot.screenshot_create('http://browshot.com/')
200
- info = @browshot.screenshot_info(screenshot['id'])
201
-
202
- assert_equal false, info['id'].nil?, "Screenshot ID should be present"
203
- assert_equal false, info['status'].nil?, "Screenshot status should be present"
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