Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command to install chromedriver #23

Closed
twolfson opened this issue Jun 30, 2015 · 12 comments · Fixed by #115
Closed

Add command to install chromedriver #23

twolfson opened this issue Jun 30, 2015 · 12 comments · Fixed by #115

Comments

@twolfson
Copy link

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
@shama
Copy link
Contributor

shama commented Jun 30, 2015

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!

@shama shama closed this as completed Jun 30, 2015
@twolfson
Copy link
Author

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:

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)

@shama
Copy link
Contributor

shama commented Jun 30, 2015

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.

@gbmhunter
Copy link

+1 for this issue, I vote for it to be re-opened!

@shama shama reopened this Jul 10, 2015
@shama
Copy link
Contributor

shama commented Jul 10, 2015

Reopening to at least explore it.

@gbmhunter
Copy link

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.

@twolfson
Copy link
Author

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

@pose
Copy link

pose commented Jul 19, 2015

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.

@twolfson
Copy link
Author

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

@twolfson
Copy link
Author

Additionally, there was a bug in the installer that should be patched in pose/webdriver-manager#14

@twolfson
Copy link
Author

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.

@ayushmanchhabra
Copy link
Collaborator

This would be pretty conveniant for testing with Selenium. Since the NW.js binary lives inside node_modules it can be cached in GitHub Actions and reused instead of downloading it every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants