1
1
#! /usr/bin/env ruby
2
2
require 'selenium/webdriver'
3
- require 'net/https '
3
+ require 'rest_client '
4
4
require 'json'
5
5
6
6
url = "http://#{ ENV [ 'BS_USERNAME' ] } :#{ ENV [ 'BS_AUTHKEY' ] } @hub.browserstack.com/wd/hub"
17
17
18
18
begin
19
19
loop do
20
- uri = URI . parse ( "https://www.browserstack.com/automate/plan.json" )
21
- agent = Net ::HTTP . new ( uri . host , uri . port )
22
- agent . use_ssl = true
23
- request = Net ::HTTP ::Get . new ( uri . request_uri )
24
- request . basic_auth ( ENV [ 'BS_USERNAME' ] , ENV [ 'BS_AUTHKEY' ] )
25
-
26
- state = JSON . parse ( agent . request ( request ) . body )
20
+ response = RestClient . get ( "https://#{ ENV [ 'BS_USERNAME' ] } :#{ ENV [ 'BS_AUTHKEY' ] } @www.browserstack.com/automate/plan.json" )
21
+ state = JSON . parse ( response . to_str )
27
22
28
23
if state [ "parallel_sessions_running" ] < state [ "parallel_sessions_max_allowed" ]
29
24
break
39
34
retry
40
35
end
41
36
42
- def screenshot ( browser )
43
- browser . capture_entire_page_screenshot ( 'screenshot.png' )
44
- request = Net ::HTTP . new ( 'imgur.com' )
45
- response = request . post ( '/api/upload.json' , image : File . open ( 'screenshot.png' ) )
46
-
47
- JSON . parse ( response . body ) [ 'rsp' ] [ 'image' ] [ 'original_image' ]
48
- end
49
-
50
37
print "\r Running specs..."
51
38
52
39
begin
@@ -60,20 +47,25 @@ def screenshot(browser)
60
47
duration = browser . find_element ( :css , 'p#duration' ) . find_element ( :css , 'strong' ) . text
61
48
62
49
puts "\r #{ totals } in #{ duration } "
63
- puts
64
50
65
51
if totals =~ / 0 failures/
66
52
exit 0
67
53
end
68
-
69
- puts screenshot ( browser )
70
54
rescue Selenium ::WebDriver ::Error ::NoSuchElementError
55
+ puts "\r No such element? You dun goof'd"
56
+ puts
71
57
puts browser . page_source
72
58
rescue Selenium ::WebDriver ::Error ::TimeOutError
73
- puts "\r Timeout, have fun: #{ screenshot ( browser ) } "
74
-
75
- exit 0
59
+ puts "\r Timeout, have fun."
76
60
ensure
61
+ browser . capture_entire_page_screenshot ( 'screenshot.png' )
62
+ response = RestClient . post ( 'https://api.imgur.com/3/upload' ,
63
+ { image : File . open ( 'screenshot.png' ) } ,
64
+ { 'Authorization' => 'Client-ID 1979876fe2a097e' } )
65
+
66
+ puts
67
+ puts JSON . parse ( response . to_str ) [ 'data' ] [ 'link' ]
68
+
77
69
browser . quit
78
70
end
79
71
0 commit comments