量角器E2E测试错误:找不到模块'selenium-webdriver'

时间:2014-02-11 14:21:41

标签: angularjs selenium protractor

错误:找不到模块'selenium-webdriver' 我在全球范围内安装了量角器和selenium-webdriver npm install -g量角器  webdriver-manager更新

    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');
  });
});

4 个答案:

答案 0 :(得分:5)

您需要安装节点模块:

npm i selenium-webdriver --save-dev

答案 1 :(得分:1)

您是否尝试删除var webdriver = require('selenium-webdriver');

您不应该需要它,您可以通过browser

在测试中访问它
  

browser这是webdriver实例的包装器。用于导航和页面范围的信息。

(引自Getting started - Protractor docs

如果您已经使用webdriver-manager update安装了Selenium独立服务器,并使用webdriver-manager start启动了它,那么您只需要使用

运行测试
protractor path/to/your/protractor-conf.js

答案 2 :(得分:0)

输入

时输入

webdriver-manager

进入终端,这些有用的选项出现:

webdriver-manager
Usage: webdriver-manager <command>
Commands:
  update: install or update selected binaries
  start: start up the selenium server
  status: list the current available drivers

您是否尝试过update, start,status?

答案 3 :(得分:0)

尝试使用独立选项:

$ webdriver-manager start --standalone