selenium-drivers
Advanced tools
Comparing version 2.0.3 to 2.1.0
var fs = require('fs'); | ||
var log = require('./log'); | ||
var path = require('path'); | ||
@@ -6,84 +7,78 @@ var request = require('request'); | ||
module.exports = { | ||
downloadDriverToDirectory : downloadDriverToDirectory, | ||
checkLastDriverVersion : checkLastDriverVersion, | ||
downloadDriverToDirectory: downloadDriverToDirectory, | ||
checkLastDriverVersion: checkLastDriverVersion, | ||
}; | ||
function downloadDriverToDirectory(driver, downloadDirectory) { | ||
function downloadDriverToDirectory(driver) { | ||
console.log('downloading: ' + driver.url); | ||
console.log('... to localPath: ' + downloadDirectory); | ||
log.infoIf(!driver.opts.silent, 'Downloading : ' + driver.url); | ||
log.infoIf(!driver.opts.silent, 'Download target : ' + driver.archivePath); | ||
var activeDownloadRequest = request(driver.url); | ||
var activeDownloadRequest = request(driver.url); | ||
var osSpecificDownloadPath = getOsSpecificPath(driver, downloadDirectory); | ||
activeDownloadRequest | ||
.pipe(fs.createWriteStream(driver.archivePath)); | ||
activeDownloadRequest | ||
.pipe(fs.createWriteStream(osSpecificDownloadPath)); | ||
return activeDownloadRequest; | ||
return activeDownloadRequest; | ||
} | ||
function checkLastDriverVersion(driver) { | ||
if(driver.name === 'chrome') { | ||
return _checkLastChromeDriverVersion(); | ||
} | ||
else if(driver.name === 'firefox') { | ||
return _checkLastFirefoxDriverVersion(); | ||
} | ||
else if(driver.name === 'internet explorer') { | ||
return _checkLastIEVersion(); | ||
} | ||
else { | ||
throw new Error('unknown driver type!'); | ||
} | ||
if (driver.name === 'chrome') { | ||
return _checkLastChromeDriverVersion(); | ||
} | ||
else if (driver.name === 'firefox') { | ||
return _checkLastFirefoxDriverVersion(); | ||
} | ||
else if (driver.name === 'internet explorer') { | ||
return _checkLastIEVersion(); | ||
} | ||
else { | ||
throw new Error('unknown driver type!'); | ||
} | ||
} | ||
function _checkLastChromeDriverVersion() { | ||
var url = 'http://chromedriver.storage.googleapis.com/LATEST_RELEASE'; | ||
return new Promise(function (resolve, reject) { | ||
request(url, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
var version = body.replace('\n', ''); | ||
resolve(version); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
var url = 'http://chromedriver.storage.googleapis.com/LATEST_RELEASE'; | ||
return new Promise(function (resolve, reject) { | ||
request(url, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
var version = body.replace('\n', ''); | ||
resolve(version); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
}); | ||
} | ||
function _checkLastIEVersion() { | ||
var url = 'http://selenium-release.storage.googleapis.com/?delimiter=/&prefix='; | ||
return new Promise(function (resolve, reject) { | ||
request(url, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
// TODO: parse DOM body and get version | ||
resolve('3.0'); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
var url = 'http://selenium-release.storage.googleapis.com/?delimiter=/&prefix='; | ||
return new Promise(function (resolve, reject) { | ||
request(url, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
// TODO: parse DOM body and get version | ||
resolve('3.0'); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
}); | ||
} | ||
function _checkLastFirefoxDriverVersion() { | ||
var url = 'https://github.com/mozilla/geckodriver/releases/latest'; | ||
return new Promise(function (resolve, reject) { | ||
request({json: true, url: url}, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
resolve(body.tag_name); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
var url = 'https://github.com/mozilla/geckodriver/releases/latest'; | ||
return new Promise(function (resolve, reject) { | ||
request({json: true, url: url}, function (error, response, body) { | ||
if (!error && response.statusCode == 200) { | ||
resolve(body.tag_name); | ||
} | ||
else { | ||
reject(); | ||
} | ||
}); | ||
}); | ||
} | ||
function getOsSpecificPath(driver, downloadDirectory) { | ||
return require('path').join(__dirname, downloadDirectory, driver.archiveFileName); | ||
} |
@@ -6,38 +6,38 @@ var path = require('path'); | ||
const OPERATING_SYSTEMS = { | ||
'linux32': { | ||
name: 'linux32', | ||
chromeAlias: 'linux32', | ||
supported: true | ||
}, | ||
'linux64': { | ||
name: 'linux64', | ||
chromeAlias: 'linux64', | ||
supported: true | ||
}, | ||
'mac32': { | ||
name: 'mac32', | ||
firefoxAlias: 'macos', | ||
chromeAlias: 'mac32', | ||
supported: false | ||
}, | ||
'mac64': { | ||
name: 'mac64', | ||
firefoxAlias: 'macos', | ||
chromeAlias: 'mac64', | ||
supported: true | ||
}, | ||
'win32': { | ||
name: 'win32', | ||
alias: 'Win32', | ||
firefoxAlias: 'win32', | ||
chromeAlias: 'win32', | ||
supported: true | ||
}, | ||
'win64': { | ||
name: 'win64', | ||
alias: 'Win64', | ||
firefoxAlias: 'win64', | ||
chromeAlias: 'win32', | ||
supported: true | ||
} | ||
'linux32': { | ||
name: 'linux32', | ||
chromeAlias: 'linux32', | ||
supported: true | ||
}, | ||
'linux64': { | ||
name: 'linux64', | ||
chromeAlias: 'linux64', | ||
supported: true | ||
}, | ||
'mac32': { | ||
name: 'mac32', | ||
firefoxAlias: 'macos', | ||
chromeAlias: 'mac32', | ||
supported: false | ||
}, | ||
'mac64': { | ||
name: 'mac64', | ||
firefoxAlias: 'macos', | ||
chromeAlias: 'mac64', | ||
supported: true | ||
}, | ||
'win32': { | ||
name: 'win32', | ||
alias: 'Win32', | ||
firefoxAlias: 'win32', | ||
chromeAlias: 'win32', | ||
supported: true | ||
}, | ||
'win64': { | ||
name: 'win64', | ||
alias: 'Win64', | ||
firefoxAlias: 'win64', | ||
chromeAlias: 'win32', | ||
supported: true | ||
} | ||
}; | ||
@@ -47,135 +47,134 @@ | ||
constructor(name) { | ||
this.supported = ['safari', 'chrome', 'internet explorer', 'firefox']; | ||
this.name = name; | ||
this.os = Driver._getOS(); | ||
this.downloadPath = path.join(__dirname, '../downloads'); | ||
this.binaryFileName = this._getBinaryFileName(name); | ||
constructor(name, opts) { | ||
this.name = name; | ||
this.opts = opts; | ||
this.supported = ['safari', 'chrome', 'internet explorer', 'firefox']; | ||
this.os = Driver._getOS(); | ||
this.downloadPath = path.join(__dirname, '../downloads'); | ||
this.binaryFileName = this._getBinaryFileName(name); | ||
this.version = undefined; | ||
this.url = undefined; | ||
this.archiveFileName = undefined; | ||
this.archivePath = undefined; | ||
} | ||
this.version = undefined; | ||
this.url = undefined; | ||
this.archiveFileName = undefined; | ||
this.archivePath = undefined; | ||
} | ||
setFileNamesFromVersion(version) { | ||
this.version = version; | ||
this.archiveFileName = this._getArchiveFileName(this.name, version); | ||
this.url = this._getUrl(version, this.archiveFileName); | ||
this.archivePath = this.getArchivePath(this.archiveFileName); | ||
} | ||
setFileNamesFromVersion(version) { | ||
this.version = version; | ||
this.archiveFileName = this._getArchiveFileName(this.name, version); | ||
this.url = this._getUrl(version, this.archiveFileName); | ||
this.archivePath = this.getArchivePath(this.archiveFileName); | ||
} | ||
extract() { | ||
return extract.extract(this).then(function (archiveEntry) { | ||
console.log('Extracted new file: ' + archiveEntry); | ||
}); | ||
extract() { | ||
return extract.extract(this); | ||
} | ||
isUpToDate() { | ||
var versionedArchiveExists = fs.existsSync(this.archivePath); | ||
var binaryExists = fs.existsSync(this.getBinaryPath()); | ||
return versionedArchiveExists && binaryExists; | ||
} | ||
getArchivePath(archiveFileName) { | ||
return path.join(this.downloadPath, archiveFileName); | ||
} | ||
getBinaryPath() { | ||
return path.join(this.downloadPath, this.binaryFileName) | ||
} | ||
static _getOS() { | ||
if (process.platform === 'linux') { | ||
if (process.arch === 'x64') { | ||
return OPERATING_SYSTEMS.linux64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.linux32; | ||
} | ||
} | ||
else if (process.platform === 'darwin') { | ||
if (process.arch === 'x64') { | ||
return OPERATING_SYSTEMS.mac64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.mac32; | ||
} | ||
} | ||
else if (process.platform === 'win32') { | ||
isUpToDate() { | ||
var versionedArchiveExists = fs.existsSync(this.archivePath); | ||
var binaryExists = fs.existsSync(this.getBinaryPath()); | ||
return versionedArchiveExists && binaryExists; | ||
function isOSWin64() { | ||
return process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); | ||
} | ||
if (isOSWin64()) { | ||
return OPERATING_SYSTEMS.win64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.win32; | ||
} | ||
} | ||
getArchivePath(archiveFileName) { | ||
return path.join(this.downloadPath, archiveFileName); | ||
else { | ||
throw new Error('Operating system was not recognized!'); | ||
} | ||
getBinaryPath() { | ||
return path.join(this.downloadPath, this.binaryFileName) | ||
} | ||
} | ||
static _getOS() { | ||
if (process.platform === 'linux') { | ||
if (process.arch === 'x64') { | ||
return OPERATING_SYSTEMS.linux64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.linux32; | ||
} | ||
} | ||
else if (process.platform === 'darwin') { | ||
if (process.arch === 'x64') { | ||
return OPERATING_SYSTEMS.mac64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.mac32; | ||
} | ||
} | ||
else if (process.platform === 'win32') { | ||
function isOSWin64() { | ||
return process.arch === 'x64' || process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); | ||
} | ||
// TODO: export below to sub-classes! | ||
if(isOSWin64()) { | ||
return OPERATING_SYSTEMS.win64; | ||
} | ||
else { | ||
return OPERATING_SYSTEMS.win32; | ||
} | ||
} | ||
else { | ||
throw new Error('Operating system was not recognized!'); | ||
} | ||
_getBinaryFileName(driverName) { | ||
var fileExtension = ''; | ||
if (process.platform === 'win32') { // TODO : export OS to a Class with isWindows() method | ||
fileExtension = '.exe'; | ||
} | ||
// TODO: export below to sub-classes! | ||
_getBinaryFileName(driverName) { | ||
var fileExtension = ''; | ||
if(process.platform === 'win32' ) { // TODO : export OS to a Class with isWindows() method | ||
fileExtension = '.exe'; | ||
} | ||
if (driverName === 'chrome') { | ||
return 'chromedriver' + fileExtension; | ||
} | ||
else if (driverName === 'firefox') { | ||
return 'geckodriver' + fileExtension; | ||
} | ||
else if (driverName === 'internet explorer') { | ||
return 'IEDriverServer' + fileExtension; | ||
} | ||
} | ||
if (driverName === 'chrome') { | ||
return 'chromedriver' + fileExtension; | ||
} | ||
else if (driverName === 'firefox') { | ||
return 'geckodriver' + fileExtension; | ||
} | ||
else if (driverName === 'internet explorer') { | ||
return 'IEDriverServer' + fileExtension; | ||
} | ||
_getArchiveFileName(driverName, version) { | ||
if (driverName === 'chrome') { | ||
return 'chromedriver_' + this.os.chromeAlias + '.zip'; | ||
} | ||
if (driverName === 'firefox') { | ||
if (this.os === OPERATING_SYSTEMS.win32 || this.os === OPERATING_SYSTEMS.win64) { | ||
return 'geckodriver-' + version + '-' + this.os.firefoxAlias + '.zip'; | ||
} | ||
else { | ||
return 'geckodriver-' + version + '-' + this.os.firefoxAlias + '.tar.gz'; | ||
} | ||
} | ||
if (driverName === 'internet explorer') { | ||
if (this.os === OPERATING_SYSTEMS.win32) { | ||
return 'IEDriverServer_' + this.os.alias + '_' + version + '.0.zip'; | ||
} | ||
else if (this.os === OPERATING_SYSTEMS.win64) { | ||
return 'IEDriverServer_x64_' + version + '.0.zip'; | ||
} | ||
} | ||
} | ||
_getArchiveFileName(driverName, version) { | ||
if (driverName === 'chrome') { | ||
return 'chromedriver_' + this.os.chromeAlias + '.zip'; | ||
} | ||
if (driverName === 'firefox') { | ||
if(this.os === OPERATING_SYSTEMS.win32 || this.os === OPERATING_SYSTEMS.win64) { | ||
return 'geckodriver-'+ version + '-' + this.os.firefoxAlias + '.zip'; | ||
} | ||
else { | ||
return 'geckodriver-'+ version + '-' + this.os.firefoxAlias + '.tar.gz'; | ||
} | ||
} | ||
if (driverName === 'internet explorer') { | ||
if(this.os === OPERATING_SYSTEMS.win32) { | ||
return 'IEDriverServer_' + this.os.alias + '_' + version + '.0.zip'; | ||
} | ||
else if(this.os === OPERATING_SYSTEMS.win64) { | ||
return 'IEDriverServer_x64_' + version + '.0.zip'; | ||
} | ||
} | ||
_getUrl(version, archiveFileName) { | ||
if (this.name === 'chrome') { | ||
var urlBase = 'https://chromedriver.storage.googleapis.com/'; | ||
return urlBase + version + '/' + archiveFileName; | ||
} | ||
else if (this.name === 'firefox') { | ||
var baseUrl = 'https://github.com/mozilla/geckodriver/releases/download/'; | ||
return baseUrl + version + '/' + archiveFileName; | ||
} | ||
_getUrl(version, archiveFileName) { | ||
if (this.name === 'chrome') { | ||
var urlBase = 'https://chromedriver.storage.googleapis.com/'; | ||
return urlBase + version + '/' + archiveFileName; | ||
} | ||
else if (this.name === 'firefox') { | ||
var baseUrl = 'https://github.com/mozilla/geckodriver/releases/download/'; | ||
return baseUrl + version + '/' + archiveFileName; | ||
} | ||
//http://selenium-release.storage.googleapis.com/3.0/IEDriverServer_Win32_3.0.0.zip | ||
else if (this.name === 'internet explorer') { | ||
var baseUrl = 'http://selenium-release.storage.googleapis.com/'; | ||
return baseUrl + version + '/' + archiveFileName; | ||
} | ||
//http://selenium-release.storage.googleapis.com/3.0/IEDriverServer_Win32_3.0.0.zip | ||
else if (this.name === 'internet explorer') { | ||
var baseUrl = 'http://selenium-release.storage.googleapis.com/'; | ||
return baseUrl + version + '/' + archiveFileName; | ||
} | ||
} | ||
}; | ||
@@ -182,0 +181,0 @@ |
var path = require('path'); | ||
module.exports = { | ||
run : run | ||
run: run | ||
}; | ||
function run(driver) { | ||
console.log('running browser driver...'); | ||
var binaryFilePath = path.join(driver.downloadPath, driver.binaryFileName); | ||
exports.defaultInstance = require('child_process').execFile(binaryFilePath); | ||
console.log('running browser driver...'); | ||
var binaryFilePath = path.join(driver.downloadPath, driver.binaryFileName); | ||
exports.defaultInstance = require('child_process').execFile(binaryFilePath); | ||
} |
@@ -0,5 +1,6 @@ | ||
var log = require('./log'); | ||
var path = require('path'); | ||
module.exports = { | ||
extract: extract | ||
extract: extract | ||
}; | ||
@@ -9,26 +10,27 @@ | ||
return new Promise(function (resolve, reject) { | ||
if (driver.archiveFileName.indexOf('zip') >= 0) { | ||
var entry = unzip(driver); | ||
resolve(entry); | ||
} | ||
if (driver.archiveFileName.indexOf('tar.gz') >= 0) { | ||
resolve(untar(driver)); | ||
} | ||
}); | ||
log.infoIf(!driver.opts.silent, 'Extracting archive contents'); | ||
return new Promise(function (resolve, reject) { | ||
if (driver.archiveFileName.indexOf('zip') >= 0) { | ||
var entry = unzip(driver); | ||
resolve(entry); | ||
} | ||
if (driver.archiveFileName.indexOf('tar.gz') >= 0) { | ||
resolve(untar(driver)); | ||
} | ||
}); | ||
} | ||
function unzip(driver) { | ||
var AdmZip = require('adm-zip'); | ||
console.log('Extracting archive contents'); | ||
var zip = new AdmZip(driver.archivePath); | ||
zip.extractAllTo(driver.downloadPath, true); | ||
var AdmZip = require('adm-zip'); | ||
var zip = new AdmZip(driver.archivePath); | ||
zip.extractAllTo(driver.downloadPath, true); | ||
var entries = zip.getEntries(); | ||
return entries[0].entryName; | ||
var entries = zip.getEntries(); | ||
var entryName = entries[0].entryName; | ||
log.infoIf(!driver.opts.silent, 'Extracted new file: ' + entryName); | ||
return entryName; | ||
} | ||
@@ -38,27 +40,27 @@ | ||
function untar(driver) { | ||
var targz = require('tar.gz'); | ||
var fs = require('fs'); | ||
var targz = require('tar.gz'); | ||
var fs = require('fs'); | ||
var parse = targz().createParseStream(); | ||
var parse = targz().createParseStream(); | ||
var entryName; // affected by temporal dependency! | ||
parse.on('entry', function (entry) { | ||
entryName = entry.path; | ||
}); | ||
var entryName; // affected by temporal dependency! | ||
parse.on('entry', function (entry) { | ||
entryName = entry.path; | ||
}); | ||
var readStream = fs.createReadStream(driver.archivePath); | ||
readStream.pipe(parse); | ||
var readStream = fs.createReadStream(driver.archivePath); | ||
readStream.pipe(parse); | ||
return new Promise(function (resolve) { | ||
return new Promise(function (resolve) { | ||
var extract = targz().extract(readStream, driver.downloadPath); | ||
extract.then(function () { | ||
setTimeout(function () { | ||
resolve(entryName); | ||
}, 100); | ||
}); | ||
var extract = targz().extract(readStream, driver.downloadPath); | ||
extract.then(function () { | ||
setTimeout(function () { | ||
log.infoIf(!driver.opts.silent, 'Extracted new file: ' + entryName); | ||
resolve(entryName); | ||
}, 100); | ||
}); | ||
}); | ||
} | ||
module.exports = { | ||
infoIf: function (condition, message) { | ||
if(condition) { | ||
if (condition) { | ||
console.info(message); | ||
@@ -5,0 +5,0 @@ } |
var path = require('path'); | ||
module.exports = { | ||
addPathToEnvironment : addPathToEnvironment | ||
addPathToEnvironment: addPathToEnvironment | ||
}; | ||
@@ -9,3 +9,3 @@ | ||
function addPathToEnvironment(pathToAdd) { | ||
process.env.PATH += path.delimiter + pathToAdd; | ||
process.env.PATH += path.delimiter + pathToAdd; | ||
} |
@@ -0,1 +1,2 @@ | ||
var log = require('./log'); | ||
var path = require('path'); | ||
@@ -5,3 +6,3 @@ var fs = require('fs'); | ||
module.exports = { | ||
fix : fix | ||
fix: fix | ||
}; | ||
@@ -11,6 +12,6 @@ | ||
if (driver.os.name != 'win32' && driver.os.name != 'win64') { | ||
console.log('Fixing file permissions'); | ||
fs.chmodSync(path.join(driver.downloadPath, driver.binaryFileName), '755') | ||
} | ||
if (driver.os.name != 'win32' && driver.os.name != 'win64') { | ||
log.infoIf(!driver.opts.silent, 'Fixing file permissions'); | ||
fs.chmodSync(path.join(driver.downloadPath, driver.binaryFileName), '755') | ||
} | ||
} |
module.exports = { | ||
reportProgress : reportProgress | ||
reportProgress: reportProgress | ||
}; | ||
function reportProgress(activeFileRequest, driver) { | ||
const reporter = createReporter(driver.opts.silent); | ||
const progressLib = require('request-progress'); | ||
function reportProgress(activeFileRequest) { | ||
const reporter = createReporter(); | ||
const progressLib = require('request-progress'); | ||
return new Promise(function (resolve, reject) { | ||
progressLib(activeFileRequest) | ||
.on('progress', function (state) { | ||
var number = (state['percentage'] * 100).toFixed(2); | ||
reporter.reportProgress('Received: ' + number + '%'); | ||
}) | ||
.on('error', function (err) { | ||
console.log(err); | ||
reject(); | ||
}) | ||
.on('end', function () { | ||
reporter.reportFinal('Received: 100%'); | ||
resolve(); | ||
}); | ||
}); | ||
return new Promise(function (resolve, reject) { | ||
progressLib(activeFileRequest) | ||
.on('progress', function (state) { | ||
var number = (state['percentage'] * 100).toFixed(2); | ||
reporter.reportProgress(' downloading new '+ driver.name +' driver > ' + number + '%'); | ||
}) | ||
.on('error', function (err) { | ||
console.log(err); | ||
reject(); | ||
}) | ||
.on('end', function () { | ||
reporter.reportFinal(' downloading new '+ driver.name +' driver > 100%'); | ||
resolve(); | ||
}); | ||
}); | ||
} | ||
function createReporter() { | ||
const readLine = require('readline'); | ||
const rl = readLine.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
function createReporter(isSilent) { | ||
const readLine = require('readline'); | ||
const rl = readLine.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}); | ||
return { | ||
reportProgress: function reportProgress(progressString) { | ||
rl.write('', {ctrl: true, name: 'u'}); // Simulate Ctrl+u to delete the line written previously | ||
rl.write(progressString); | ||
}, | ||
reportFinal: function (progressString) { | ||
this.reportProgress(progressString); | ||
rl.write('', {name: 'enter'}); | ||
rl.close(); | ||
} | ||
return { | ||
reportProgress: function reportProgress(progressString) { | ||
rl.write('', {ctrl: true, name: 'u'}); // Simulate Ctrl+u to delete the line written previously | ||
rl.write(progressString); | ||
}, | ||
reportFinal: function (progressString) { | ||
this.reportProgress(progressString); | ||
if(isSilent) { | ||
process.stdout.clearLine(); | ||
process.stdout.write("\r"); | ||
} | ||
else { | ||
rl.write('', {name: 'enter'}); | ||
} | ||
rl.close(); | ||
} | ||
} | ||
} |
@@ -10,68 +10,69 @@ var log = require('./log'); | ||
module.exports = { | ||
driver: '', | ||
init: prepareForSelenium, | ||
start: start, | ||
stop: stop | ||
driver: '', | ||
init: prepareForSelenium, | ||
start: start, | ||
stop: stop | ||
}; | ||
function prepareForSelenium({download = true, browserName, deactivate = false, silent = false}) { | ||
function prepareForSelenium({download = true, browserName, deactivate = false, silent = true} = opts) { | ||
log.infoIf(!silent, 'Preparing driver for browser: ' + browserName); | ||
var driver = new Driver(browserName); | ||
if (!driver.supported.includes(browserName)) { | ||
throw new Error('Selenium drivers does not support browser: ' + browserName); | ||
var driver = new Driver(browserName, arguments[0]); | ||
if (!driver.supported.includes(browserName)) { | ||
throw new Error('Selenium drivers does not support browser: ' + browserName); | ||
} | ||
return new Promise(function (resolve, reject) { | ||
if (deactivate) { | ||
resolve(); | ||
} | ||
else if (browserName === 'safari') { | ||
log.infoIf(!driver.opts.silent, 'NOTICE: requires minimum OSX: ElCaptain & Safari 10.0!'); | ||
resolve(); | ||
} | ||
else { | ||
pathPrep.addPathToEnvironment(driver.downloadPath); // for selenium | ||
return new Promise(function (resolve, reject) { | ||
if (deactivate) { | ||
resolve(); | ||
} | ||
else if (browserName === 'safari') { | ||
console.log('NOTICE: requires minimum OSX: ElCaptain & Safari 10.0!'); | ||
resolve(); | ||
} | ||
else { | ||
pathPrep.addPathToEnvironment(driver.downloadPath); // for selenium | ||
if (download) { | ||
handleDownload(driver, resolve, reject); | ||
} | ||
else { | ||
console.log('Driver download disabled, version will not be checked.') | ||
resolve(); | ||
} | ||
} | ||
}); | ||
if (download) { | ||
handleDownload(driver, resolve, reject); | ||
} | ||
else { | ||
log.infoIf(!driver.opts.silent, 'Driver download disabled, version will not be checked.') | ||
resolve(); | ||
} | ||
} | ||
}); | ||
} | ||
function handleDownload(driver, callback, error) { | ||
download.checkLastDriverVersion(driver).then(function (version) { | ||
driver.setFileNamesFromVersion(version); | ||
if(driver.isUpToDate(version)) { | ||
console.log('Local driver is up to date!'); | ||
callback(); | ||
} | ||
else { | ||
var downloadSuccess = prepareDownloadedFile.bind(this, driver, callback); | ||
var downloadRequest = download.downloadDriverToDirectory(driver, '../downloads'); | ||
report.reportProgress(downloadRequest); | ||
downloadRequest.on('end', downloadSuccess); | ||
downloadRequest.on('error', error); | ||
} | ||
}); | ||
download.checkLastDriverVersion(driver).then(function (version) { | ||
driver.setFileNamesFromVersion(version); | ||
if (driver.isUpToDate(version)) { | ||
log.infoIf(!driver.opts.silent, 'Local driver is up to date!'); | ||
callback(); | ||
} | ||
else { | ||
var downloadSuccess = prepareDownloadedFile.bind(this, driver, callback); | ||
var downloadRequest = download.downloadDriverToDirectory(driver); | ||
report.reportProgress(downloadRequest, driver); | ||
downloadRequest.on('end', downloadSuccess); | ||
downloadRequest.on('error', error); | ||
} | ||
}); | ||
} | ||
function prepareDownloadedFile(driver, callback) { | ||
driver.extract().then(function () { | ||
permissions.fix(driver); | ||
callback(); | ||
}); | ||
driver.extract().then(function () { | ||
permissions.fix(driver); | ||
callback(); | ||
}); | ||
} | ||
function start() { | ||
// TODO: start driver programmatically | ||
// TODO: start driver programmatically | ||
} | ||
@@ -81,3 +82,3 @@ | ||
function stop() { | ||
// TODO: stop driver programmatically | ||
// TODO: stop driver programmatically | ||
} |
{ | ||
"name": "selenium-drivers", | ||
"version": "2.0.3", | ||
"version": "2.1.0", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "selenium", |
@@ -12,2 +12,4 @@ # selenium-drivers | ||
Make sure your OS & Browser are [supported!](#Supported-Browsers) | ||
## Use case: | ||
@@ -34,2 +36,3 @@ ```javascript | ||
* `browserName`: ('chrome' | 'firefox' | 'internet explorer' | 'safari') specify browser name | ||
* `silent`: (true | false) set to false for verbose output (default: `true`) | ||
* `download`: (true | false) disable driver download (default: `true`) | ||
@@ -36,0 +39,0 @@ * `deactivate`: (true | false) deactivate library (useful when running with custom browser capabilities where driver is provided, |
@@ -5,5 +5,5 @@ var seleniumDrivers = require('../lib/selenium-drivers'); | ||
describe('webDriver is able to run browser!', function () { | ||
describe.skip('WebDriver is able to download new drivers & run browser!', function () { | ||
before(function () { | ||
before('Deleting all local drivers.', function () { | ||
return del(['downloads/*', '!downloads/.tmp']); | ||
@@ -19,4 +19,12 @@ }); | ||
}); | ||
it.skip('safari', function () { | ||
return assertWebdriverRunsWithBrowser('safari'); | ||
}); | ||
it.skip('internet explorer', function () { | ||
return assertWebdriverRunsWithBrowser('internet explorer'); | ||
}); | ||
function assertWebdriverRunsWithBrowser(browserName) { | ||
@@ -26,3 +34,4 @@ var actualOutcome; | ||
return seleniumDrivers.init({ | ||
browserName: browserName | ||
browserName: browserName, | ||
silent: true | ||
}).then(function () { | ||
@@ -42,4 +51,2 @@ | ||
} | ||
}); |
var Mocha = require('mocha'), | ||
fs = require('fs'), | ||
path = require('path'); | ||
fs = require('fs'), | ||
path = require('path'); | ||
@@ -10,3 +10,3 @@ | ||
var mocha = new Mocha({ | ||
timeout: DEFAULT_CASE_TIMEOUT | ||
timeout: DEFAULT_CASE_TIMEOUT | ||
}); | ||
@@ -16,15 +16,15 @@ | ||
fs | ||
.readdirSync(TEST_DIR).filter(function (file) { | ||
return file.substr(-3) === '.js'; | ||
}) | ||
.forEach(function (file) { | ||
mocha.addFile( | ||
path.join(TEST_DIR, file) | ||
); | ||
}); | ||
.readdirSync(TEST_DIR).filter(function (file) { | ||
return file.substr(-3) === '.js'; | ||
}) | ||
.forEach(function (file) { | ||
mocha.addFile( | ||
path.join(TEST_DIR, file) | ||
); | ||
}); | ||
mocha.run(function (failures) { | ||
process.on('exit', function () { | ||
process.exit(failures); // exit with non-zero status if there were failures | ||
}); | ||
process.on('exit', function () { | ||
process.exit(failures); // exit with non-zero status if there were failures | ||
}); | ||
}); |
19648982
23
520
58