1414 * limitations under the License.
1515 */
1616
17- const { Builder, By , until } = require ( 'selenium-webdriver' ) ;
17+ const { Builder } = require ( 'selenium-webdriver' ) ;
1818const { expect } = require ( 'chai' ) ;
1919const chrome = require ( 'selenium-webdriver/chrome' ) ;
2020const fs = require ( 'fs' ) ;
@@ -35,7 +35,12 @@ const logger = winston.createLogger({
3535} ) ;
3636
3737describe ( 'Selenium chromedriver' , function ( ) {
38+ // The deafult timeout of 2s is not enough for selenium tests.
39+ this . timeout ( 60 * 1000 ) ;
40+
3841 let driver ;
42+ let chromedriverBuild ;
43+ let chromeBuild ;
3944
4045 before ( async function ( ) {
4146 // The chrome and chromedriver installation can take some time. Give 5
@@ -58,13 +63,13 @@ describe('Selenium chromedriver', function () {
5863
5964 logger . debug ( `Chrome version: ${ BROWSER_VERSION } ` ) ;
6065
61- const chromeBuild = await install ( {
66+ chromeBuild = await install ( {
6267 browser : Browser . CHROME ,
6368 buildId : BROWSER_VERSION ,
6469 cacheDir : cacheDir ,
6570 } ) ;
6671
67- const chromedriverBuild = await install ( {
72+ chromedriverBuild = await install ( {
6873 browser : Browser . CHROMEDRIVER ,
6974 buildId : BROWSER_VERSION ,
7075 cacheDir : cacheDir ,
@@ -74,23 +79,27 @@ describe('Selenium chromedriver', function () {
7479 logger . debug (
7580 `ChromeDriver installed at: ${ chromedriverBuild . executablePath } ` ,
7681 ) ;
82+ } ) ;
83+
84+ beforeEach ( async function ( ) {
85+ logger . debug ( `Launching Chrome at ${ chromeBuild . executablePath } ` ) ;
7786
7887 const options = new chrome . Options ( ) ;
7988 options . addArguments ( '--headless' ) ;
8089 options . addArguments ( '--no-sandbox' ) ;
8190 options . setBinaryPath ( chromeBuild . executablePath ) ;
8291
83- const logDir = path . join ( __dirname , 'logs' ) ;
84- if ( ! fs . existsSync ( logDir ) ) {
85- fs . mkdirSync ( logDir ) ;
92+ const chromedriverLogDir = path . join ( __dirname , 'logs' ) ;
93+ if ( ! fs . existsSync ( chromedriverLogDir ) ) {
94+ fs . mkdirSync ( chromedriverLogDir ) ;
8695 }
87- const logFile = path . join (
88- logDir ,
96+ const chromedriverLogFile = path . join (
97+ chromedriverLogDir ,
8998 `chromedriver-${ new Date ( ) . toISOString ( ) } .log` ,
9099 ) ;
91100
92101 const service = new chrome . ServiceBuilder ( chromedriverBuild . executablePath )
93- . loggingTo ( logFile )
102+ . loggingTo ( chromedriverLogFile )
94103 . enableVerboseLogging ( ) ;
95104
96105 driver = await new Builder ( )
@@ -100,7 +109,7 @@ describe('Selenium chromedriver', function () {
100109 . build ( ) ;
101110 } ) ;
102111
103- after ( async function ( ) {
112+ afterEach ( async function ( ) {
104113 await driver . quit ( ) ;
105114 } ) ;
106115
0 commit comments