firefox-profile
Advanced tools
Comparing version 0.2.9 to 0.2.10
@@ -1,34 +0,38 @@ | ||
var FirefoxProfile = require('./lib/firefox_profile'), | ||
wd = require('wd'); | ||
var FirefoxProfile, | ||
wd = require('wd'); | ||
try { | ||
FirefoxProfile = require('./lib/firefox_profile'); | ||
} catch (e) { | ||
FirefoxProfile = require('firefox-profile'); | ||
} | ||
// set some userPrefs if needed | ||
// Note: make sure you call encoded() after setting some userPrefs | ||
var fp = new FirefoxProfile(); | ||
// activate and open firebug by default for all sites | ||
// activate the console panel | ||
// set some userPrefs if needed | ||
// Note: make sure you call encoded() after setting some userPrefs | ||
var fp = new FirefoxProfile(); | ||
// activate and open firebug by default for all sites | ||
// activate the console panel | ||
// show the console panel | ||
fp.setPreference('extensions.firebug.allPagesActivation', 'on'); | ||
fp.setPreference('extensions.firebug.allPagesActivation', 'on'); | ||
fp.setPreference('extensions.firebug.console.enableSites', true); | ||
fp.setPreference('extensions.firebug.cookies.enableSites', true); | ||
fp.setPreference('extensions.firebug.net.enableSites', true); | ||
fp.setPreference('extensions.firebug.script.enableSites', true); | ||
fp.setPreference('extensions.firebug.currentVersion', '2.0.1'); | ||
fp.setPreference('extensions.firebug.defaultPanelName', 'console'); | ||
fp.setPreference('saadt.coucou', 'console'); | ||
fp.updatePreferences(); | ||
// you can install multiple extensions at the same time | ||
fp.addExtensions(['./test/extensions/firebug-2.0.1-fx.xpi'], function() { | ||
fp.encoded(function(zippedProfile) { | ||
browser = wd.promiseChainRemote(); | ||
browser.init({ | ||
browserName:'firefox', | ||
// set firefox_profile capabilities HERE!!!! | ||
firefox_profile: zippedProfile | ||
}). | ||
// woOot!! | ||
get('http://en.wikipedia.org'); | ||
}); | ||
// show the console panel | ||
fp.setPreference('extensions.firebug.allPagesActivation', 'on'); | ||
fp.setPreference('extensions.firebug.allPagesActivation', 'on'); | ||
fp.setPreference('extensions.firebug.console.enableSites', true); | ||
fp.setPreference('extensions.firebug.cookies.enableSites', true); | ||
fp.setPreference('extensions.firebug.net.enableSites', true); | ||
fp.setPreference('extensions.firebug.script.enableSites', true); | ||
fp.setPreference('extensions.firebug.currentVersion', '2.0.1'); | ||
fp.setPreference('extensions.firebug.defaultPanelName', 'console'); | ||
fp.setPreference('saadt.coucou', 'console'); | ||
fp.updatePreferences(); | ||
// you can install multiple extensions at the same time | ||
fp.addExtensions(['./test/extensions/firebug-2.0.1-fx.xpi'], function() { | ||
fp.encoded(function(zippedProfile) { | ||
browser = wd.promiseChainRemote(); | ||
browser.init({ | ||
browserName:'firefox', | ||
// set firefox_profile capabilities HERE!!!! | ||
firefox_profile: zippedProfile | ||
}). | ||
// woOot!! | ||
get('http://en.wikipedia.org'); | ||
}); | ||
}); |
var webdriver = require('selenium-webdriver'); | ||
var FirefoxProfile; | ||
try { | ||
FirefoxProfile = require('./lib/firefox_profile'); | ||
} catch(e) { | ||
FirefoxProfile = require('firefox-profile'); | ||
} | ||
// create profile | ||
var FirefoxProfile = require('./lib/firefox_profile'); | ||
var myProfile = new FirefoxProfile(); | ||
@@ -10,13 +15,13 @@ console.log(myProfile.profileDir); | ||
var capabilities = webdriver.Capabilities.firefox(); | ||
var capabilities = webdriver.Capabilities.firefox(); | ||
// attach your newly created profile | ||
myProfile.encoded(function(prof) { | ||
capabilities.set('firefox_profile', prof); | ||
capabilities.set('firefox_profile', prof); | ||
// start the browser | ||
var wd = new webdriver.Builder(). | ||
withCapabilities(capabilities). | ||
build(); | ||
}); | ||
}); | ||
withCapabilities(capabilities). | ||
build(); | ||
}); | ||
}); | ||
@@ -53,5 +53,5 @@ module.exports = function(grunt) { | ||
grunt.registerTask('travis', ['mochacov:unit', 'mochacov:coveralls']); | ||
grunt.registerTask('travis', ['mochacov:unit'/*, 'mochacov:coveralls'*/]); | ||
grunt.registerTask('docs', 'apidox'); | ||
}; |
@@ -6,12 +6,13 @@ 'use strict'; | ||
fs = require('fs-extra'), | ||
// third-party | ||
parseString = require('xml2js').parseString, | ||
// third-party | ||
wrench = require('wrench'), | ||
AdmZip = require('adm-zip'), | ||
wrench = require('wrench'), | ||
AdmZip = require('adm-zip'), | ||
archiver = require('archiver'), | ||
uuid = require('node-uuid'), | ||
uuid = require('node-uuid'), | ||
Readable = require('lazystream').Readable, | ||
async = require('async'), | ||
uuid = require('node-uuid'), | ||
getID = require('jetpack-id'); | ||
async = require('async'), | ||
uuid = require('node-uuid'), | ||
getID = require('jetpack-id'), | ||
_ = require('lodash'); | ||
@@ -85,11 +86,12 @@ var config = { | ||
* Constructor | ||
*/ | ||
/** | ||
* | ||
* Initialize a new instance of a Firefox Profile | ||
* Note that this function uses filesystem sync functions to copy an existing profile (id profileDirectory is provided) | ||
* which is not optimized. | ||
* If you need optimzed async version, use `FirefoxProfile.copy(profileDirectory, cb); | ||
* | ||
* @param {String|null} profileDirectory optional. if provided, it will copy the directory | ||
* @param {String|null} profileDirectory optional. if provided, it will copy the directory synchronously (not recommended) | ||
*/ | ||
function FirefoxProfile(profileDirectory) { | ||
// cloning! | ||
this.defaultPreferences = JSON.parse(JSON.stringify(config.DEFAULT_PREFERENCES)); | ||
this.defaultPreferences = _.clone(config.DEFAULT_PREFERENCES); | ||
this.profileDir = profileDirectory; | ||
@@ -119,3 +121,3 @@ // if true, the profile folder is deleted after | ||
if (self._deleteOnExit) { | ||
self.deleteDir(); | ||
self._cleanOnExit(); | ||
} | ||
@@ -128,9 +130,47 @@ }; | ||
function deleteParallel(files, cb) { | ||
async.parallel(files.map(function(file) { | ||
return function(next) { fs.unlink(file, next)}; | ||
}), function () { | ||
cb && cb(); | ||
}); | ||
} | ||
FirefoxProfile.prototype._copy = function(profileDirectory, cb) { | ||
var self = this; | ||
wrench.copyDirRecursive(profileDirectory, this.profileDir, { | ||
forceDelete: true, | ||
preserveFiles: true, | ||
filter: /^(parent\.lock|lock|\.parentlock)$/ // does not work, not implemented in wrench (async version) | ||
}, function() { | ||
// remove parent.lock, lock or .parentlock files if they have been copied | ||
deleteParallel(['parent.lock', 'lock', '.parentlock'].map(function(file) { | ||
return path.join(self.profileDir, file); | ||
}), cb); | ||
}); | ||
}; | ||
/** | ||
* Deletes the profile directory. | ||
* creates a profile Profile from an existing firefox profile directory | ||
* * | ||
* @param {String|null} profileDirectory optional. if provided, it will copy the directory synchronously | ||
*/ | ||
FirefoxProfile.copy = function(profileDirectory, cb) { | ||
var profile = new FirefoxProfile(); | ||
profile._copy(profileDirectory, function() { | ||
cb && cb(profile); | ||
}); | ||
}; | ||
/** | ||
* Deletes the profile directory asynchronously. | ||
* | ||
* Call it only if you do not need the profile. Otherwise use at your own risk. | ||
* this function is automatically called by default (= if willDeleteOnExit() returns true) | ||
@param cb a callback function with boolean parameter (false if the dir is not found) | ||
that will be called when the profileDir is deleted | ||
*/ | ||
FirefoxProfile.prototype.deleteDir = function() { | ||
FirefoxProfile.prototype.deleteDir = function(cb) { | ||
var self = this; | ||
@@ -141,6 +181,27 @@ ['exit', 'SIGINT'].forEach(function(event) { | ||
this.shouldDeleteOnExit(false); | ||
fs.existsSync(this.profileDir) && wrench.rmdirSyncRecursive(this.profileDir); | ||
fs.exists(this.profileDir, function(doesExists) { | ||
if (!doesExists) { | ||
cb && cb(); | ||
return; | ||
} | ||
wrench.rmdirRecursive(self.profileDir, false, function() { | ||
cb && cb(); | ||
}); | ||
}); | ||
}; | ||
/** | ||
* called on exit to delete the profile directory synchronously. | ||
* | ||
* should not be called directly. process.on('exit') cannot be asynchronous: async code is not called | ||
* | ||
*/ | ||
FirefoxProfile.prototype._cleanOnExit = function() { | ||
if (fs.existsSync(this.profileDir)) { | ||
wrench.rmdirSyncRecursive(this.profileDir, false); | ||
} | ||
}; | ||
/** | ||
* Specify if the profile Directory should be deleted on process.exit() | ||
@@ -313,7 +374,6 @@ * | ||
zipStream.on('close', function() { | ||
cb(fs.readFileSync(path.join(tmpFolder,'profile.zip')).toString('base64')); | ||
if (self._deleteZippedProfile) { | ||
fs.unlinkSync(path.join(tmpFolder,'profile.zip')); | ||
fs.rmdirSync(tmpFolder); | ||
} | ||
fs.readFile(path.join(tmpFolder,'profile.zip'), function(err, content) { | ||
cb(content.toString('base64')); | ||
deleteParallel([path.join(tmpFolder,'profile.zip'), tmpFolder]); | ||
}); | ||
}); | ||
@@ -442,19 +502,44 @@ archive.pipe(zipStream); | ||
var addonPath = path.join(self.extensionsDir, path.sep, addonId); | ||
async.series([ | ||
// creates extensionsDir | ||
function(next) { | ||
fs.exists(self.extensionsDir, function(exists) { | ||
if (!exists) { | ||
fs.mkdir(self.extensionsDir, function() { | ||
next(); | ||
}); | ||
return; | ||
} | ||
// already exists | ||
next(); | ||
}); | ||
}, | ||
function(next) { | ||
if (!unpack && xpiFile) { | ||
fs.copy(xpiFile, addonPath + '.xpi', function() { next(); }); | ||
} else { | ||
// copy it! | ||
fs.mkdir(addonPath, function() { | ||
wrench.copyDirRecursive(addon, addonPath, { | ||
forceDelete: true, | ||
preserveFiles: true, | ||
}, function() { | ||
next(); | ||
}); | ||
}); | ||
if (!fs.existsSync(self.extensionsDir)) { | ||
fs.mkdirSync(self.extensionsDir); | ||
} | ||
if (!unpack && xpiFile) { | ||
fs.copySync(xpiFile, addonPath + '.xpi'); | ||
} else { | ||
// copy it! | ||
fs.mkdirSync(addonPath); | ||
wrench.copyDirSyncRecursive(addon, addonPath, {forceDelete: true}); | ||
} | ||
if (tmpDir) { | ||
wrench.rmdirSyncRecursive(tmpDir); | ||
} | ||
// done! | ||
cb && cb(); | ||
} | ||
}, | ||
function (next) { | ||
if (tmpDir) { | ||
wrench.rmdirRecursive(tmpDir, function() { | ||
next(); | ||
}); | ||
} | ||
} | ||
], function() { | ||
// done! | ||
cb && cb(); | ||
}); | ||
}); | ||
@@ -461,0 +546,0 @@ |
{ | ||
"name": "firefox-profile", | ||
"version": "0.2.9", | ||
"version": "0.2.10", | ||
"description": "firefox profile for selenium WebDriverJs, admc/wd or any other node selenium driver that supports capabilities", | ||
@@ -72,4 +72,5 @@ "main": "lib/firefox_profile", | ||
"async": "~0.9.0", | ||
"fs-extra": "~0.9.1", | ||
"fs-extra": "~0.10.x", | ||
"lazystream": "~0.1.0", | ||
"lodash": "~2.4.1", | ||
"node-uuid": "~1.4.1", | ||
@@ -76,0 +77,0 @@ "wrench": "~1.5.1", |
@@ -16,3 +16,3 @@ # firefox-profile-js | ||
* create a firefox profile | ||
* use an existing profile (by specifying path) | ||
* use an existing profile (by specifying a path) | ||
* add extensions to your profile, | ||
@@ -19,0 +19,0 @@ * specify proxy settings, |
@@ -27,3 +27,3 @@ /*jshint camelcase:false*/ | ||
afterEach(function() { | ||
afterEach(function(done) { | ||
// will remove the onexit() call (that deletes the dir folder) | ||
@@ -33,3 +33,3 @@ // prevents warning: | ||
// X listeners added. Use emitter.setMaxListeners() to increase limit. | ||
fp.deleteDir(); | ||
fp.deleteDir(done); | ||
}); | ||
@@ -53,2 +53,17 @@ | ||
}); | ||
describe('#Firefox.copy', function() { | ||
it('lock files should not be copied over', function(done) { | ||
FirefoxProfile.copy(testProfiles.emptyProfile.path, function(fp) { | ||
expect(fs.statSync(fp.profileDir).isDirectory()).to.be.true; | ||
['.parentlock', 'lock', 'parent.lock'].forEach(function(lockFile) { | ||
expect(fs.existsSync(path.join(fp.profileDir, lockFile))).to.be.false; | ||
}); | ||
expect(fs.existsSync(path.join(fp.profileDir, 'empty.file'))).to.be.true; | ||
fp.deleteDir(done); | ||
}); | ||
}); | ||
}); | ||
describe('#setPreference', function() { | ||
@@ -302,10 +317,12 @@ describe('should correctly store string values', function() { | ||
describe('#deleteDir', function() { | ||
it('should delete profile dir', function() { | ||
it('should delete profile dir', function(done) { | ||
expect(fs.existsSync(fp.path())).to.be.true; | ||
expect(fs.statSync(fp.path()).isDirectory()).to.be.true; | ||
fp.deleteDir(); | ||
expect(fs.existsSync(fp.path())).to.be.false; | ||
fp.deleteDir(function() { | ||
expect(fs.existsSync(fp.path())).to.be.false; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6510389
1082
10
+ Addedlodash@~2.4.1
+ Addedfs-extra@0.10.0(transitive)
+ Addedjsonfile@1.2.0(transitive)
- Removedfs-extra@0.9.1(transitive)
- Removedjsonfile@1.1.1(transitive)
Updatedfs-extra@~0.10.x