Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor E2E Testing Error: Cannot find module 'selenium-webdriver'

Error: Cannot find module 'selenium-webdriver'

I have installed protractor and selenium-webdriver globally using npm install -g protractor webdriver-manager update

var webdriver = require('selenium-webdriver');


describe('modes of failure', function() {
  it('should fail to find a non-existent element', function() {
    browser.get('index.html#/form');

    // Run this statement before the line which fails. If protractor is run
    // with the debugger (protractor debug debugging/conf.js), the test
    // will pause after loading the webpage but before trying to find the
    // element.
    browser.debugger();

    // This element doesn't exist, so this fails.
    var nonExistant = element(by.binding('nopenopenope')).getText();
  });

  it('should fail to use protractor on a non-Angular site', function() {
    browser.get('http://www.google.com');
  }, 20000);

  it('should fail an assertion', function() {
    browser.get('index.html#/form');

    var greeting = element(by.binding('{{greeting}}'));

    expect(greeting.getText()).toEqual('This is not what it equals');
  });
});
like image 436
user3061796 Avatar asked Feb 11 '14 14:02

user3061796


2 Answers

You need to install the node module:

npm i selenium-webdriver --save-dev
like image 114
cyberwombat Avatar answered Sep 20 '22 18:09

cyberwombat


Did you try to remove the var webdriver = require('selenium-webdriver'); ?

You shouldn't need it, you can access it in your test via browser

browser this is the a wrapper around an instance of webdriver. Used for navigation and page-wide information.

(quoted from Getting started - Protractor docs)

If you've already installed the Selenium standalone server using webdriver-manager update, and started it with webdriver-manager start, all you have to do is to run your tests using

protractor path/to/your/protractor-conf.js
like image 35
glepretre Avatar answered Sep 20 '22 18:09

glepretre