'use strict';
/* globals jasmine */

var path = require('path');

var failFast = require('protractor-fail-fast');


// var FsCleaner = require('./lib/fs-cleaner');

var config = {
	plugins: [],
	seleniumAddress: process.env.SELENIUM_ADDRESS,
	// specs: require('./specList.js'),
	specs: require('./specList').getAll(),
	framework: 'jasmine2',
	// params: {
	// 	screenshotsBasePath: path.resolve(__dirname, './screenshots')
	// },
	capabilities: {
		browserName: 'chrome',
		'chromeOptions': {
			// Get rid of --ignore-certificate yellow warning
			args: ['--no-sandbox', '--test-type=browser'],
			// Set download path and avoid prompting for download even though
			// this is already the default on Chrome but for completeness
			prefs: {
				'download': {
					'prompt_for_download': false,
					'default_directory': path.resolve(__dirname, './downloads/'),
				},
			},
		}
	},
	// in case it throws  Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds. 
	allScriptsTimeout: 300 * 1000,
	getPageTimeout: 300 * 1000,
	jasmineNodeOpts: {
		defaultTimeoutInterval: 300 * 1000
	},
	onPrepare: function() {

		if (process.env.FAIL_FAST === 'true'){
			jasmine.getEnv().addReporter(failFast.init());	
		}

		

		var SpecReporter = require('jasmine-spec-reporter');
		// add jasmine spec reporter
		jasmine.getEnv().addReporter(new SpecReporter({
			displayStacktrace: true
		}));
		// FsCleaner.cleanScreenshotsFolder();
		// FsCleaner.cleanDownloadFolder();
	},
	afterLaunch: function() {
		if (process.env.FAIL_FAST === 'true'){
			failFast.clean(); // Cleans up the "fail file" (see below) 
		}
	}

};

if (process.env.FAIL_FAST === 'true') {
	config.plugins.push({
		package: 'protractor-fail-fast'
	});
}

exports.config = config;