0
votes

I have previously installed selenium using 'npm install -g selenium-webdriver so all my projects were using global node-modules (set up on mac os). It worked! Then I have experimented with different JavaScript Test Automation frameworks. Now I want to start again from scratch, however when I am following the same steps as before to install selenium for webdriverJs automation it does not work.

#The steps that I took:#

  1. Run npm init (I did not change any values in the package.json)
  2. Run sudo npm install -g selenium-webdriver
  3. Run sudo npm install -g chromedriver
  4. Run sudo npm install -g geckodriver
  5. Verify that all modules were successfully created in /usr/local/lib/node_modules
  6. Verify that global modules are used by running the following simple script:

var webdriver = require('selenium-webdriver'),
    //By = webdriver.By,
    //until = webdriver.until;
var driver = new webdriver.Builder().forBrowser('chrome').build();

driver.get('https://www.google.com/');

#The Result#

Error: Cannot find module 'selenium-webdriver'

While I understand what the error is communicating (run the npm install selenium-webdriver to place node-modules with drivers inside of the Project), my intention is to use selenium-webdriver (plus chromedriver, geckodriver) globally for more projects.

How can I achieve that and enforce the project to use selenium globally rather than locally?

Thank You.

1

1 Answers

0
votes

Try clearing your node_modules folder and running npm install.