From 430439c2454e37717517b607ecfe3ffdb33d0bc9 Mon Sep 17 00:00:00 2001 From: hmdne <54514036+hmdne@users.noreply.github.com> Date: Fri, 23 Jul 2021 12:46:36 +0200 Subject: [PATCH] Further work on the CI. Remove the warning, note the user agent and make a screenshot of the entire page. (opal/opal-browser#26). Co-authored-by: Elia Schito --- spec/runner.rb | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/spec/runner.rb b/spec/runner.rb index 6dd3065..71c32f5 100755 --- a/spec/runner.rb +++ b/spec/runner.rb @@ -8,22 +8,22 @@ browser, options = case ENV['BROWSER'] when "chrome" - opts = Selenium::WebDriver::Chrome::Options.new(args: ['--no-sandbox', '--headless']) - [:chrome, options: opts] + opts = Selenium::WebDriver::Chrome::Options.new(args: ['--headless', '--no-sandbox']) + [:chrome, opts] when "gecko" opts = Selenium::WebDriver::Firefox::Options.new(args: ['--headless']) - [:firefox, options: opts] + [:firefox, opts] when "safari" - opts = Selenium::WebDriver::Safari::Options.new(args: ['--headless']) - [:safari, {}] + opts = Selenium::WebDriver::Safari::Options.new() + [:safari, opts] when "edge" opts = Selenium::WebDriver::Edge::Options.new(args: ['--headless']) - [:edge, {}] + [:edge, opts] else raise "Wrong web browser provided in BROWSER. Acceptable values: chrome, gecko, safari, edge" end -browser = Selenium::WebDriver.for(browser, options, **{}) +browser = Selenium::WebDriver.for(browser, capabilities: options) browser.navigate.to('http://localhost:9292') # if we don't quit the browser it will stall @@ -31,6 +31,8 @@ browser.quit } +puts "Browser: " + browser.execute_script("return window.navigator.userAgent") + # the title is a good way to know if anything went wrong while fetching the # page Selenium::WebDriver::Wait.new(timeout: 30, interval: 5).until { @@ -54,7 +56,7 @@ puts "\r#{element.text}" exit 1 end -rescue Selenium::WebDriver::Error::TimeOutError; end +rescue Selenium::WebDriver::Error::TimeoutError; end print "\rRunning specs..." @@ -84,14 +86,19 @@ ensure # take a screenshot and upload it to imgur begin - browser.save_screenshot('screenshot.png') - response = RestClient.post('https://api.imgur.com/3/upload', - { image: File.open('screenshot.png') }, - { 'Authorization' => 'Client-ID 1979876fe2a097e' }) + upload = lambda do |filepath| + response = RestClient.post('https://api.imgur.com/3/upload', + { image: File.open(filepath) }, + { 'Authorization' => 'Client-ID 1979876fe2a097e' }) - print " (" - print JSON.parse(response.to_str)['data']['link'] - puts ")" + JSON.parse(response.to_str)['data']['link'] + end + + w, h = browser.execute_script("return [document.body.clientWidth, document.body.clientHeight];") + browser.manage.window.resize_to(w, h) + browser.save_screenshot('screenshot.png') + screenshot_url = upload.('screenshot.png') + puts " (#{screenshot_url})" rescue Exception puts end