From 7c8373106f62b9f25d404beb6930ee1c56bd088f Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Thu, 11 Jan 2018 18:24:25 +0100 Subject: [PATCH] Catch timeout errors in screenshot scripts Bug: T184724 Change-Id: Ifbc03b1291c291dcfc862487766e3786f9bd437c --- Gruntfile.js | 8 ++++++-- build/screenshots.js | 28 +++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index f25fad17fb..9436bfb4f5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -11,7 +11,9 @@ module.exports = function ( grunt ) { var modules = grunt.file.readJSON( 'lib/ve/build/modules.json' ), screenshotOptions = { reporter: 'spec', - timeout: 40000, + // TODO: Work out how to catch this timeout and continue. + // For now just make it very long. + timeout: 5 * 60 * 1000, require: [ function () { // eslint-disable-next-line no-undef, no-implicit-globals @@ -21,7 +23,9 @@ module.exports = function ( grunt ) { }, screenshotOptionsAll = { reporter: 'spec', - timeout: 40000, + // TODO: Work out how to catch this timeout and continue. + // For now just make it very long. + timeout: 5 * 60 * 1000, require: [ function () { // eslint-disable-next-line no-undef, no-implicit-globals diff --git a/build/screenshots.js b/build/screenshots.js index d163a43f8e..f7d6feefb5 100644 --- a/build/screenshots.js +++ b/build/screenshots.js @@ -1,5 +1,7 @@ /* global seleniumUtils */ +/* eslint-disable no-console */ + ( function () { 'use strict'; var accessKey = process.env.SAUCE_ONDEMAND_ACCESS_KEY, @@ -7,7 +9,8 @@ fs = require( 'fs' ), Jimp = require( 'jimp' ), username = process.env.SAUCE_ONDEMAND_USERNAME, - webdriver = require( 'selenium-webdriver' ); + webdriver = require( 'selenium-webdriver' ), + TIMEOUT = 40 * 1000; function createScreenshotEnvironment( test, beforeEach ) { var clientSize, driver; @@ -29,7 +32,7 @@ driver = new chrome.Driver(); } - driver.manage().timeouts().setScriptTimeout( 40000 ); + driver.manage().timeouts().setScriptTimeout( TIMEOUT ); driver.manage().window().setSize( 1200, 1000 ); driver.get( 'https://en.wikipedia.org/wiki/Help:Sample_page?veaction=edit&uselang=' + lang ); @@ -132,10 +135,22 @@ } ).then( function ( cs ) { clientSize = cs; + }, function ( e ) { + // Log error (timeout) + console.error( e.message ); } ) ); if ( beforeEach ) { - driver.wait( driver.executeAsyncScript( beforeEach ) ); + driver.manage().timeouts().setScriptTimeout( TIMEOUT ); + driver.wait( + driver.executeAsyncScript( beforeEach ).then( + function () {}, + function ( e ) { + // Log error (timeout) + console.error( e.message ); + } + ) + ); } } ); @@ -165,6 +180,7 @@ function runScreenshotTest( name, lang, clientScript, padding ) { var filename = './screenshots/' + name + '-' + lang + '.png'; + driver.manage().timeouts().setScriptTimeout( TIMEOUT ); driver.wait( driver.executeAsyncScript( clientScript ).then( function ( rect ) { return driver.takeScreenshot().then( function ( base64Image ) { @@ -176,8 +192,10 @@ fs.writeFile( filename, base64Image, 'base64' ); } } ); - } ), - 40000 + }, function ( e ) { + // Log error (timeout) + console.error( e ); + } ) ); }