npm-installer
npm-installer copied to clipboard
Add command to install chromedriver
The current setup for testing is a bit tedious. It would be nice if we could automate chromedriver installation similarly to how simple nw is. For example:
npm install nw
nw-installer install chromedriver
I believe there are a few chromedriver packages already on npm: https://www.npmjs.com/search?q=chromedriver If one of those doesn't meet your needs it should still be a separate package as this is just an installer for nw.js and not for installing other packages.
npm i nw
npm i nw-chromedriver
Thanks!
Unfortunately, nw.js has a custom Chromedriver server which searches for nw/nw.exe:
https://github.com/nwjs/nw.js/wiki/Chromedriver
which results in none of the proposed modules working. The reason for requesting these repos to be bundled has 2 parts:
- Chromedriver requires being installed to the same directory as
nw/nw.exe- https://github.com/nwjs/nw.js/wiki/Chromedriver#installing
- Resolving the URL to download the hosted nw.js Chromedriver solution changes based on architecture and release version as with this module
- http://dl.nwjs.io/v0.12.2/
At the very least, can we make this repo more developer friendly? (e.g. abstract URL resolution piece, provide a CLI utility to find out where the existing nw.js is so we can create symlinks and/or move it)
You can get the path to where nw has been installed with var nwpath = require('nw').findpath().
I understand it would make it easier if they were bundled together. I just don't want to go down the path of maintaining support for download locations and compatible versions of web drivers, at least not in this repo. I don't have the capacity to maintain that atm.
+1 for this issue, I vote for it to be re-opened!
Reopening to at least explore it.
Note that for certain test frameworks, you don't have to have chromedriver.exe in the same folder as nw.exe. One example is when using the protractor.js framework. Here is protractor-config.js:
'use strict';
exports.config = {
// Relative path to node-webkit's chromedriver,
// note this is a special chromedriver, specifically for nw!
chromeDriver: 'support\\chromedriver.exe',
chromeOnly: true, // starting Selenium server isn't required in our case
capabilities: {
browserName: 'chrome',
chromeOptions: {
// Relative path to NW.js binary goes here, this should of been placed
// here when "npm install" was run from root project directory.
binary: 'node_modules\\nw\\nwjs\\nw.exe'
}
},
// Files which contains the app tests
specs: ['test/todo-spec.js'],
// baseUrl needs to be relative, because of this, we will provide it through the command line
// rather than set it in here (see the test.cmd file)
//baseUrl: 'file:///C:/Work/Resources/BSL%20Hub/src/HardwareValidation/',
rootElement: 'html', // specify a correct element where you bootstrap your AngularJS app, 'body' by default
onPrepare: function() {
// By default, Protractor use data:text/html,<html></html> as resetUrl, but
// location.replace (see http://git.io/tvdSIQ) from the data: to the file: protocol is not allowed
// (we'll get ‘not allowed local resource’ error), so we replace resetUrl with one
// with the file: protocol (this particular one will open system's root folder)
browser.resetUrl = 'file://';
// This isn't required and used to avoid ‘Cannot extract package’ error showed
// before Protractor have redirected node-webkit to resetUrl.
browser.driver.get('file://');
}
};
Note that paths above for chromedriver.exe and nw.exe are specified in separate places.
Ah, if that's the case then we might be able to request the nw flavor of Chromedriver as a download option in https://github.com/pose/webdriver-manager
I've added support for chromedriver-nw. You can take a look at the following example: https://github.com/pose/webdriver-manager/blob/master/examples/chromedriver-nw-example.js#L9
Also, you can achieve the same using the CLI:
npm i -g webdriver-manager
webdriver-manager update --chromedriver-nw
Let me know if you find any issues.
As a heads up, we really want to set --chrome false on the CLI. Otherwise, the Chromedriver's will overwrite each other =/
webdriver-manager update --standalone true --chrome false --chromedriver-nw true
Additionally, there was a bug in the installer that should be patched in pose/webdriver-manager#14
Alright, after a bit of working around errors. We got both a non-symlink version working with the code that @gbmhunter posted (once the pose/webdriver-manager#14 patches are landed). Here are the relevant code pieces:
# Install Selenium dependencies
webdriver-manager update --standalone true --chrome false --chromedriver-nw true
# Start webdriver server
webdriver-manager start
// Load in dependencies
var nw = require('nw');
var wd = require('wd');
// Resolve nw.js and start wd against our nw.js instance
var nwCmd = nw.findpath();
var browser = wd.remote();
browser.init({
browserName: 'chrome',
chromeOptions: {
binary: nwCmd
}
});
@shama I will leave it to your discretion to choose to leave the issue open or close it. I am content with either scenario.