|
3 | 3 | require 'net/https'
|
4 | 4 | require 'json'
|
5 | 5 |
|
6 |
| -trials = 0 |
| 6 | +loop do |
| 7 | + uri = URI.parse("https://www.browserstack.com/automate/plan.json") |
| 8 | + agent = Net::HTTP.new(uri.host, uri.port) |
| 9 | + agent.use_ssl = true |
| 10 | + request = Net::HTTP::Get.new(uri.request_uri) |
| 11 | + request.basic_auth(ENV['BS_USERNAME'], ENV['BS_AUTHKEY']) |
7 | 12 |
|
8 |
| -begin |
9 |
| - loop do |
10 |
| - uri = URI.parse("https://www.browserstack.com/automate/plan.json") |
11 |
| - agent = Net::HTTP.new(uri.host, uri.port) |
12 |
| - agent.use_ssl = true |
13 |
| - request = Net::HTTP::Get.new(uri.request_uri) |
14 |
| - request.basic_auth(ENV['BS_USERNAME'], ENV['BS_AUTHKEY']) |
15 |
| - |
16 |
| - state = JSON.parse(agent.request(request).body) |
17 |
| - |
18 |
| - if state["parallel_sessions_running"] < state["parallel_sessions_max_allowed"] |
19 |
| - break |
20 |
| - end |
| 13 | + state = JSON.parse(agent.request(request).body) |
21 | 14 |
|
22 |
| - print '.' |
23 |
| - sleep 30 |
| 15 | + if state["parallel_sessions_running"] < state["parallel_sessions_max_allowed"] |
| 16 | + break |
24 | 17 | end
|
25 | 18 |
|
26 |
| - puts "\rRunning specs..." |
27 |
| - puts |
| 19 | + print '.' |
| 20 | + sleep 30 |
| 21 | +end |
| 22 | + |
| 23 | +puts "\rRunning specs..." |
| 24 | +puts |
28 | 25 |
|
29 |
| - url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub.browserstack.com/wd/hub" |
30 |
| - cap = Selenium::WebDriver::Remote::Capabilities.new |
| 26 | +url = "http://#{ENV['BS_USERNAME']}:#{ENV['BS_AUTHKEY']}@hub.browserstack.com/wd/hub" |
| 27 | +cap = Selenium::WebDriver::Remote::Capabilities.new |
31 | 28 |
|
32 |
| - cap['platform'] = ENV['SELENIUM_PLATFORM'] || 'ANY' |
33 |
| - cap['browser'] = ENV['SELENIUM_BROWSER'] || 'chrome' |
34 |
| - cap['browser_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION'] |
| 29 | +cap['platform'] = ENV['SELENIUM_PLATFORM'] || 'ANY' |
| 30 | +cap['browser'] = ENV['SELENIUM_BROWSER'] || 'chrome' |
| 31 | +cap['browser_version'] = ENV['SELENIUM_VERSION'] if ENV['SELENIUM_VERSION'] |
35 | 32 |
|
36 |
| - cap['browserstack.tunnel'] = 'true' |
37 |
| - cap['browserstack.debug'] = 'false' |
| 33 | +cap['browserstack.tunnel'] = 'true' |
| 34 | +cap['browserstack.debug'] = 'false' |
38 | 35 |
|
39 |
| - browser = Selenium::WebDriver.for(:remote, url: url, desired_capabilities: cap) |
40 |
| - browser.navigate.to('http://localhost:9292') |
| 36 | +browser = Selenium::WebDriver.for(:remote, url: url, desired_capabilities: cap) |
| 37 | +browser.navigate.to('http://localhost:9292') |
41 | 38 |
|
42 |
| - begin |
43 |
| - Selenium::WebDriver::Wait.new(timeout: 540, interval: 5) \ |
44 |
| - .until { not browser.find_element(:css, 'p#totals').text.strip.empty? } |
| 39 | +begin |
| 40 | + Selenium::WebDriver::Wait.new(timeout: 540, interval: 5) \ |
| 41 | + .until { not browser.find_element(:css, 'p#totals').text.strip.empty? } |
45 | 42 |
|
46 |
| - totals = browser.find_element(:css, 'p#totals').text |
47 |
| - duration = browser.find_element(:css, 'p#duration').find_element(:css, 'strong').text |
| 43 | + totals = browser.find_element(:css, 'p#totals').text |
| 44 | + duration = browser.find_element(:css, 'p#duration').find_element(:css, 'strong').text |
48 | 45 |
|
49 |
| - puts "#{totals} in #{duration}" |
50 |
| - puts |
| 46 | + puts "#{totals} in #{duration}" |
| 47 | + puts |
51 | 48 |
|
52 |
| - if totals =~ / 0 failures/ |
53 |
| - exit 0 |
54 |
| - end |
| 49 | + if totals =~ / 0 failures/ |
| 50 | + exit 0 |
| 51 | + end |
55 | 52 |
|
56 |
| - browser.find_elements(:css, '.example_group').slice_before {|x| |
57 |
| - begin |
58 |
| - x.find_element(:css, 'dd') |
| 53 | + browser.find_elements(:css, '.example_group').slice_before {|x| |
| 54 | + begin |
| 55 | + x.find_element(:css, 'dd') |
59 | 56 |
|
60 |
| - false |
61 |
| - rescue Exception |
62 |
| - true |
63 |
| - end |
64 |
| - }.each {|header, *specs| |
65 |
| - next unless specs.any? { |x| x.find_element(:css, '.failed') rescue false } |
| 57 | + false |
| 58 | + rescue Exception |
| 59 | + true |
| 60 | + end |
| 61 | + }.each {|header, *specs| |
| 62 | + next unless specs.any? { |x| x.find_element(:css, '.failed') rescue false } |
66 | 63 |
|
67 |
| - namespace = header.find_element(:css, 'dt').text |
| 64 | + namespace = header.find_element(:css, 'dt').text |
68 | 65 |
|
69 |
| - specs.each {|group| |
70 |
| - next unless group.find_element(:css, '.failed') rescue false |
| 66 | + specs.each {|group| |
| 67 | + next unless group.find_element(:css, '.failed') rescue false |
71 | 68 |
|
72 |
| - method = group.find_element(:css, 'dt').text |
| 69 | + method = group.find_element(:css, 'dt').text |
73 | 70 |
|
74 |
| - group.find_elements(:css, 'dd.example.failed').each {|el| |
75 |
| - puts "#{namespace}#{method}" |
76 |
| - puts " #{el.find_element(:css, '.failed_spec_name').text}" |
77 |
| - puts |
78 |
| - puts el.find_element(:css, '.failure').text |
79 |
| - puts |
80 |
| - } |
| 71 | + group.find_elements(:css, 'dd.example.failed').each {|el| |
| 72 | + puts "#{namespace}#{method}" |
| 73 | + puts " #{el.find_element(:css, '.failed_spec_name').text}" |
| 74 | + puts |
| 75 | + puts el.find_element(:css, '.failure').text |
| 76 | + puts |
81 | 77 | }
|
82 | 78 | }
|
83 |
| - rescue Selenium::WebDriver::Error::NoSuchElementError |
84 |
| - puts browser.page_source |
85 |
| - ensure |
86 |
| - browser.quit |
87 |
| - end |
| 79 | + } |
| 80 | +rescue Selenium::WebDriver::Error::NoSuchElementError |
| 81 | + puts browser.page_source |
88 | 82 | rescue Selenium::WebDriver::Error::TimeOutError
|
89 |
| - retry unless (trials += 1) >= 4 |
| 83 | + puts "Timeout, have fun." |
| 84 | + |
| 85 | + exit 0 |
| 86 | +ensure |
| 87 | + browser.quit |
90 | 88 | end
|
91 | 89 |
|
92 | 90 | exit 1
|
0 commit comments